Re: [Gambas-user] MoveFirst MoveNext etc
> But during the long years now I have written programs :-) I found that we > most > often test for errors than success. So using TRUE for errors leads to less > lines of code. > > It is just a matter of habit. And changing habits is a good thing, it keeps > you young. :-) > I need something to keep me young :-) > You can write your loop this way: > > MyResult.MoveFirst() > WHILE MyResult.Available > ... > myResult.MoveNext() > WEND > Aaaahh - the available property. Yes that's what I was looking for. Obvious now. Thanks. -- This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] MoveFirst MoveNext etc
> 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 > Usually, languages and libraries use TRUE to mean success and FALSE to mean error. But during the long years now I have written programs :-) I found that we most often test for errors than success. So using TRUE for errors leads to less lines of code. It is just a matter of habit. And changing habits is a good thing, it keeps you young. :-) You can write your loop this way: MyResult.MoveFirst() WHILE MyResult.Available ... myResult.MoveNext() WEND Regards, -- Benoît -- This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] MoveFirst MoveNext etc
Ron_1st ha scritto: > 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++ > I think it could be pretty the same, but I like it this way; I think that the normal flow of code is when normal things happen, and when something exceptional happens, branches are taken. So, the code above could be written: if myResult.MoveFirst() then print "No records" return endif repeat print myresult!id until myresult.MoveNext() ...no "NOT" used. I agree that "if MoveNext()" could signify "if MoveNext succeeded", but if the functions worked this way, one should write: if not movefirst then ... endif print myresult.id while movenext printd ...!id wend or, even worse, if movefirst then print ..!id while ... wend else print "no records" endif It is a matter of taste. Regards, -- Doriano Blengino "Listen twice before you speak. This is why we have two ears, but only one mouth." -- This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] MoveFirst MoveNext etc
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 -- This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user