Function Syntax

A function declaration begins with the keyword Function, followed by the function name. A parameter list contains the name and data type of variables to be passed into the function. Optional parameters are identified by the Optional keyword an must have a default value. . A function returns a value; the keyword As precedes the data type of the returned value. The Return keyword is used to specify the value to be returned by the function. The function is terminated with the keywords End Function.

Note: A parameter list contains one or more parameters separated by commas.

Alternatively, the return value could be specified by setting the function to a value, as shown below:

Function Call Syntax

The following examples show the calling syntax for MyFunction above.

Example 1

Testing in the immediate pane:

Intent >MyFunction(10, 15)
--> 12.5
Intent >MyFunction(10, 15, c := 18)
--> 14.3333333333333

Example 2

Set a rule value to the result of MyFunction averaging two numbers:

Rule avg2 As Number = MyFunction(10, 15)

Example 3

Set a rule value to the result of MyFunction averaging three numbers using the optional parameter c:

Rule avg3 As Number = MyFunction(10, 15, c := 20)