2

(I'm using VS2008 with EMDK v2.9 with Fix1)

I have a form, where I declare my reader:

Private WithEvents barcodeReader As Barcode.Barcode = New Barcode.Barcode

I want it to be active only in one of the controls on the form, so I do this:

Private Sub txbAccount_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txbAccount.GotFocus
barcodeReader.EnableScanner = True
End Sub

And turn it off the same way in the Lost Focus event of that textbox.

Here is the OnRead sub:

Private Sub barcodeReader_OnRead(ByVal sender As Object, ByVal readerData as Symbol.Barcode.ReaderData) Handles barcodeReader.OnRead
If (readerData.HasReader) Then
    Try
        Dim ctrl As TextBox = Ctype(GetActiveControl(), TextBox)
        If (ctrl.Name = "txbAccount") Then
            ctrl.Text = readerData.Text
        End If
    Catch ex As Exception
        MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
End If
End Sub

The problem is: as soon as I enable scanner in the GotFocus event of the textbox, the OnRead event will fire over and over (with empty data) until I actually press the scan key, scan actual data - then it stops.

I've read that maybe the Handled property is not getting set properly, however I don't see property like that for this.

Yuropoor
  • 354
  • 2
  • 17

1 Answers1

0

Quick question to answer is the handledis usualy within the e eventargs (although I dont see any in that routine just readerdata it may be in there!?

On a side, with barcode scanners they usualy use the sendkeys commands to simply pass string through to the system. These can be trapped easily by using any of the OnKeyPress / OnKeyDown... etc. If you wanted to go down this route, you'll need to take each keypress / down as aan individual character, whereas your barcode.OnRead might do all that for you. (Again I havent used the EMDK you reference).

Lastly 'usualy' barcode scanners end with a cr (carriage return) some barcode scanners can turn this off, or change these in settings. If not this might be where the e.handled referenced elsewhere is talking about. This would be something like ..

 if e.KeyChar = Chr(Keys.Enter) then
      e.handled = true
 end if

This would stop the send going to the object (textbox) and therfore not losing focus (as the enter key wasn't passed)

Hope this helps.. a bit :) Chicken

Chicken
  • 428
  • 3
  • 11