iT邦幫忙

2

vba 掃描槍TextBox1

Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim WshShell, EE
   Dim intLen As Integer
  On Error Resume Next
       If KeyCode = 13 Then
If Len(Me.TextBox1.Text) And Len(Me.TextBox1.Text) <> 16 Then
Set WshShell = CreateObject("Wscript.Shell")
WshShell.popup "※字數不正確,請重新輸入!", 1, ""
Else
        If Me.Controls("TextBox1") <> "" Then
If Me.Controls("TextBox1") = Me.Controls("TextBox2") Then GoTo EE
        bcr = True
       Cells(Cells(Rows.Count, 1).End(xlUp).Row + 1, 2) = TextBox1.Text
            Cells(Cells(Rows.Count, 1).End(xlUp).Row + 1, 3) = TextBox2.Text
                   Cells(Cells(Rows.Count, 1).End(xlUp).Row + 1, 1) = Date
                ElseIf bcr = True Then
        bcr = False
    Else
    End If
        End If
        End If
            If KeyCode = 13 Then CommandButton1_Click
Exit Sub
EE: MsgBox WshShell.popup
Set WshShell = CreateObject("WScript.Shell")
EE = WshShell.popup(BtnCode, 1, "重複", 16)
   If KeyCode = 13 Then CommandButton1_Click
End Sub

Private Sub CommandButton1_Click()
  r = Len(Me.TextBox1.Text)
Me.TextBox1.SetFocus
Me.TextBox1.SelStart = 0
Me.TextBox1.SelLength = r
KeyCode = 13
TextBox1.Text = ""
  TextBox2.Text = ""
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

Dim r&, i&
If Target.Column = 2 And Target.Count = 1 Then
r = Target.Row
i = Application.CountIf(Range("B1:B" & r), Target.Value)
If i > 1 Then
Set WshShell = CreateObject("Wscript.Shell")
WshShell.popup Target.Value & "重複,請重新輸入!", 1, ""
End If
End If
If Target.Column = 3 And Target.Count = 1 Then
r = Target.Row
i = Application.CountIf(Range("C1:C" & r), Target.Value)
If i > 1 Then
Set WshShell = CreateObject("Wscript.Shell")
WshShell.popup Target.Value & "重複,請重新輸入!", 1, ""
End If
End If
      End Sub

各位前輩們,自己拼湊完成了一個掃描槍的程式,但現在出現一個問題,就是掃描,記錄到欄位後,會出現重複訊息的問題,應該是超過16碼的問題吧,請問有解嗎?謝謝

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
純真的人
iT邦大師 1 級 ‧ 2021-05-13 23:52:42

那個掃描槍~你應該要先開記事本測試~先測試是否輸出內容正常才對~
那個只是模擬鍵盤動作~掃描條碼輸出數字內容~

我要發表回答

立即登入回答