182
Description:
Description:Description:
Description:
Creating a user-defined function
DEF FN ..END DEF creates a user-defined function. The function definition block between
DEF FN and END DEF is a set of some statements and functions.
• 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.
• This statement block 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 ..END DEF functions can be recursive.
• In defining a string function, you can specify the maximum stringlength. 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 block, is a local variable valid only in that block. Therefore, if a
variable having the same name as dummyparameter is used outside DEF FN ..END
DEF statement block or used as a dummyparameter of any other function in the same
program, then it will be independently treated.
• In user-defined functions, you can call other user-defined functions. You can nest DEF
FN ..END DEF statements to a maximum of 10 levels.
• When using the DEF FN ..END DEF together with 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), you
can nest them to a maximum of 30 levels.
• If variables other than dummyparameter(s) are specified in the function definition block,
they will be treated as global variables whose current values are available.
• EXIT DEF exits the function block prematurely and returns control to the position
immediately after the statement that called the user-defined function.
• The block-format DEF FN statement should be followed by END DEF which ends the
function block and returns control to the position immediately after the statement that
called the user-defined function.
• Using Syntax 5 allows you to assign a return value for a user-defined function. The type
of functionname should match that of a return value. If no return value is assigned to
functionname, then the value 0 or a null string will be returned for a numeric function
or a string function, respectively.
Kommentare zu diesen Handbüchern