tags:

views:

209

answers:

2

I have an interface in access that is using a barcode scanner to gather information. I would like to have a barcode that has multiple information in it example: a barcode that holds the value of an order and a specific item on that order.

I have items that are divided into "lot", these items are grouped into these lots by the specific item it is, 1 item type per lot. But an order can have multiple item types therefore multiple lots per order. I would like to add the order and lot number in one barcode.

It would look like O961LA1450

The asterisks begin and end the barcode. The O starts the order number 961. The L starts the lot number A1450.

I would like to define a delimiter, "L", to separate the barcode to compare the lot number to the lot number of the form to check that it is correct and then populate the order number on the form with the correct order number.

Can anyone explain how to define delimiters or have code snippets that they can offer. Any help would be appreciated.

+1  A: 

Very basic example:

Sub Main()

    Dim barcode As String

    barcode = "O961LA1450"

    ProcessBarcode (barcode)

End Sub

Function ProcessBarcode(barcode As String)

    Dim order As Long
    Dim lot As String
    Dim codes As Variant

    codes = Split(barcode, "L")
    order = CLng(Right(codes(0), Len(codes(0)) - 1))
    lot = codes(1)

    'for testing purposes:
    Debug.Print "Order: " & order & " Lot: " & lot
    'do comparing against other values here

End Function

Results in:

Order: 961 Lot: A1450
Marc
Thank you very much, that was exactly what I needed!
gary A.K.A. G4
A: 

It's customary for this kind of data to use fixed-length fields, so that you'd allocate, say, 4 characters to the Order Number and five for the Lot Number, so that this:

  0961A1450

Would be parsed:

  Order Number: Left("0961A1450", 4)
  Lot Number:   Mid("0961A1450", 5, 5)

The only reason to waste space on delimiters is when the data is variable length. I'd probably allocate 5 characters to the order number and 6 to the lot number for future proofing (and pad appropriately). For instance, the example would be encoded as:

  00961A01450

...and you'd probably want to parse it this way in order to strip out the leading zeroes:

  Order Number: Val(Left("00961A01450", 5))
  Lot Number:   Mid("00961A01450", 6, 1) & CStr(Val(Mid("00961A01450", 7, 5)))

After all that, it does seem like delimiters would be easier, but I've never encountered barcode data that used them. If you're only encoding two pieces of data, it could be much easier, as you'd allocate the first N places to your first piece of data, and everything after that would be your other piece, and it could be any length.

David-W-Fenton