Function
Top  Previous  Next

Function name (arglist)
statements
name = expression
statements
End Function 

Declares the name, arguments, and code that form the body of a Function procedure.

Parameters
 
name  
 
Name of the Function. See standard variable naming conventions.  
 
arglist  
 
List of variables representing arguments that are passed to the Function procedure when it is called. Multiple variables are separated by commas.  
 
statements  
 
Any group of statements to be executed within the body of the Function procedure.  

Remarks


You can declare variable type within varlist or you can specify only variable name.  
You can't define a Function procedure inside any other procedure.  
You call a Function procedure using the procedure name followed by the argument list.  
Function declaration must precede Function call.  
Code execution starts with the first line after the last procedure.  
To return a value from a function, assign the value to the function name. Any number of such assignments can appear anywhere within the procedure. If no value is assigned to name, the procedure returns integer variable with value 0.  
Functions can be recursive, that is, they can call themselves to perform a given task. However, recursion can lead to stack overflow.  

Example
 
Function sincos (angle as floating)  
          sincos = sin(angle) + cos(angle)  
End Function  
 
........  
 
print sincos(pi/2)  
 
........