Parsing a QR code
I know there's another post similar to this one, but mine is a little more complicated.
I am trying to parse a QR code and the delimiter is "<CRTA>" (no quotes). Here's an example string:
00000000<CRTA>-<CRTA>CSES<CRTA>CLT<CRTA>000000-000000<CRTA>PJ00268.01<CRTA>WB-RI<CRTA>1.00<CRTA>EA
Here's the map: Item<CRTA>Revision<CRTA>Site<CRTA>Warehouse<CRTA>Batch<CRTA>Project Tracking <CRTA>Location<CRTA>Quantity<CRTA>UoM
Anyway, I used the other post to do this for the "Item" (placed in 'OnPostPrompt'), which is the 1st thing in this list. PARSETEST is the name of the barcode that is scanned during print.
Value = PARSETEST
Value = Format.NamedSubStrings("PARSETEST").Value
Delim1=Instr(1,Value,"<CRTA>",1)-1
Value=mid(Value,1,Delim1)
This works well, but to find the next item, I'll have to use INSTR again, starting at the end of the 1st occurrence of "<CRTA>". Since INSTR gives the position relative to the starting point, I'll have to add the 2 lengths together to find the location of the second "<CRTA". This will continue and become very complicated for the last item to parse because you have to build up by using a lot of INSTR to find that last one.
Anyway, I think INSTR is possible, just messy. Any better ways?
Brian
-
Hi Bryan!
We appreciate you reaching us via our Community Forums.
Perhaps what you are trying to accomplish could be done with a Search and Replace function. There should be some tutorials online with examples.
Also, we would recommend reaching our complimentary Professional Services Department or one of our BarTender Partners in case you need further and more dedicated help with VBS scripting.
Cheers,0 -
Ok, I figured it out with the help of some community forums searches. I placed this in the OnPostPrompt section of the Event Control Scripts:
Dim patrn, patrnLen, strng, regEx, Match, Matches, i' Create variables
Dim Delim1, Delim3, Delim4, Delim5, Delim6, Delim8, Val_1, Val_3, Val_4, Val_5, Val_6, Val_8
Value = PARSETEST
Value = Format.NamedSubStrings("PARSETEST").Valuepatrn = "<CRTA>" 'This is the delimiter (text the seperates components within the string) for the QR code
patrnLen = Len(patrn)
strng = Value 'PARSETEST 'This is the Name of the QR code on the label AND what is scanned in at print time.Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = patrn ' Inputting the delimiter text we're looking for
regEx.Global = True ' True = pattern should match all occurrences in an entire search string
regEx.IgnoreCase = FalseSet Matches = regEx.Execute(strng) ' Execute search which finds the locations for ALL occurrences of the delimiter.
i=1 'setting counter to 1
For Each Match in Matches ' Iterate Matches collection.
select case i 'iterrating through delimiters to parse data
Case 1
Delim1 = Match.FirstIndex 'delimiter location
Val_1 = Mid(strng,1,Delim1) 'value of parsed information
Format.NamedSubStrings("PARTNO").Value = Val_1 'sending parsed data to named Data Sources (PARTNO is a named text box)
Case 3
Delim3 = Match.FirstIndex 'I'm only parsing some of the data
Case 4
Delim4 = Match.FirstIndex 'delimiter location
Val_4 = Mid(strng,Delim3+patrnLen +1,Delim4-Delim3-patrnLen) 'value of parsed information
Format.NamedSubStrings("WHSE").Value = Val_4
Case 5
Delim5 = Match.FirstIndex 'delimiter location
Val_5 = Mid(strng,Delim4+patrnLen +1,Delim5-Delim4-patrnLen) 'value of parsed information
Format.NamedSubStrings("LOT").Value = Val_5
Case 6
Delim6 = Match.FirstIndex 'delimiter location
Val_6 = Mid(strng,Delim5+patrnLen +1,Delim6-Delim5-patrnLen) 'value of parsed information
Format.NamedSubStrings("PRJ").Value = Val_6
Case 8
Delim8 = Match.FirstIndex 'delimiter location
Val_8 = Right(strng, Len(strng)-Delim8-patrnLen) 'value of parsed information
Format.NamedSubStrings("UOM").Value = Val_8
end select
i=i+1
Next0 -
Awesome! Thank you for sharing this with us! :)
0
Please sign in to leave a comment.
Comments
3 comments