Android Question Lookup Table problem with Parsing ABZXing data with SQL cursor which is Double, Int / Long

Discussion in 'Android Questions' started by Devan, May 14, 2015.

  1. Devan

    Devan Member Licensed User

    Hi There,
    Good day to All. First of all I would like to thank GabrielM for his SQL Lookup Table. With just minor changes the Lookup Table was super.
    I found 2 problems :
    1. Minor Problem: 1st line cannot read from the table.
    2. Major Problem: is cannot parse ABZxing scanned code which is in String, but the Cursor1 is using Double/Int/ Long cannot function properly. My table consist of Numbers & also Letters and combination 0f both. How to parse data between all the parameter seamlessly without any problems.
    Below is my code & Table.

    Thank you guys for your support.

    Sub itemABBarcode_BarcodeFound(barcode As String, formatName As String)
    Msgbox(barcode, "")
    Dim result_vector As Double
    Dim lookup_vector As Double
    Dim lookup_value As Double
    Dim lookup_pre, lookup_post As Double
    Dim Cursor1 As Cursor
    Cursor1 = SQL2.ExecQuery("SELECT Barcodeold, Barcodenew FROM F")
    lookup_value = barcode 'parameter_value
    For i = 0 To Cursor1.RowCount - 1
    Cursor1.Position = i
    lookup_vector = Cursor1.Getdouble("Barcodeold")
    'Log(Cursor1.GetDouble("ID"))
    Log(Cursor1.GetDouble("Barcodeold"))
    If lookup_vector = lookup_value Then
    lookup_post = lookup_vector - lookup_value
    Cursor1.Position = i
    lookup_pre = Cursor1.Getdouble("Barcodeold")
    Cursor1.Position = i - 1
    lookup_pre = lookup_value - lookup_pre
    If lookup_post = lookup_pre Then
    Cursor1.Position = i
    result_vector = Cursor1.Getdouble("Barcodenew")
    EdTextItemCode.Text = result_vector
    Else
    'Cursor1.Position = i - 1
    'result_vector = Cursor1.GetDouble("Barcodenew")
    'Cursor1.Position = i
    End If
    Cursor1.Close
    Exit
    End If
    Next
    End Sub

    My Table in .txt created using Notepad.
    556789, 45789,
    342145, 90567, Mop
    G223457, U78429,
    1, 2,
    10E, 20, A
    B44512316S, F10,
    556789, V45789,
    4895057865995, F65995,
    4895125708476, F08476,
    9555668700034, V00034,
    4895057870098, F70098,
    4895125745617, F45617
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.

    I'm not sure that I understand the question. You should use Cursor.GetString with text columns.
     
  3. Devan

    Devan Member Licensed User

    Hi Mr.Erel,
    Thank you for prompt feedback.
    Yes it works fine with String & Cursor1.GetString. thank you.
    But now, only problem is if the list consist of SKU/ item number with letters and numbers then the output in the log is 0.
    Do I need to convert (G223456S) Unicode into String?
    Thank you

    Code:
    Sub itemABBarcode_BarcodeFound(barcode As String, formatName As String)
        
    Msgbox(barcode, "")
        
    'EdTextItemCode.Text = barcode
           
            
    'After Scanner catch 12 digit barcode than below code will match & search for the correct 5 digit barcode frm F.db database.
           
             
    Dim result_vector As String
             
    Dim lookup_vector As String
             
    Dim lookup_value As String
               
    Dim lookup_pre, lookup_post As String
               
    Dim Cursor1 As Cursor
               Cursor1 = SQL2.ExecQuery(
    "SELECT Barcodeold, Barcodenew FROM F")
               lookup_value = barcode 
    'parameter_value                     
              
        
    For i = 0 To Cursor1.RowCount - 1                  
              Cursor1.Position = i
               lookup_vector = Cursor1.GetString(
    "Barcodeold")
             
    'Log(Cursor1.GetInt("ID"))
             Log(Cursor1.GetInt("Barcodeold"))
            
             
    'Below Function: Should compare the scanned barcode against Stock List and find the correct Stock Number
          If  lookup_vector = lookup_value Then
                 lookup_post = lookup_vector - lookup_value   
                Cursor1.Position = i
                 lookup_pre  = Cursor1.GetString(
    "Barcodeold")          
                 Cursor1.Position = i - 
    1
                 lookup_pre  = lookup_value -  lookup_pre
            
             
    If   lookup_post = lookup_pre Then  
                     Cursor1.Position = i
                    result_vector = Cursor1.GetString(
    "Barcodenew")
                   
                    
    'Below To show final result in the Edit Text on the screen
                    EdTextItemCode.Text = result_vector
             
    Else
                     
    ' if there is no alternate result than no need below code.
                 Cursor1.Position = i - 1
                result_vector = Cursor1.GetString(
    "Barcodenew")
                Cursor1.Position = i
               
             
    End If
             Cursor1.Close
             
    Exit
          
    End If
        
    Next
    End Sub
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Your code still calls Cursor.GetInt.
     
  5. Devan

    Devan Member Licensed User

    Hi Erel,
    I already change the below code from GetInt to GetString.
    Log(Cursor1.GetString("Barcodeold"))
    But I still get below errors? Any suggestion
    Thank you
    Cheers



    ** Activity (main) Pause, UserClosed = false **
    ** Activity (main) Create, isFirst = true **
    ** Activity (main) Resume **
    ** Activity (main) Pause, UserClosed = false **
    ** Activity (layout2) Create, isFirst = true **
    ** Activity (layout2) Resume **
    ** Activity (layout2) Pause, UserClosed = false **
    sending message to waiting queue (OnActivityResult)
    running waiting messages (1)
    342145
    G223457
    1
    10E
    B44512316S
    Error occurred on line: 523 (layout2)
    java.lang.NumberFormatException: Invalid double: "B44512316S"
    at java.lang.StringToReal.invalidReal(StringToReal.java:63)
    at java.lang.StringToReal.parseDouble(StringToReal.java:269)
    at java.lang.Double.parseDouble(Double.java:295)
    at b4a.example.layout2._itemabbarcode_barcodefound(layout2.java:1198)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:305)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:163)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
    at com.AB.ABZxing.ABZxing$1.ResultArrived(ABZxing.java:96)
    at anywheresoftware.b4a.BA$5.run(BA.java:505)
    at anywheresoftware.b4a.BA.setActivityPaused(BA.java:390)
    at b4a.example.layout2$ResumeMessage.run(layout2.java:271)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:150)
    at android.app.ActivityThread.main(ActivityThread.java:5406)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
    ** Activity (layout2) Resume **
    ** Activity (main) Resume **
     
  6. DonManfred

    DonManfred Expert Licensed User

    Without seeing your code it is hard to answer. But you are trying to convert the string to a double and get an Exception. "B44512316S" cannot cast to a double.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    What is line 523?
     
  8. Devan

    Devan Member Licensed User

    Hi DonManfred,
    I already shared the code earlier....
    Maybe you can check & see.
    anyway thanks buddy...
     
  9. Devan

    Devan Member Licensed User

    Hi Erel,
    Below is the line 523
    Code:
    lookup_post = lookup_vector - lookup_value
     
  10. DonManfred

    DonManfred Expert Licensed User

    So loockup_post seems to be a double. But loockup_vetor or lookup_value seems to be a string which is not parseable
     
  11. Devan

    Devan Member Licensed User

  12. DonManfred

    DonManfred Expert Licensed User

    I think you should have enough informations now to fix it by yourself...
    Put log-commands to create log output and see whathappen
    think over the problem and think over what you are doing and what can be wrong
     
    Devan likes this.
  13. Devan

    Devan Member Licensed User

    :p:D:) Hey..Hey... manage to cheat the system. As your advice I log the messages every stage and manage to find out it should give 0. So I define lookup_pre, lookup_value & lookup_vector = 0. Now te system can read mix barcode.... Thanks to DonManfred & Erel.
    I hope my Lookup Table can be useful for others projects in future...

    Code:
    Sub itemABBarcode_BarcodeFound(barcode As String, formatName As String)
        
    Msgbox(barcode, "")
        
    'EdTextItemCode.Text = barcode
           
            
    'After Scanner catch barcode than below code will match & search for the correct 5 digit barcode frm F.db database.
             Dim result_vector As String
             
    Dim lookup_vector As String
             
    Dim lookup_value As String
               
    Dim lookup_pre, lookup_post As String
               
    Dim Cursor1 As Cursor
               Cursor1 = SQL2.ExecQuery(
    "SELECT Barcodeold, Barcodenew FROM F")
               lookup_value = barcode 
    'parameter_value (Scanned Barcode Data)         
              
        
    For i = 0 To Cursor1.RowCount - 1                  
              Cursor1.Position = i
               lookup_vector = Cursor1.GetString(
    "Barcodeold")
             
    'Log(Cursor1.GetString("ID"))
             Log(Cursor1.GetString("Barcodeold"))
            
             EdTextItemCode.Text = 
    ""    'To clear the area from previous scan data.
            
             
    'Should convert string/ Text into number/ Interger. This is for combination barcode
             'such as G223415/ 223457H/ S7899R123P. current code cannot execute this type of barcode.
             'because lookup_post = lookup_vector - lookup_value gives 0.
             'lookup_value & lookup_vector should be convert to number/ int/ string
             
            
    'Below Function: Should compare the scanned barcode against Stock List and find the correct Stock Number
              'lookup_vector; lookup_value; lookup_pre = 0 in order to catch non number barcode results. (G223457,
            'B44512316S and so on).
          If  lookup_vector = lookup_value Then
                  lookup_vector = 
    0
                lookup_value = 
    0
                
    Log(lookup_vector)
                 lookup_post = lookup_vector - lookup_value
                
    Log(lookup_post)
                Cursor1.Position = i
                 lookup_pre  = Cursor1.GetString(
    "Barcodeold")  
                
    Log(lookup_pre)
                 Cursor1.Position = i - 
    1
                lookup_pre = 
    0
                 lookup_pre  = lookup_value -  lookup_pre
                
    Log(lookup_pre)
               
             
    If   lookup_post = lookup_pre Then 
                     
    Log("")
                     Cursor1.Position = i
                    
    Log(Cursor1.Position)
                    result_vector = Cursor1.GetString(
    "Barcodenew")
                    
    Log(result_vector)
                   
                    
    'Below To show final result in the Edit Text on the screen
                    EdTextItemCode.Text = result_vector
             
    Else
                    
                    
    ' if there is no alternate result than no need below code.
                Cursor1.Position = i - 1
                result_vector = Cursor1.GetString(
    "Barcodenew")
                Cursor1.Position = i
               
             
    End If
            Cursor1.Close
             
    Exit
            
          
    End If
        
    Next
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice