Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question on how best to parse text 2

Status
Not open for further replies.

robojeff

Technical User
Dec 5, 2008
220
US
I have a bar code which contains a "part number", a "from location", a "quantity", a "To location", and a "lot code" field and all of these fields are seperated by a tab.

A typical bar code might decode as follows:

N18-128200 WH 3 LOC04 1d2423
(part) (from) (qty) (to) lot)

Because these fields can be of different lengths, how
can I parse each field from an individual text box on my
form into certain controls on my form with extra space compression?

I envision having the user scan the bar code into one text box field on the form and then have this data populate certain controls on my form with the data derived from the bar code...

I would like to store the "part number" into Me.Part,
the from data into Me.from, the quantity into Me.qty, the
to data into Me.to, and the lot info into Me.lotsn

Is there an efficient way of doing this?


Thanks in advance...
 


Hi,

"seperated by a tab"
Code:
dim a, i as integer
a = split(YourDataString, vbtab)
for i = 0 to ubound(a)
  debug.print a(i)
next


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
thanks SkipVought-

There is something funny going on with this...
If I scan the bar code into notepad, the tabs are shown as follows:

N18-128200 WH 3 LOC04 1d2423

but if I scan the bar code into the text box on my form, a(i) = "N18-128200WH3LOC041d2423"

It appears as if the tabs are not recognized in the text box.

All I really need out of the bar code is the part number and the quantity.

Any ideas why the tabs are not showing up or how I can pull only those two fields from this stream of bar code data?

 
>It appears as if the tabs are not recognized in the text box

I suspect the problem is related to how your barcode reader is inserting characters into the buffer combined with how the textbox is interpreting that.

First off try setting the textbox's Multiline property to True

And if that by itself does not work, try setting the TabStop property to True
 
Why bother with the textbox at all? Just scan into a string, then Split() it as Skip suggested and assign the array elements you want to the controls you want.
 
thanks strongm

I checked the text box properties and see that the tabstop is set to Yes but I do not see a Multiline property at all... where is this property located in Access 2003?

I can strip out just the part number with the following where Me.kb_lbl is the text box where I insert the bar code label info "N18-128200WH3LOC041d2423" and Me.part is the text box where I want to display the part number on the form:

pos = InStr(2, Me.kb_lbl, "WH", 1)
Me.part = Left$(Me.kb_lbl, (pos - 1))

but I also need the the quantity and the lot code. The quantity should always follow "WH" in every scan but it can vary in how many digits that it may be due to its value and I can not guarantee that the stock location which is the next field will always start with an alpha character rather than a number. Then there is the lot code which is on the trailing end after the stock location...

Not sure if there is any other way to do that and the strip seems like a nice way if only I can get the tabs to be recognized...
 
thanks harebrain...

How do I scan this into a string without having a text box on a form to aim the scanning of the bar code to?

Please advise
 
Have you tried a RichTextBox?
You could have each item on a different line by scenning into a string (MyString) then change every tab to a vbcr to give a new line.

lblNewBigBox.caption=Replace(MyString,vbtab,vbcr)

or if you want names as well, create an array
In Form_Load
Dim Title(5) as string
Titel(1)="Part "
Titel(1)="From "
Titel(1)="Qty "
Titel(1)="To "
Titel(1)="Lot "

In OnCom Sub
Dim =MyArray()
RichtextBox1.Text=""
MyArray=Split(MyString,vbtab)
For a=1 to Ubound(MyArray)
RichtextBox1.Seltext=Title(a) & MyArray(a)& vbcr
Next

This gives in the one square label box with Wordwrap=true
Part N18-128200
From WH
Qty 3
To LOC04
Lot 1d2423

 
thanks Tedsmith but now I am really confused...

I am still stuck on how to scan in the bar code data into a string without a text box or some other control that has focus on the form... how do I scan into a string?

Also, I am not sure what a RichTextBox is and the help of my access 2003 does not show this... Sorry I am so dense but I feel like I am missing something here...
 
>where is this property located in Access 2003?
>the help of my access 2003 does not show this

This is the VB5/6 forum. Access 2003 uses VBA - and different controls. I'd suggest that future queries related to VBA in Access be posted in forum707

