Android Question jump a loop without traeting it

DALB

Active Member
Licensed User
Hello everyone,

in this code

B4X:
    curs=Starter.SQL1.ExecQuery("SELECT chif FROM lotoGroupe")
    Dim lst As List
    lst.Initialize
'---------------------------------- this block is ignored
    For i=0 To curs.RowCount-1
        curs.Position=i
        lst.Add(curs.GetString("chif"))
    Next
'-----------------------------------
    lst.Sort(True)
    For i=0 To lst.Size-1
        Log(lst.Get(i))
    Next

the pointer doesn't make the first loop. It jumps directly to 'lst.sort(true)'.
I've closed the app and relaunched it, but the behaviour is the same.
I've relaunched my device too, and the result is the same.
The table chif is not empty, the SQLite statement is declared correctly in module Starter.
Did I forget to add something anywhere ?
 

DALB

Active Member
Licensed User
1734, the right number
 
Upvote 0

DALB

Active Member
Licensed User
hmmmm ! the result is the same, no loop exectuted !


B4X:
'curs=Starter.SQL1.ExecQuery("SELECT chif FROM lotoGroupe")
    Dim Res As ResultSet=Starter.SQL1.ExecQuery("SELECT chif FROM lotoGroupe")
    Dim lst As List
    lst.Initialize
'    For i=0 To curs.RowCount-1
'        curs.Position=i
'        lst.Add(curs.GetString("chif"))
'    Next
    Res.Position=0'---doesn't exists with resultset ?
    Do While Res.NextRow
        lst.Add(Res.GetString("chif"))
    Loop
  
    lst.Sort(True)
    For i=0 To lst.Size-1
        Log(lst.Get(i))
    Next
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Hello everyone,

in this code

B4X:
    curs=Starter.SQL1.ExecQuery("SELECT chif FROM lotoGroupe")
    Dim lst As List
    lst.Initialize
'---------------------------------- this block is ignored
    For i=0 To curs.RowCount-1
        curs.Position=i
        lst.Add(curs.GetString("chif"))
    Next
'-----------------------------------
    lst.Sort(True)
    For i=0 To lst.Size-1
        Log(lst.Get(i))
    Next

the pointer doesn't make the first loop. It jumps directly to 'lst.sort(true)'.
I've closed the app and relaunched it, but the behaviour is the same.
I've relaunched my device too, and the result is the same.
The table chif is not empty, the SQLite statement is declared correctly in module Starter.
Did I forget to add something anywhere ?

Code looks OK to me. Maybe you could show some more code.
How is curs declared?
How is i declared?
Try:
lst.Add(curs.GetString2(0))

RBS
 
Upvote 0

DALB

Active Member
Licensed User
The complete code looks like this:

B4X:
Sub chargementDepuislaTablelotoGroupe
   
    'si table boc remplie, la charger
    Dim ligTot As Int=Starter.sql1.ExecQuerySingleResult("SELECT COUNT(*) FROM lotoGroupe")
    Log("ligtot " & ligTot)
    If ligTot=0 Then
        '                            no valid datas to treat : STOP
        Msgbox("Pas de données à traiter sur les chiffres des tirages : ARRET ! ","PAS DE DONNEES")
        Return
    End If
   
    'sinon on traite la table
    curs=Starter.SQL1.ExecQuery("SELECT chif FROM lotoGroupe")
    'Dim Res As ResultSet=Starter.SQL1.ExecQuery("SELECT chif FROM lotoGroupe")
    Dim lst As List
    lst.Initialize
    For j=0 To curs.RowCount-1
        curs.Position=j
        lst.Add(curs.GetString("chif"))
    Next
'    Res.Position=0
'    Do While Res.NextRow
'        lst.Add(Res.GetString("chif"))
'    Loop
   
    lst.Sort(True)
    For i=0 To lst.Size-1
        Log(lst.Get(i))
    Next
    curs.close
   
End Sub

and 'curs' is declared like : curs as cursor.
I use curs in different modules.

+restarted the computer
I've deleted the Activity and rebuilt it. The result is the same..
 
Upvote 0

DALB

Active Member
Licensed User
Found !!!
An error of a beginner !
I've mixed table name with column name.

it's solved !
Soon, I'll go to drink a glass of apple juice for better relax !
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Found !!!
An error of a beginner !
I've mixed table name with column name.

it's solved !
Soon, I'll go to drink a glass of apple juice for better relax !

Had a feeling it would be something simple like that.
Do these things myself.

RBS
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
(O.T., sorry)...

New @alwaysbusy's look; nice :)

upload_2019-12-9_19-14-44.png
 
Upvote 0

DALB

Active Member
Licensed User
Thanks to you.
But I can add something which is troubling.

If I have many loops like
B4X:
For i=0 to lst.Size-1
...
next

...this behaviour appears.

If I change my indices to others, it works.

Example

I have three loops like the one below in the same sub, The problem appears.

If I write

B4X:
for i=0 to...

for ii=0 to ...

for iii=0 to ...

I have no problem. But this appaers in my all modules, and all apps I develope
A mystery for me.

Maybe Windows cant refresh the memory correctly ?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I don't understand your last question (as Erel would say: "You should start a new thread for this new question").
Please write it so that even I understand it :D

curs=Starter.SQL1.ExecQuery("SELECT chif FROM lotoGroupe")
You could write directly in your query the "sort command", of course:
curs=Starter.SQL1.ExecQuery("SELECT chif FROM lotoGroupe ORDER BY chif"

Found !!!
An error of a beginner !
I've mixed table name with column name.
What is the output of:

B4X:
Log(curs.RowCount)
evidently you hadn't written that "Log"
 
Upvote 0

DALB

Active Member
Licensed User
Thanks LucasMs, I'll try this !
 
Upvote 0
Top