by Mike Reed (4 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Fri 5th May 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
A hand held serial scanner can be used to scan into field.
API Declarations
Please NOTE: The scanner must be programmed to the setting set to 9600 E 8 1 with bar code type 39 and programmed with CR turn on.
Private Sub MSComm1_OnComm()
'On data from scanner
Dim CheckMyScan As String
Dim CheckForCR As String
Dim MyText As String
Dim CountMe As Integer
Dim Counter As Integer
Dim Number As Integer
On Error GoTo Mscomm11:
If MSComm1.CommEvent = 2 And MSComm1.InBufferCount > 0 Then
CheckMyScan = MSComm1.Input
MyText = CheckMyScan
Text1.Text = CheckMyScan
CountMe = Len(Text1.Text)
Number = 0
Do Until Counter = CountMe 'looking for the CR from the scanner
Text1.SelStart = Number
Text1.SelLength = Len(Text1.Text)
CheckForCR = Text1.SelText
'If CR then reset the port, clean up Text1.Text
'and set the focus on the next Text box.
If CheckForCR = vbCr Then
Text1.Text = (MyText) - vbEnter
MSComm1.PortOpen = False
MSComm1.PortOpen = True
Text2.SetFocus
Exit Sub
End If
DoEvents
Number = Number + 1
Counter = Counter + 1
Loop
End If
Exit Sub
Mscomm11:
MsgBox "A error in reading this bar code", vbOKOnly, "Your title caption here"
End Sub