What event does a barcode reader fire off?
I am trying to figure out how to do an automatic inventory look up using a barcode reader. Right now I have items in my database that I can retrieve by scanning an item and then tabbing out of the textbox with code like this.
VB Code:
Private Sub txtBarcode_Leave(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles txtBarcode.LostFocus
LookUpItem()
End Sub
However, I want to be able to scan an item and have the lookup happen automatically without the user having to press tab, enter or mouse out of the text box. I have tried various textbox events but none have done what I need it to do.
After a scan an item I do get a sound like the scanner is trying to fire an event but the program doesn't know what to do with it. Any ideas?
Re: What event does a barcode reader fire off?
The TextChanged event should fire when the barcode reader fills the text box.
Re: What event does a barcode reader fire off?
Most barcode scanners are connected to the keyboard port, although more and more are and will be USB. Basically, using a barcode scanner is akin to typing the same characters in from the keyboard. I could be wrong but I'm guessing that the TextChanged event will be raised for each character in the barcode, as opposed to just once for the whole thing.
Re: What event does a barcode reader fire off?
jmcilhinney you are correct. The text changed does raise an event for each character in the code. The reader I am using is a USB device and as you stated it essentially a series of keyboard entries.
The more I have played with this device the more I am sure that that it is adding an "enter" at the end of the barcode. How would I go about trapping that enter and using it to do the look up?
Re: What event does a barcode reader fire off?
instead of text_changed you could try using the keyPress event and then check if the KeyPress was a Carriage return and if it was then call LookUpItem().
VB Code:
if e.KeyChar = 13 then
'If return key call LookUpItem()
End if
Re: What event does a barcode reader fire off?
Thank you. This is what I ended up with
VB Code:
Private Sub txtBarcode_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles txtBarcode.KeyDown
If e.KeyCode = Keys.Enter Then
LookUpItem()
ListBox1.Items.Add(lblItemName.Text)
txtBarcode.Clear()
txtBarcode.Focus()
End If
End Sub
Re: What event does a barcode reader fire off?
Just a thought - Last time I made an app for a barcode scanner, I got stuck with one that couldn't be programmed to put enter after the read. I used a timer to find out how long it had been since the last character was entered, and if it was more than a second, I processed the barcode. Hopefully they'll stick with the one you've got :)
Bill