Click here to Skip to main content
15,910,980 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a VB.net program that has textboxes that get populated via a barcode scanner. For things to work properly, the barcode scanner needs to be formatted with a "Tab" suffix. Every once in a while, the barcode scanners get replaced and end up getting formatted with the wrong suffix. Usually what happens is they get formatted with an "Enter" vs a "Tab". This can sometimes cause issues because if a button has focus after the barcode, the enter will "click" the button. To address this issue, I am trying to write code to validate the barcode scanner is formatted with a "Tab". I thought I could use the keydown event but it is not detecting the tab from the barcode reader. I made sure I set the AcceptsTab property of the textbox to True and I also set the multiline property to true. If I actually press the tab key via the keyboard, it recognizes the tab but not from the barcode reader. I went ahead and reformatted the barcode reader to add the tab suffix and I can see the tab when I scan the barcode into NotePad. Any ideas on why this is not working? It is matters, I am using a Honeywell 3800G scanner with USB input.

What I have tried:

Private Sub TxtSequenceBarcode_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TxtSequenceBarcode.KeyDown

        Debug.WriteLine("KeyDown = " & e.KeyCode)

        If e.KeyCode = Keys.Tab Then
            Debug.WriteLine("Tab Found via KeyDown")
        End If
    End Sub
Posted
Updated 31-Oct-18 5:06am
Comments
MadMyche 31-Oct-18 12:31pm    
Do you have the ability to use the scanner management program to make sure it has the correct prefix/suffix
theskiguy 1-Nov-18 6:56am    
Yes I do. As I mentioned above, I did reprogram it just to make sure. I first removed all suffixes and tested the output in Notepad and noticed there was no tab. I then added the tab suffix to the barcode reader and tested it again in Notepad and I could see the tab added.

1 solution

The problem is that if the barcode scanner isn't set, it won't give you a TAB at all - it will just give you the numbers it scans, with no prefix or suffix info. And you can;t tell if that numeric infor was typed or scanned as Windows doesn't keep that kind of information.

The only way to detect the absence of a TAB is to set up a timer when you receive the actual data and clear if it you do receive a TAB key. If the timer expires after a "reasonable time (a couple of seconds maybe) then you didn't get a TAB.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900