简体   繁体   English

在vba中定义分隔符以进行访问

[英]defining delimiters in vba for access

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. 我有一些物品被分为“很多”,这些物品按照特定的物品分组到这些批次中,每批次1种。 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* 看起来像* O961LA1450 *

The asterisks begin and end the barcode. 星号开始和结束条形码。 The O starts the order number 961. The L starts the lot number A1450. O以订单号961开始。L以批号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. 我想定义一个定界符“ L”,以分隔条形码以将批号与表格的批号进行比较以检查其正确性,然后在表格上填充正确的订单号。

Can anyone explain how to define delimiters or have code snippets that they can offer. 谁能解释如何定义定界符或提供其代码段。 Any help would be appreciated. 任何帮助,将不胜感激。

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

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: 通常,此类数据使用固定长度的字段,因此您要为订单号分配4个字符,为批号分配5个字符,这样:

  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). 我可能会为订单号分配5个字符,为批号分配6个字符,以便将来打样(并适当填充)。 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. 如果您仅编码两个数据,则可能会容易得多,因为您将前N个位置分配给了第一个数据,之后的所有内容将是您的其他数据,并且可以是任意长度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM