Reviewed May 2009
The default return value is 0 for numeric functions and "" (null) for string functions. To set another return value, assign it to the variable matching the function name (e.g. FN'name = -1). Note that this is similar in concept to the RETURN(<expression>) statement in an SBX, except that it doesn't end the function.
The return variable otherwise functions as a standard variable and can be used in expressions and be assigned a value multiple times (only the last one will matter at the time the function returns). As an example of one possibility, in the Fn'Dec2Hex$ sample function above, the return variable Fn'Dec'Hex$ receives its value by being passed as a parameter to a subroutine:
xcall MIAMEX, MX_OCVT, decval, width, OT_MEM or flags, Fn'Dec2Hex$
A special case occurs when the function returns a defined structure. In this case, in order to obey the naming rules, the function name must end with a $. But the $ is dropped when referencing members of the structure. Consider this example of a function which returns an item structure when passed an item ID.
defstruct ST_ITEM
map2 id,s,10
map2 descr,s,30
map2 price,f
endstruct
map1 item,ST_ITEM
item = Fn'Item$("A12345")
end
Function Fn'Item$(itemid as s10) as ST_ITEM
Fn'Item.id = itemid
Fn'Item.descr = "some description"
Fn'Item.price = 7.99
End Function
Note that the name of the function has a $ on the end (Fn'Item$), but when referring to the individual fields within the structure, the $ is dropped (Fn'Item.id = itemid).
Also note that the return value of the function is a copy of the entire ST_ITEM structure as it exists at the end of the function, even though there is no explicit reference to the structure as a whole. Any members of the structure which are not assigned would simply default to zeros or nulls, just as they would for a traditional unformatted MAP1/MAP2 structure.