How to capture a post amble carriage return from data wedge input using a text box in vb.net?

1.1k views Asked by At

I have a simple app that is currently using an SDK, but this is causing memory problems, and I also want the app to run on multiple hand-held scanner types without being redone for each platform, if possible. So I decided to use the data wedge.

The scanned text is read into a text box (one character at a time) from the data wedge, the problem is the input from the scanner can be of varying lengths, so I need to capture the default [CR][LF] (carriage return and line feed) characters that are set in the post amble.

I've tried comparing the last characters of the string against Chr(13) and Chr(10) but couldn't get this to work. I'm using the TextChanged property of the text box to check for input to the box -

     Private Sub tbx_Scan_TextChanged() Handles TBX_Scan.TextChanged

And want to return a valid result from this function if an end-of-line is found

     Public Function CheckLocationInput(ByVal inputString As String) As String

      If (Len(inputString) >= 5) And (Len(inputString) <= 40) Then
          If inputString.Contains(Environment.NewLine) Then
              Return "VALID"  'Opens the Item Input Screen
          End If

But the [CR] and [LF] characters don't seem to be entered into the text box, or at least can't seen to be read. Basically all I'm trying to do is check for the end of the data wedge input. I can do this if I change the post-amble to a string E.g. '~E%'

I know the arguments against doing this this, but it should be a simple app, so I'd appreciate no, "you should use the SDK" answers.

So what is the best way to capture the non-printable characters using VB.net and/or C# from a data-wedge input?

Thank you.

1

There are 1 answers

0
Garry_G On

I couldn't get this reading a non-printable character from the end of the input to a text box. but I did manage to get around it by putting the following in the form. Then using Barcoding as my input string, as this does contain the non-printable codes at the end.

Imports System.Text
  Public Class frm

Private Barcode As StringBuilder

Private Sub frm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.KeyPreview = True
    Me.TBX_Scan.Focus()
    Barcode = New StringBuilder()
End Sub

Private Sub frm_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
    Barcode.Append(e.KeyChar)
End Sub