Specifications

195
Description:
Creating a user-defined function
DEF FN creates a user-defined function.
Definition of a user-defined function should appear preceding a calling statement
of the user-defined function in a source program.
You cannot make double definition to a same function name.
The
DEF FN statement should not be defined in the block-structured statements
(
DEF FN...END DEF, FOR...NEXT, FUNCTION...END FUNCTION, IF...THEN
...ELSE...END
IF, SELECT...CASE...END SELECT, SUB...END SUB and
WHILE...WEND), in the error-handling routine, event-handling routine, or in the
subroutines.
DEF FN functions cannot be recursive.
The type of
functionname should match that of the function definition
expression.
In defining a string function, you can specify the maximum
stringlength for a
return value. If its specification is omitted, the default value of 40 characters takes
effect.
dummyparameter, which corresponds to the variable having the same name in
the function definition
expression, is a local variable valid only in that
expression . Therefore, if a variable having the same name as dummypa-
rameter
is used outside DEF FN statement or used as a dummyparameter
of any other function in the same program, then it will be independently treated.
expression describes some operations for the user-defined function. It
should be within one program line including definition described left to the equal
sign (=).
expression can call other user-defined functions. You can nest DEF FN state-
ments to a maximum of 10 levels.
If variables other than
dummyparameter(s) are specified in expression,
they will be treated as global variables whose current values are available.
stringlength should be enclosed with a pair of square brackets [ ].
Calling a user-defined function
FNfunctionname calls a user-defined function.
The number of realparameters should be equal to that of dummyparame-
ter
s, and the types of the corresponding variables used in those parameters
should be identical.
If you specify a global variable in
realparameter when calling a user-defined
function, the user-defined function cannot update the value of the global variable.
This is because all
realparameters are passed not by address but by value.
(So called "Call-by-value")