[Gambas-user] Bad loop.

Benoit Minisini gambas at ...1...
Thu Jun 3 18:18:04 CEST 2004


On Wednesday 02 June 2004 19:51, Jack wrote:
> Bonjour,
> I have a loop which work well but i don't can log out .

What do you mean ?

> Please, see my code below. What is wrong ? (Ecrit1 is a columnView with
> many lines that i want read with my program to update a database.)
> Is it "LOOP UNTIL Ecrit1.MoveNext() = TRUE" which is bad ?
>
> ----- My code ---------
>
>  IF rResult.Available THEN
>     Ecrit1.MoveFirst()
>   DO
>   Numcpt = Ecrit1.Item[0]
>   Numdoc.Text = Ecrit1.Item[2]
>   rResult = DB.Exec("UPDATE  "&Tab&"  SET  Jour = '"& Journal.Text
> &"',Numero = '" & Numecrit.Text & "' , Compte = '" & Numcpt & "'")

NEVER use Exec() this way. Type:

  rResult = DB.Exec("UPDATE " & Tab & " SET Jour = &1, Numero = &2, Compte = 
&3", Journal.Text, Numecrit.Text, Numcpt)

Otherwise, your SQL request might have syntax errors if your data include 
quotes.

DB.Exec() returns nothing with an UPDATE request. So 'rResult =' is not 
necessary.

>   Ecrit1.MoveNext()
>   Ecrit1.MoveCurrent()
> LOOP UNTIL Ecrit1.MoveNext() = TRUE

Two MoveNext() implies that you can forget a column. Just keep the last line:

  LOOP UNTIL Ecrit1.MoveNext()

It is not necessary to use '=' to compare a boolean. Just use it directly in a 
test - it is a boolean !

> ENDIF
> ----- End of Code --------
>
> Thank you very much for your answer.
>
> °~ Jack ~°
>
>

Are things better now ?

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the User mailing list