B4J Question reading from a simple list

Pelky

Active Member
Licensed User
Longtime User
simple list:
    '-----------------------------------------------*** BkData list holds all valid booking records *------------*
    Dim BoothDataRecords As Int
    Dim BoothData As List
    Dim bkCursor As ResultSet
    bkCursor = DB.ExecQuery("SELECT * FROM BoothName")
    BoothData.Initialize
    Do While bkCursor.NextRow
        Dim Row(3) As Object
        Row(0) = bkCursor.GetString("Booth")
        Row(1) = bkCursor.GetString("Secure")
        Row(2) = bkCursor.GetString("Bookable")       
        BoothData.Add(Row)
    Loop
    bkCursor.Close
    BoothDataRecords = BoothData.Size

    BoothA.Text= " ": BoothB.Text = " ":BoothC.Text= " ": BoothD.Text = " ":BoothE.Text= " ": BoothF.Text = " ":BoothG.Text= " "
'    Log("booth Records count "&BoothDataRecords)
    For i = 1 To BoothDataRecords -1
        Dim ListRow(3) As String = BoothData.Get(i -1)
        Log("ListRow "&ListRow(0))
    Next

I can't understand where the error is. I have reused this code and i continue to get an error when I get the Boothdata item
I have checked and there are 3 records in the list
 

LucaMs

Expert
Licensed User
Longtime User
i continue to get an error when I get the Boothdata item
What is the errore message?

Anyway, this:
B4X:
    For i = 1 To BoothDataRecords -1
        Dim ListRow(3) As String = BoothData.Get(i -1)
        Log("ListRow "&ListRow(0))
    Next
should be:
B4X:
    For i = 0 To BoothDataRecords -1
        Dim ListRow(3) As String = BoothData.Get(i)
        Log("ListRow "&ListRow(0))
    Next
Better:
B4X:
    For i = 0 To BoothData.Size -1
        Dim ListRow(3) As String = BoothData.Get(i)
        Log("ListRow "&ListRow(0))
    Next
 
Upvote 0

Pelky

Active Member
Licensed User
Longtime User
all it showed was that there was an error on that row. Nothing specific which was a bit annoying. The crazy thing is that I managed to make it work by declaring
listrow as an object and using another variable to receive the actual value i was looking for. I did try - Dim ListRow(3) As String = BoothData.Get(i) but got the same error.

Once again I would like to thank you both for your assistance it is truly appreciated.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Instead of declaring Dim Row(3) As Object
B4X:
    Do While bkCursor.NextRow
        Dim Row(3) As Object
        Row(0) = bkCursor.GetString("Booth")
        Row(1) = bkCursor.GetString("Secure")
        Row(2) = bkCursor.GetString("Bookable")       
        BoothData.Add(Row)
    Loop
try to declare it as String.
B4X:
    Do While bkCursor.NextRow
        Dim Row(3) As String
        Row(0) = bkCursor.GetString("Booth")
        Row(1) = bkCursor.GetString("Secure")
        Row(2) = bkCursor.GetString("Bookable")       
        BoothData.Add(Row)
    Loop
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…