Android Question Barcode CODE128 - how to capture the barcode CRLF

mfstuart

Active Member
Licensed User
Longtime User
Hi All,
I've built an app that is to capture a scanned barcode using the Honeywell hand held model 1900.
The device is plugged into the tablet and while the EditText field is focused, the user triggers the scanner and the barcode is captured into the EditText field. No problem so far.

With CODE128, it is terminated with a CRLF character which I'm having trouble identifying.

I've tried using the Activity_KeyPress, but haven't had success capturing the complete barcode value HERE, in Post#6 from Erel.
I'm now trying the txtBarCode_TextChanged event.

With both of these event types, I'm unable to capture the CRLF.
B4X:
Sub txtBarcode_TextChanged (Old As String, New As String)
    If New.Contains(Chr(10)) Then
        Log("Has chr(10) in barcode")
    Else If New.Contains(Chr(13)) Then
        Log("Has chr(13) in barcode")
    Else If New.Contains(CRLF) Then
        Log("Has CRLF")
    Else if New = "10" Then
        Log("Has 10")
    Else If New = "13" Then   
        Log("Has 13")
    Else If New = CRLF Then
        Log("Pure CRLF")
    Else
        Log("Has no CRLF in barcode")
    End If
End Sub

I've also tried the various ZXing libraries (offered on this forum) using the camera, but the camera captures the same barcode over and over, which is no good.

I need to capture and identify the CRLF terminating string to know when to write the barcode to a local SQLite table.
So how is this done?

Thanx,
Mark S.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Mark, what ZXing libraries have you tried on the forum? Can you post a link to it? If the library includes an Event that will be raised in the B4A project then you can simply compare the new scanned result with the previous scanned result (or keep a list/map of codes scanned and run through the list/map to check for the same code having been scanned).
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User

I'm now using this approach to work with barcode input to a EditText field.
I think this is a better approach to handling the barcode input.
It seems the line feed is forcing the loss of focus of the txtBarCode field.

B4X:
Sub txtBarcode_FocusChanged (HasFocus As Boolean)
    If HasFocus = False Then
        btnAdd_Click
    End If
End Sub

When the Add button is pressed by the EditText field loosing focus, all the action to validate and process the barcode value is done:

B4X:
Sub btnAdd_Click
    Dim BarCode As String = txtBarcode.Text
   
    'if no barcode
    If BarCode = "" Then
        txtBarcode.RequestFocus
        SoundBeep(100,800)
        ToastMessageShow("Barcode required!",False)
    Else
        'else there is a barcode scanned,
        'get the item info: Description and Price
        Dim ItemInfo() As String
        ItemInfo = DBCalls.GetItemInfo(BarCode)
       
        'if the ItemInfo is valid
        If ItemInfo <> Null Then
            'if Item comes back as ITEM NOT FOUND
            If ItemInfo(0) = "ITEM NOT FOUND" Then
                txtBarcode.RequestFocus
                txtBarcode.Text = ""
                SoundBeep(100,800)
                ToastMessageShow("ITEM NOT FOUND!",False)
            Else
                'else we do have a valid scan,               
                'save to ScanDetail table
                Dim PLU As String = BarCode
                Dim ItemDesc As String = txtLastItemDesc.Text
                Dim ItemPrice As Double = txtLastPrice.Text
                Dim Qty As String = txtQty.Text
                If Qty.Contains(",") Then
                    Qty = txtQty.Text.Replace(",","")
                End If
                txtLastQty.Text = Qty
                'insert data
                DBCalls.SaveScanDetail(HID,PLU,ItemDesc,Qty,ItemPrice,Main.gUserID)
               
                'load Scanned Items - Top 20
                ScannedItems_ClearAll
                Load_ScannedItems
                SetScannedCount            
            End If
           
        Else
            'invalid scanned data
            txtBarcode.Text = ""
            txtBarcode.RequestFocus
            SoundBeep(100,800)
            ToastMessageShow("Invalid scanned data or setup incomplete!",False)
        End If
    End If
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…