2

For example I have this form:

As you can see I have Barcode textbox, and 6 more textboxes. What I need is a code that will parse my barcode from the textbox and fill in the remaining fields. The parenthesis ie (), and the numbers inside it, have to be deleted.

LINK TO IMAGE

Here is example of my barcode

(1)CODE1(3)NAME(4)SURNAME(8)CODE2(10)CODE3(12)CODE4

For now I have this code:

Private Sub Barcode_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Barcode.Leave
    Dim Duzina As String = Me.Barcode.Text.Length
    Dim I As Integer = 0
    Dim Slog As String = ""
    Dim Rec As String = Me.Barcode.Text
    For I = 4 To Duzina
        If Rec.Substring(I, 1) = "(" Then
            Me.Surname.Text = Slog
            Exit For
        End If
        Slog = Slog + Rec.Substring(I, 0)
    Next

End Sub

So when the barcode loads into the first textbox, it should fill up all the other textboxes.

4

4 回答 4

2

我的简单解决方案

Private Sub Barcode_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Barcode.Leave
    Dim codes = barcodeTextBox.Text.Split("("c)
    Dim code1 = codes(1).Split(")"c)
    Dim name = codes(2).Split(")"c)
    Dim surename = codes(3).Split(")"c)
    Dim code2 = codes(4).Split(")"c)
    Dim code3 = codes(5).Split(")"c)
    Dim code4 = codes(6).Split(")"c)

    sureNameTextBox.Text = surename(0).ToString()
    nameTextBox.Text = name(0).ToString()
    code1TextBox.Text = code1(0).ToString()
    code2TextBox.Text = code2(0).ToString()
    code3TextBox.Text = code3(0).ToString()
    code4TextBox.Text = code4(0).ToString()
End Sub

替代解决方案

Private Sub Barcode_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Barcode.Leave
    Dim codes = barcodeTextBox.Text.Split("("c)
    Dim code1 = codes(1).Split(")"c).FirstOrDefault()
    Dim name = codes(2).Split(")"c).FirstOrDefault()
    Dim surename = codes(3).Split(")"c).FirstOrDefault()
    Dim code2 = codes(4).Split(")"c).FirstOrDefault()
    Dim code3 = codes(5).Split(")"c).FirstOrDefault()
    Dim code4 = codes(6).Split(")"c).FirstOrDefault()

    sureNameTextBox.Text = surename
    nameTextBox.Text = name
    code1TextBox.Text = code1
    code2TextBox.Text = code2
    code3TextBox.Text = code3
    code4TextBox.Text = code4
End Sub
于 2013-01-28T12:20:08.520 回答
1

我已经这样做了

Private Function CitanjeBarkoda() As Boolean
    Dim Duzina As String = Me.TextBox8.Text.Length
    Dim I As Integer = 0
    Dim Slog As String = ""
    Dim Rec As String = Me.TextBox8.Text
    Dim BrOz As Integer = 0
    Dim BrZz As Integer = 0
    Dim NizOz As New ArrayList
    Dim NizZz As New ArrayList
    Dim Slog1 As String = ""


    For I = 0 To Duzina - 1
        If Rec.Substring(I, 1) = "(" Then
            BrOz = BrOz + 1
            NizOz.Add(I)
        End If
        If Rec.Substring(I, 1) = ")" Then
            BrZz = BrZz + 1
            NizZz.Add(I)
        End If



    Next
    Me.TextBox10.Text = Rec.Substring(NizZz(0) + 1, NizOz(1) - NizZz(0) - 1)
    Me.IMEOSOBE = Rec.Substring(NizZz(1) + 1, NizOz(2) - NizZz(1) - 1)
    Me.PREZIMEOSOBE = Rec.Substring(NizZz(2) + 1, NizOz(3) - NizZz(2) - 1)
    Me.TextBox3.Text = Rec.Substring(NizZz(3) + 1, NizOz(4) - NizZz(3) - 1)
    Me.BRKART = Rec.Substring(NizZz(4) + 1, NizOz(5) - NizZz(4) - 1)
    Me.TextBox5.Text = Rec.Substring(NizZz(5) + 1, NizOz(6) - NizZz(5) - 1)
return true
End function
于 2013-01-29T08:43:02.867 回答
0

实际上,标题有点误导。它应该是字符串解析而不是条形码解析。不管怎样,你可以试试这个。

Private Sub Barcode_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Barcode.Leave
    Dim pvsBarcodeRAW As String = Trim(Me.Barcode.Text.Length)
    Dim voNVC As New System.Collections.Specialized.NameValueCollection

    Dim vasCodePairs() As String = Split(pvsBarcodeRAW, "(")
    For Each vsCodePair As String In vasCodePairs
        vsCodePair = Trim(vsCodePair)
        If vsCodePair.Length > 0 Then
            Dim vasCodePair() As String = Split(vsCodePair, ")")
            If vasCodePair.Length = 2 Then
                Select Case vasCodePair(0)
                    Case 1
                        voNVC("Code1") = vasCodePair(1)
                    Case 3
                        voNVC("Name") = vasCodePair(1)
                    Case 4
                        voNVC("SurName") = vasCodePair(1)
                    Case 8
                        voNVC("Code2") = vasCodePair(1)
                    Case 10
                        voNVC("Code3") = vasCodePair(1)
                    Case 12
                        voNVC("Code4") = vasCodePair(1)
                End Select
            End If
        End If
    Next

    'Now you can do whatever you want with the variables in the voNVC variable.
    SurName.Text = voNVC("SurName")
End Sub
于 2013-01-28T11:39:49.790 回答
0

在扫描仪上输入启用了键盘映射$I的 Code 39 条形码。 $I就像键盘上的 TAB 键一样。

一次扫描

CODE1$INAME$ISURNAME$ICODE2$ICODE3$ICODE4

将填充此:CODE1 NAME SURNAME CODE2 CODE3 CODE4

话虽如此,Code 39 不适用于长条码。您可以使用 QR,但那里的选项卡有点复杂,但仍然可行。您还需要一台 2D 扫描仪。

于 2016-08-30T19:34:52.430 回答