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.
Alternatively, the return value could be specified by setting the function to a value, as shown below:
The following examples show the calling syntax for MyFunction above.
Testing in the immediate pane:
Intent >MyFunction(10, 15) --> 12.5 Intent >MyFunction(10, 15, c := 18) --> 14.3333333333333
Set a rule value to the result of MyFunction averaging two numbers:
Rule avg2 As Number = MyFunction(10, 15)
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)