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. The Optional keyword identifies the Optional parameters and 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:
Optional arguments to functions and methods: Use of the calling syntax ":=" is enforced and raises an error if the ":=" is missing. In releases preceding 2016, certain illegal usages were ignored.
If an error displays due to the ":=" missing, it means that your existing code was not functioning as expected. You were attempting to pass in a value for an optional argument, and it was ignored. Instead it used the default value for the argument.
The following examples show the calling syntax for MyFunction.
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)