<<

Contents

Search

>>

 

FUNCTION

 

 

Instruction

 

 

Syntax:

FUNCTION FN<Name>[$ | %] ([<Variable>[,<Variable>]...] )

                 … Instructions …

                 RETURN <Expression>

ENDFUNC

 

<Name>

= <NAME>

<Variable>

= <VARIABLE>

<Expression>

= <EXPRESSION>

 

Meaning:

Declares a function.

 

Functions can be declared at any position in the macro, but not within blocks IF ... THEN, WHILE ... DO, ON ERROR ... END, etc.).

 

The function name must begin with FN... .

 

The function type (string, numeric, integer) is defined by the written form: If the function name ends with '$', this defines a string function. '%' means integer, letter and number means numeric (double).

 

Any number of parameters can be specified. The type of the parameters is again defined by their written form. Functions do not necessarily have parameters.

 

The following instructions are not allowed in functions:

QUIT

MACRO

GOTO #

FIELD

DIM

SHARED

REPEAT

NEXTFIELD

ENDPROG

ENDREP

 

Every function declaration must end with ENDFUNC.

 

Functions always return a value and may thus not appear on the left side of an assignment.

 

With the instruction RETURN <Expression> the returned value is defined and the function is closed.

 

<Expression> must be of the same type as the function. Only numeric and integer can be exchanged.

 

The last instruction in the function declaration before ENDFUNC must be the instruction RETURN <Expression> .

 

Example:

FUNCTION FNMAX%(I%,J)

  IF I%<J

  THEN RETURN J

  ELSE RETURN I%

  ENDIF   <←> is not allowed. Last instruction must be RETURN.

ENDFUNC

 

Correct is:

FUNCTION FNMAX%(I%,J)

  IF I%<J

  THEN RETURN J

  ENDIF

  RETURN I%

ENDFUNC

 

Functions can be called at any position in any nesting depth. Any expressions are allowed with parameters. The expression type must be identical with the parameter type in the function declaration. All parameters are given to the function ‘by value’. As a consequence the value of the called variable is not changed when a value is assigned to a parameter within the function declaration.

 

Parameter:

Name

Name of Function

Variable

Function variable

Expression

Return value of the function

 

Sample:

FUNCTION FN_DATE_TIME$(TYPE%)

  IF TYPE% = 1

  THEN RETURN DATEG$+” “+TIME$

  ENDIF

  RETURN DATEG8$+” “+TIME$

ENDFUNC

…

D$ = FN_DATE_TIME$(0)

 

See also:

RETURN