Android Question for..next and sql problem

tufanv

Expert
Licensed User
Longtime User
hello

I have h0 and h1 coloumns in my sql file. i want lbl0 and lbl1 text to be the values h0 and h1 in sql file. I want to use arrays becausethere are many of them. I am using the code :

B4X:
  Dim adet,v As String
Dim lbl(15) As String
adet = cursormyraces.RowCount -1
Dim n As Int
n=0
For n=0 To adet
v= "h" & n
lbl(n) = cursormyraces.GetString(v)
lbl0.Text = lbl0
lbl1.Text = lbl1
Next

When i run the program ii see that lbl0.text and lbl1.text is android.widget.textview.....

It doesnt make any sense . Any ideas ?
 

tufanv

Expert
Licensed User
Longtime User
you are right but when i use
lbl(n).text =cursormyraces.GetString(v)
it does not recognize it as lbl0.text lbl1.text ... etc
i am doing something wrong .
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
What exactly do you want to do ?
How many Labels do you have and how and where do you define them ?
You dimed Dim lbl(15) As String
these are strings and not Labels.
Your code looks strange to me.
You Dim adet As String but you use it as an Int ?
You set adet = cursormyraces.RowCount -1
In the For / Next loop you go through the rows
but then you use the row index as the column index ?!
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
ok pls forget everything.
I have a sql file with 1 row only and it has 15 coloumns car1,car2 ....car15 etc
i want lbl1.text = cursormyraces.getstring("car1"), lbl2.text = cursormyraces.getstring("car2") .... until car15
but i dont want to write this code one by one
 
Upvote 0

Reviewnow

Active Member
Licensed User
Longtime User
if you don't want to write all the code, I would suggest looking at the dbutils class
and use the ShowTableInWebView

Sorry did not see that your table had one row

B4X:
cursormyraces = dbSQL.ExecQuery("SELECT * FROM mytable LIMIT 1")
if cursormyraces.rowCount > 0 then
For I = 0 To cursormyraces.RowCount - 1
               
    DoEvents

    cursormyraces.Position = I

    lbl1.Text = cursormyraces.GetString("Car1")
    lbl2.Text = cursormyraces.GetString("Car2")
    lbl3.Text = cursormyraces.GetString("Car3")
    lbl4.Text = cursormyraces.GetString("Car4")
    lbl5.Text = cursormyraces.GetString("Car5")
    lbl6.Text = cursormyraces.GetString("Car6")
    lbl7.Text = cursormyraces.GetString("Car7")
    lbl8.Text = cursormyraces.GetString("Car8")
    lbl9.Text = cursormyraces.GetString("Car9")
    lbl10.Text = cursormyraces.GetString("Car10")
    lbl11.Text = cursormyraces.GetString("Car11")
    lbl12.Text = cursormyraces.GetString("Car12")
    lbl13.Text = cursormyraces.GetString("Car13")
    lbl14.Text = cursormyraces.GetString("Car14")
    lbl15.Text = cursormyraces.GetString("Car15")



Next
Else
Log("No Records found for cursormyraces")
End if
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
You could do it like this:
B4X:
Dim lbls(15) As Label

lbls = Array As Label (lbl1, lbl2, lbl3, lbl4, lbl5, lbl6, lbl6, lbl8, lbl9, lbl10, lbl11, lbl12, lbl13, lbl14, lbl15)

If cursormyraces.rowCount > 0 Then
    For i = 0 To cursormyraces.ColumnCount - 1
        lbls(i).Text = cursormyraces.GetString("Car" & (i + 1))
    Next
Else
    Log("No Records found for cursormyraces")
End If
Not tested.
 
Upvote 0
Top