[Gambas-user] TRY bug example

nando nando_f at ...951...
Sat Dec 10 12:54:20 CET 2005


Thank you Benoit.
Although I find it a bit inconsistent,
it makes sense for the way it has been implemented.
You have answered many questions.
And I sincerely do thank you.
It clears some of the fog.

Perhaps do you think that CStr(False) should return F instead of NULL?
Since PRINT "HELLO: " & ERROR & " is the error" shows T for TRUE
then would F be a logical for False if using CSTR in the &.
You are converting to a string.

-Fernando


---------- Original Message -----------
From: Benoit Minisini <gambas at ...1...>
To: gambas-user at lists.sourceforge.net
Sent: Sat, 10 Dec 2005 11:10:58 +0100
Subject: Re: [Gambas-user] TRY bug example

> On Saturday 10 December 2005 08:21, nando wrote:
> > Benoit,
> >
> > This is causing me a bit of trouble..and narrowed it down.
> >
> 
> First, read carefully the documentation about Val(), Str$(), and CStr()
> . The last function *does not* use localisation settings.
> 
> >
> > Example 1:
> > -------------------------------------------------------------
> > PUBLIC SUB Form_Open()
> >
> > PRINT ERROR
> > TRY RMDIR "/home/stupid"    'make sure stupid does not exist
> > PRINT ERROR
> > PRINT "HELLO: " & ERROR & " is the error"
> > TRY RMDIR "/home/stupid"
> > TRY PRINT "HELLO: " & ERROR & " is the error"
> >
> > END
> >
> >
> >
> > Output I get on Console:
> > -------------------------------------------------------------
> > False
> > True
> > HELLO: T is the error   <---  Error shown as T and not True
> > HELLO:  is the error    <---  The T or F value for ERROR is missing
> >
> >
> >
> > Example 2:
> > -------------------------------------------------------------
> > Also, include TRY on the first and third lines and the output
> > gets more wierd...
> >
> > PUBLIC SUB Form_Open()
> >
> > TRY PRINT ERROR
> > TRY RMDIR "/home/stupid"
> > TRY PRINT ERROR               'Error should be true from previous line
> > PRINT "HELLO: " & ERROR & " is the error"
> > TRY RMDIR "/home/stupid"
> > TRY PRINT "HELLO: " & ERROR & " is the error"
> >
> > END
> >
> > Output is...
> > ------------------------------------------------------------
> >
> > False
> > False            <---- I expected True ...see question 3 below.
> > HELLO:  is the error  <--- What is the error?
> > HELLO:  is the error
> >
> >
> > --------------------------------------------------------------------
> > Questions ??
> > (1) Why does ERROR print out as False or True but sometimes is T or F ??
> 
> Because PRINT use Str$() to convert boolean values to strings, whereas 
> the '&' operator use CStr().
> 
> > (2) Why is ERROR blank sometimes ??
> 
> Because CStr(False) returns NULL.
> 
> > (3) Is printing ERROR within a TRY statement showing the previous ERROR ?
> >     I'm thinking TRY PRINT can never make ERROR TRUE so that PRINT
> > shouldn't affect ERROR.
> 
> TRY clears the internal error flag before executing its statement.
> 
> > (4) Is it mandatory to ERROR.CLEAR after every TRY ??
> 
> Usallay, you use TRY and read the ERROR flag just after. So it is not 
> mandatory, and moreover it is useless!
> 
> > (5) or does TRY clear ERROR after the next statement ??
> 
> See (3).
> 
> >
> > I'm thinking ERROR should always be T/F or always True/False but not mixed.
> 
> Mixed ??? ERROR returns a boolean value, that's all.
> 
> > I get better consistent results with STR$(ERROR) but I didn't think I
> > needed to force conversion.
> 
> See (1), and read the documentation about Str$() and CStr().
> 
> >
> > Thanks in advance.
> > -Fernando
> >
> 
> Regards,
> 
> -- 
> Benoit Minisini
> 
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log 
> files for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------





More information about the User mailing list