Results 1 to 7 of 7

Thread: What event does a barcode reader fire off?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    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:
    1. Private Sub txtBarcode_Leave(ByVal sender As Object, _
    2.         ByVal e As System.EventArgs) _
    3.         Handles txtBarcode.LostFocus
    4.  
    5.         LookUpItem()
    6.  
    7.     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?

  2. #2
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: What event does a barcode reader fire off?

    The TextChanged event should fire when the barcode reader fills the text box.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    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?

  5. #5
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    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:
    1. if e.KeyChar = 13 then
    2.     'If return key call LookUpItem()
    3. End if

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Re: What event does a barcode reader fire off?

    Thank you. This is what I ended up with
    VB Code:
    1. Private Sub txtBarcode_KeyDown(ByVal sender As Object, _
    2.         ByVal e As System.Windows.Forms.KeyEventArgs) _
    3.         Handles txtBarcode.KeyDown
    4.  
    5.         If e.KeyCode = Keys.Enter Then
    6.             LookUpItem()
    7.             ListBox1.Items.Add(lblItemName.Text)
    8.             txtBarcode.Clear()
    9.             txtBarcode.Focus()
    10.         End If
    11.     End Sub

  7. #7
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    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
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width