[Gambas-user] How to return results and status from a function to the calling procedure??

Benoit Minisini gambas at ...1...
Mon Dec 8 15:42:26 CET 2008


On lundi 8 décembre 2008, gambas at ...1938... wrote:
> Hi List,
>
> stupid question.
> What I wanted to do is
> - call a function and check if all went OK (True/False)
> - If True get the result and go on.
> - If False do some error managemen
>
> In principle it is an easy task, but:
> - Using global vars is (citation): "Poor programming practise" ;-)  (no
> offense)
> - Using ByRef is slower then copy the content
>
> So, what's the best, cleanest or preferred way to do it in Gambas?
>
> Greetz
> Stevie
>

If "all was not ok" means that there was an error, then you should use 
Error.Raise() and error management.

If "all was not ok" is actually normal, then your function should return a 
boolean that will tell you the result.

If your function also return a value, then you can use one of the value to 
indicate a problem. For example, a function that returns a Date can return 
NULL for errors.

If you can't use one of the value to indicate an error, then you must do 
something else!

-- 
Benoit Minisini




More information about the User mailing list