The user-defined function (UDF) allows the programmer to create mvBASIC functions that may be used in any expression in the mvBASIC program.
Format
FUNCTION function-name ([var1,var2,...]) statements RETURNING exp . . . |
After the function has been defined, use the following format to call the function:
Format
@function-name ([exp1, exp2,...]) |
Parameter(s)
function-name |
Name selected by the programmer. |
var1,var2 |
Names of local variables used in the function. These variables are not available to the external program. |
statements |
One or more valid mvBASIC statements. |
exp |
Local variable used in the function. The value of this variable is passed to the main program when the function terminates. |
exp1, exp2,... |
One or more expressions. The value(s) of the expressions(s) is passed to the function’s local variables when the function is called. |
Description
User-defined functions always return a single value, and accept any number of input expressions. User-defined functions may not pass dimensioned arrays. All variables used within the function are local to the function, and are not available to the external program. This private use of the variables allows standardized global libraries to be created and referenced by any program via the $INCLUDE statement.) The programmers need not be concerned about the variable names used in the function-they cannot conflict with the variables in the program, even if the names are the same.
NOTE |
|
Example
* * DEFINE FUNCTION * FUNCTION LIMIT (V,LOWER,UPPER) IF V < LOWER THEN V = LOWER IF V > UPPER THEN V = UPPER RETURNING V ;* CAUSES FUNCTION TO EVALUATE TO ;* THE VALUE IN THE VARIABLE 'V' . . . * *MAINLINE USAGE OF FUNCTION * INPUT X X = @LIMIT(X,1,10); * INSURES: 1<= X <=10 |
See Also