[Gambas-user] Why Vassilis' code raised a "Result not available"

Benoît Minisini gambas at ...1...
Mon Oct 19 10:41:21 CEST 2009


Hi,

I renamed the subject, because the thread was too deep for my screen. :-)

The following code:

PUBLIC SUB Form_Open()
  DIM i AS Integer
  DIM rsThesi AS Result
    MODMain.Connect()
    rsThesi = MODMain.$Con.exec("select * from egrafes where elenchosAnax = 
0")
    rsThesi.MoveFirst
    WHILE rsThesi.Index < rsThesi.Count
      change_bgcolor("Label" & rsThesi!thesi)
      rsThesi.MoveNext
    WEND 
    MODMain.$Con.Commit()
END

...does not work and raise "Result not available" because when you reach the 
end of the Result and call MoveNext(), the Index property switches to -1 (-1 
meaning "not available"). And as -1 is always lower then rsThesi.Count, the 
loop continues.

Writing `WHILE rsThesi.Index < rsThesi.Count - 1' does not raise the error, 
but you lose the last record of the Result! So it is wrong too.

So, as Werner wrote, the right way of writing that code is:

FOR EACH rsThesi
  ME["Label" & rsThesi!thesi].Background = Color.Red
NEXT

And the commit is useless, as you didn't write anything to the database.

And, finally, to Kad Mann: Vassili used a bunch of Labels and not a GridView 
because he used them for drawing a camping schema.

Regards,

-- 
Benoît Minisini




More information about the User mailing list