function ... end function 

Create a user-defined function. A function is a sequence of instructions that is often used in several parts of your program.

Syntax:
function name ( parmlist {...} )
    shared variable {, ..}
    dim variable {, ...}
    commands
    {exit function}
    {return function}
    { functionName = expression }
end function

name is the user-defined function name, it's an alphanumeric string who must starts with a non numeric character. For example: 1printString is incorrect while printString1 is correct.
args represent the variables used to pass argument to the function.
{,...} indicates the the function can take a variable number of arguments.

Variables used inside the function are local variables, that means they will not influence other variables that happens to use the same variable name in your main program or in any other function. This is valid for arrays too. See common statements for more details.
You can pass to the function a list of parameters containing the informations to be processed from the function itself. Functions that do not require input parameters can be called from your main program without using brackets.
Functions can optionally return values,specified by the return statement. Returning values can be ignored by the calling instruction, in this case functions behave like subroutines.

Example:
function myFunction(a,b)
    return a*b
end function
print myFunction(10,4)
print myFunction(3,5)
print myFunction(7,8)

You can mix required with optional args. The total number of arguments can be found by calling function argument() , and the function argument(n) returns a particular argument passed to the caller.


Example:
' sum the args passed
function sumNumbers( a )
    total = 0
    for i = 1 to argument()    
        total = total + argument( i )
    end for
    return sum
end function

See also shared , dim , exit function and return commands.