Android Question Updating a Label from a Sub Function

algPoS

New Member
Hi everyone

WELL I have taken the plunge and have started Working on our Android Hand held application

So far it is going ok we have 60% of the screen redone and working on the Zebra TC55 Hand held

But I am stuck on a function

In Windows Mobile I was allowed to have all my Database functions in one sub file and I could call them from any part of the program and update labels.

But in B4A its crashes if I try the following

B4X:
Public Sub LegalCheck_FindIteminDatabase(BarcodeNumber As String)
    Dim SQLCommand As String = ""
    
    SQLCommand = SQLCommand + "Select "
    SQLCommand = SQLCommand + "posdescription "
    SQLCommand = SQLCommand + "from producttable "
    SQLCommand = SQLCommand + "where barcodenumber='" + BarcodeNumber + "';"
    
End Sub

And just so I know the code has worked I wanted to update the label2 on the b4XLegalCheck (and the Desgin screen is called LegalCheck) but when ever I try I crash the App

I have tried to use b4XLegalCheck.label2.text = "This is from the DB Sub" and I have tried LegalCheck.label2.text = "This is from the DB Sub" and nothing

I have even tried to do it as a Return function and that also crashes my app.

I would like to get this working as when I scan items and recall the data from the database the Product name is to be shown on label2 (example if I scan 50201600 then the App would show "Cadburys Cream Egg" on the label.

Does anyone know what I am doing wrong I can attach my full project if that helps as it is only forms at the moment and not much code.
 

aeric

Expert
Licensed User
Longtime User
LegalCheck_FindIteminDatabase
This is a bad function signature.
The left side of the underscore is same as a view's name and the right side can denotes the event's name.

How to you declare the view?
B4X:
Private LegalCheck As Label
or
B4X:
Private LegalCheck As B4XView
Either way, you can just assign the value by using the Text method/property.
B4X:
LegalCheck.Text = BarcodeNumber

Not sure how you write your app. Usually, you can scan the barcode and assign it to a EditText view. You can use the TextChanged event.
B4X:
Private Sub EditText1_TextChanged (Old As String, New As String)
    Log(New)
End Sub

From the value you got, you can do a query to the database and retrieve the required fields.
 
Upvote 0
Top