>I am not sure what a RichTextBox

It is not a default control (for VB or for Access VBA), so you would need to insert an ActiveX control called 'Microsoft Rich Textbox Control 6.0' (do this via the 'More Controls ...' button on the Form Design toolbox).

However, by itself it won't fix this problem.

You would need to add Event code similar to the following:
Code:
[blue]Private Sub ctlRichText1_KeyDown(KeyCode As Integer, _
      ByVal Shift As Integer)
   Dim rtf As RichTextBox
   Set rtf = Me!ctlRichText1.Object
   If KeyCode = 9 Then  ' TAB key was pressed.
      ' Ignore the TAB key, so focus doesn't
      ' leave the control
      KeyCode = 0
      ' Replace selected text with the tab character
      rtf.SelText = vbTab
   End If
End Sub[/blue]

Another, probably better, alternative would be to have 5 textboxes for each scan which are sequential in the tab order (call them, for example, txtPart, txtFrom, txtQty, txtTo and txtLot). Select the first one, then scan with the barcode reader - and let the default action of Tab in Access parse your input for you ...

Now consider the fact that you already have controls Me.Part etc. Perhaps you can do away with the textboxes we have introduced altogether ...

 
thanks strongm-

There is quite a list of contols listed in the more controls but I could not find an ActiveX control called 'Microsoft Rich Textbox Control 6.0'... Do I need to add something to Access 2003 to have this available?

Also, at first I did try to place a series of text boxes in tab order hoping that the tab in the bar code would forward to the next text box but what I am experiencing is that the full data of the bar code (minus the tabs) is being dumped into the first text box only...

Do these text boxes need to be grouped in order for this to work?
 
How do I scan this into a string without having a text box on a form to aim the scanning of the bar code to?[\quote]

Depends on the bar code scanner but many, if not all anymore, can easily be set up to OPOS compatible(non keyboard emulation) where an ocx will return your result without being ready for text input. Such as OPOSScanner.ocx. Keyboard emulation is as good as gone for any new apllication, in my opinion. Why bother with keyboard emulation? OPOS ocx's or the hardware manufacture's ocx's will simplify everything. Some might even have built in functions to automatically parse the data you need. I use one for MSR's that does it.

Tom
 
Thanks TLowder =

This sounds promising... I have a Symbol Ds6608-hd2007 scanner and am attempting to acquire some information on how to do this, but how is this set up in Access 2003 to retrieve and utilize this stream of data? Is there some sort of data input event or would I have to create one some how?
 
I failed to notice this was in Access, I thought you were doing this in VB6.

Probably the same as Strongm suggested -
It is not a default control (for VB or for Access VBA), so you would need to insert an ActiveX control called 'Microsoft Rich Textbox Control 6.0' (do this via the 'More Controls ...' button on the Form Design toolbox).

Except add the OPOSScanner.ocx. You will also want to move your question to the correct forum if you have trouble adding the ocx. I don't know how, other than what I just read from Strongm.

Yes there is an event that is called when the data changes.

First open scanner ussually in a load event -

OPOSScanner.Open(YourOPOSNameHere)

Event that is called when a bar code is scanned -

Private Sub OPOSScanner_DataEvent(ByVal Status As Long)

Then the value is in -

OPOSScanner.ScanDataLabel

Also your scanner probably needs to be programed for OPOS. Check with the manufacturer on how to do this. It's something like enter configuration mode then scan the proper bar codes. It should be listed in your manual or they may have an easy list of all the codes you need on their website so you can just print the sheet and scan all the codes without having to look them up individually. They should also have a sample program to test and set it up as an OPOS device. It must be given an OPOS name. I've only used Metrologic so I don't know how to do this with Symbol.

Feel free to ask me more about this. But I have only done this in VB6 and don't know how in Access.

Tom
 
Programming??? Maybe left to the professionals!
 
I apologize if anyone feels like I have insulted their professionalism here as that was never my intent...

Thank you everyone for your valuable suggestions, and best regards!
 
No need to apologise - well not to me. My comment was aimed at ccv. Not quite sure what they were on about ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top