I got the list of UPC codes they are 10 digit (Some 11 some 5 but they are outside of the range I need to look at) numbers only. There are 450 total but I think we will only see about 300 on the line we are working on. I want to look at the barcode and if it is within range 1 turn on output 1, if it is within range 2 turn on output 2, if within range 3 turn on output 3, if not 1 2 or 3 turn on output 4. The first 5 numbers for ranges 1,2 and 3 are all the same. Any suggestions on the best way to do this?
I agree with 'nut...except for one possible caveat. The range of a 32 bit integer is -2147483648 to 2147483647, or for our purposes, 0 to 2147483647. If the first 5 digits are less than or equal to 21474xxxxx, then yes STREAMIN to read data, STR2INT to convert, and a handful of relational contacts to do the compares and set bits.
If the first 5 are outside that range, then you will need to do some string processing to lop off the first 5 characters and first compare them to your 1, 2, and 3 ranges first 5, and then if they match do a STR2INT on the last 5 digits and do the compares.
If there are different lengths of codes, which it sound like there is, you will first have to normalize the input string to a known fixed length before doing the other work.
Conceptually it might end up being something like this (in psuedocode):
InputStr = StreamIn()
if(InputStr.Length > 10)
Group = 4
else
NormalizedStr = FmtString(InputStr, 10, right)
Left5Digits = StrSub(NormalizedStr, 5, left)
if(Left5Digits != Group123Prefix)
Group = 4
else
Right5Digits = StrSub(NormalizedStr, 5, right)
BarCodeValue = Str2Int(Right5Digits)
if(BarCodeValue >= Group1Start && BarCodeValue <= Group1End)
Group = 1
else if(BarCodeValue >= Group2Start && BarCodeValue <= Group2End)
Group = 2
else if(BarCodeValue >= Group3Start && BarCodeValue <= Group3End)
Group = 3
else
Group = 4