VBA条形码扫描仪只返回第一个数字,如何返回完整数字



当我扫描条形码时,它只显示TextBox1中条形码的第一个数字,而不是全长数字,这不允许我测试除"格式错误";我想有完整的条形码,这样其他条件可以测试。

Private Sub TextBox1_Change()
Dim scan As String
Dim premier As Integer
Dim deuxieme As Integer
Dim troisieme As Integer
Dim quatrieme As Integer
scan = TextBox1

premier = InStr(1, scan, "-")
deuxieme = InStr(premier + 1, scan, "-")
troisieme = InStr(deuxieme + 1, scan, "-")
quatrieme = InStr(troisieme + 1, scan, "-")

If premier = 9 And deuxieme = 18 And troisieme = 22 And quatrieme = 27 Then
magnetA = InStr(1, scan, "A")
magnetB = InStr(1, scan, "B")
disque = InStr(1, scan, "D")

'MAGNET A'
If magnetA = 28 Then
TextBox1.BackColor = RGB(0, 255, 0)
TextBox2.SetFocus
MsgBox "Magnet A detecté !"
End If

'MAGNET B'
TextBox1.BackColor = RGB(0, 255, 0)
If magnetB = 28 Then
TextBox2.SetFocus
MsgBox "Magnet B detecté !"
End If

'DISC  '
TextBox1.BackColor = RGB(0, 255, 0)
If disque = 28 Then
TextBox2.SetFocus
MsgBox "Disque detecté !"
End If

End If

'WRONG FORMAT'
If premier = 0 And deuxieme = 0 Then
TextBox1.BackColor = RGB(255, 0, 0)
MsgBox "format incorrect !"
TextBox1.BackColor = RGB(255, 255, 255)
TextBox1 = ""
End If

'BRAKE'
If premier = 9 And deuxieme = 11 Then
TextBox1.BackColor = RGB(0, 255, 0)
TextBox2.SetFocus
MsgBox "Numero frein detecté !"
End If
End Sub

条形码扫描仪充当pc的键盘,只有在第一个";键";按下。

扫描仪可能会在整个条形码打印出来后添加CR/LF,或者可以配置为,所以你应该在它离开单元格后激发它来检查整个值。

最新更新