When you have finished defining the function prototype, you specify the code for the function, just as you specify the script for an event in the Script view. For information about using the Script view, see Chapter 6, “Writing Scripts.”
User-defined functions can include PowerScript statements, embedded SQL statements, and calls to built-in, user-defined, and external functions.
You can type the statements in the Script view, or you can use the buttons in the PainterBar or items on the Edit>Paste Special menu to insert them into the function. For more information, see “Pasting information into scripts”.
If you specified a return type for your function in the Prototype window, you must return a value in the body of the function. To return a value in a function, use the RETURN statement:
RETURN expression
where expression is the value you want returned by the function. The datatype of the expression must be the datatype you specified for the return value for the function.
The following function returns the result of dividing arg1 by arg2 when arg2 does not equal zero. It returns –1 if arg2 equals zero:
IF arg2 <> 0 THEN RETURN arg1 / arg2 ELSE RETURN -1 END IF