FUNCTION                                                           Statement

FUNCTION procedurename[(arglist)]

                [statements]

                [procedurename = expression]

                [EXIT FUNCTION]

                [statements]

                [procedurename = expression]

END FUNCTION

Description

FUNCTION declares a procedure, procedurename, that executes statements, with arglist as parameters, with an optional return value. The required parameter, procedurename, is used to call the procedure, and must follow standard variable naming conventions. The optional parameter list, arglist, is a comma separated list of variables used to represent variables that are passed to the procedure when it is called. The optional component, statements, will be executed as the body of the procedure. Any number of optional EXIT FUNCTION statements can be used to exit the procedure during execution. The value returned by the procedure defaults to EMPTY. To return a value other than the default, assign the value to the function name. The current value of procedurename will be returned when the procedure exits by executing all statements or encountering an EXIT FUNCTION statement.

Each member of arglist is an argument passed to the procedure, as declared below:

[BYVAL | BYREF] varname[()]

The optional keyword, BYVAL, specifies that a copy of the variable be passed into the procedure, making its value outside the procedure unmodifiable by the procedure. The optional keyword, BYREF, specifies that the address of the variable be passed into the procedure, making its value outside the procedure modifiable by the procedure. varname can be used within the procedure to reference a value passed in, it follows standard variable naming procedure.

Note: If the return value is not stored in a variable or used in an expression, the procedure is called as a SUB procedure, and multiple arguments cannot be enclosed in parenthesis.

Example

REM FUNCTION Example

'FUNCTION: a procedure that returns a value

DIM Selection, SalePrice

Selection = Menu("Wednesday")

PRINT "Wednesday's menu feature:",Selection

SalePrice = Min(31,29)

PRINT "Sale Price:", SalePrice

FUNCTION Menu(day)

  IF day = "Wednesday" THEN

    Menu = "Salisbury Steak"

  END IF

END FUNCTION

FUNCTION Min(x,y)

  IF x > y THEN

    MIN = y

    EXIT FUNCTION

  ELSE

    MIN = x

  END IF

END FUNCTION

Output

Wednesday's menu feature: Salisbury Steak

Sale Price:   29

Related Items

CALL, SUB