Function Statement
Declares the name, arguments, and code that form the body of a Function procedure.
Function name [(arglist)] as {Integer|String}
[statements]
[ExitFunction value]
[statements]
EndFunction value
Arguments
Name Name of the Function; follows standard variable naming conventions.
arglist List of variables (comma seperated) representing arguments that are passed to the Function procedure when it is called.
statements Any group of statements to be executed within the body of the Function procedure.
value Return value of the Function.
Remarks
The value of local variables in a Function is not preserved between calls to the procedure. You cannot define a Function procedure inside any other function.
The ExitFunction statement causes an immediate exit from a Function procedure. Program execution continues with the statement that follows the statement that called the Function procedure. Any number of Exit Function statements can appear anywhere in a Function procedure.
A Function procedure is a separate procedure that can take arguments, perform a series of statements, and change the values of its arguments.
You call a Function procedure using the function name, followed by the argument list in parentheses, in an expression.
Caution
Function calls can be recursive, that is, they can call themselves to perform a given task. However, be aware that recursion can lead to stack overflow.
Example
Function ReadSPI(CLKPIN as string, DATAPIN as string) as string
DIM RESULT as string
RESULT =""
DIM loop as integer
COUNT = 8
FOR LOOP = 1 TO COUNT
CLKPIN = "1"
LOAD
CLKPIN = "0"
LOAD // will read the pins as well
RESULT = RESULT + DATAPIN
NEXT
EndFunction Result