Hi there, I have a visual basic 6 program that has a form with a textbox. The text inside the textbox says:
%CABAKERSFIELD^MUTHANA$MOHAMED$MOHAMED... BAKER ST^?;636014029230373=070919829909?#!!933... C M509238BLKBLK D52919990625 [5#,R]-'/=*?
I need to cut pieces of the string and put each piece on a separate textbox. This is a drivers license string generated by a drivers license scanner. The name of the person and last name, city, state, everything will be different depending on the person's driver's license. This means, that the lenght of the strings may vary. Now, to cut each piece from the string what needs to be done is to use the signs that separate each piece. Here are the pieces I want to cut:
State=CA
City=Bakersfield
Last Name=Muthana
FirstName=Mohamed
Full Middle Name=Mohamed
Street Adress=430 Baker St
Id Number=9230373
Zip Code=93305
Class=C
Sex=M
Height=509
Weight=238
Each piece will be on a separate textbox. HELP!
Cut string in Visual Basic 6?
Unless the scanner puts all those special characters in automatically, it seems that you're working too hard.
I would just separate the fields with one delimiter like a comma, so it would be CA,BAKERSFIELD,MOHAMED, etc.
Set up a string array
DIM strResults(12) as String
dim y as integer
y = 0
Then you set up a loop and a mid statement like
FOR x = 1 to LEN(stringALL)
'Then an if statement looking for the comma's like
IF mid(stringALL,x,1) = ASCII(44) THEN 'I think 44 is the comma
'move to the next string in the array
y = y + 1
ELSE
strResults(y) = mid(stringALL,x,1)
End If
Next
Finally. txtState.text = strResults(0)
txtCity.text = strResults(1)
etc until all your text boxes are filled
Oh in case you have no control over all the special characters, you can replace the check for ASCII(44) line with this:
If Not(mid(stringALL,x,1)) Like "[0-9A-Za-z]" Then
which should check for numbers or letters only
hope that helps
Reply:You can use split to cut the string, you have ^ as deliminator.
The following statement will return a array of strings.
split(st,"^",,vbTextCompare )
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment