[Gambas-user] MoveFirst MoveNext etc
Ron_1st
ronstk at ...239...
Thu Apr 9 18:27:54 CEST 2009
On Thursday 09 April 2009, Jeff wrote:
> What is the thinking behind a Result.MoveFirst() and MoveNext()
> returning a false if a record is there?
>
> So, to read round a result set I end up using a Boolean with a double
> negative:
>
> noMoreRows = myResult.MoveFirst()
> WHILE NOT noMoreRows
> PRINT myResult!id
> noMoreRows = myResult.MoveNext()
> WEND
>
> I would have expected the MoveFirst() and MoveNext() return true if a
> record found, so I'm wondering why it's that way round.
> Or, is there a better loop structure to use so that it reads better?
>
>
The only logic I see is the way it is done in C/C++
If result returned is 0 means OK else the value other then
0 means the error code for the occured error.
-1 means i.e. syntax
-2 means i.e. invalid something
In C/C++ the IF THEN use a value instead the Basic boolean True/False
Symbolic 0 equals to False, other value to True
Just in good old practice for Basic a question in IF ... THEN
was/is always true.
So your way the next code is right
IF myResults.MoveNext() then
' ok the movenext was OK
ELSE
' oops a error
ENDIF
For gambas in relation to the MoveXXX() this is reversed by Benoit.
It means with false ( equals to 0) there was no error
IF myResults.MoveNext() then
' returned not 0 (zero)
' oops a error
ELSE
' ok the movenext was OK
' return was 0 (zero)
ENDIF
So you can use:
Const NOERROR as boolean=false
IF myResults.MoveNext() = NOERROR THEN
' ok the movenext was OK
' return was 0 (zero)
ENDIF
Personal I do not like the Gambas way, IMHO the myReult.MoveNext()
should return TRUE if succes and FALSE when error occured.
I use now the method with NOERRO to get a clean Basic readable code.
NOERROR makes more sence then False here.
Best regards,
Ron_1st
More information about the User
mailing list