#73126 - 2003-02-15 06:34 PM
Function return values
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
Hi all!
Not sure if here or UDFs is the better place to post this, but - here goes.
After looking at the Kix manual, other people's UDFs, and the FAQ, I'm not really clear on the BEST way to code the value returned from a UDF.
Some examples I've considered: INGROUP: 1 if found, 0 if not EXIST: 1 if found, 0 if not OPEN: 0 if success, other if error
Basically, what I've seen is that if a function "looks for something" (exist/not exist) it returns "1" on success, zero otherwise. However, if a function performs some other action, it appears to reverse the return values - "0" on success, non-zero for failure.
Is this a fair assumption?
How might you return an error code when the function normally returns an array? Is "EXIT 1" when an error occurs enough? Or should I end every function with an "EXIT 0" ? See below:
code:
Function test() Open(some_file) If @ERROR Exit @ERROR EndIf : do stuff to the file & Close() : $test = $answer1,$answer2 ; return an array Exit 0 ; <= is this necessary, or recommended? EndFunction
Finally, when a function can return Yes, No, or Fail, is "1", "0", and "-1" a reasonable representation of the Yes, No, and Fail values?
Thanks for the comments & feedback.. I kind of know what's right in my head, but - if I'm going to write a UDF that might be used by others, I'd like to make sure I follow the same path as everyone else (within reason ).
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 1607 anonymous users online.
|
|
|