User-defined functions make it possible to create structured scripts. User- defined functions must be declared at the beginning of a script. The FUNCTION keyword identifies the block of statements as a user-defined function.
The function declarations must follow a specific format:
return-type FUNCTION function-name (optional parameters) { optional local variables; statements...}
| Part | Description |
|---|---|
| Return-type | The data-type of the return value of the function. |
| FUNCTION | The keyword that identifies this as a user-defined function. |
| Function-name | A unique name that identifies this function. Must follow the naming convention of Identifiers. |
| Optional parameters | The named parameters (if any) that will be passed to this function. Enclosed in parentheses. |
| Optional local variables | The declaration of any local variables that this function will use. |
| statements | The Statement(s) that will be performed when the function is called. |
The rules described in the "Constants and variables" topic apply to the parameters and local variables used in a function. Any optional parameter names are assumed to be local to a function. Other local variables that are unique to a function can be declared. The control flow of the statements in a function follow the same rules that apply to normal program statement blocks. A RETURN statement returns control to the point in the program where a function was called. A return value might be passed back as part of the return statement. Example:
int FUNCTION signonPanel(string arg1)
{
if ((findString(arg1) > 0) AND
(findString("Sign On Panel") > 0) AND
(findString("Userid") > 0) AND
(findString("Password") > 0) )
return 0;
else
return 1;
}