If an argument is listed in a Cicode function declaration, the Argument Initialisation Statement is optional, and if used, is listed last in the Argument Statement after the required Argument Data Type and the Argument Name Statements. The Argument Initialization Statement needs to be preceded by an equals ( = ) assignment operator.
Note: In the following function syntax example:
Replace the <InitialDefaultValue> placeholder in the following function example with an appropriate value for your Argument variable.
FunctionName ( <ArgumentDataType> <ArgumentName> [ = <InitialDefaultValue> ] )
The default value for an argument needs to be of the same data type as declared for the argument in the Argument Data Type Statement.
You assign a default argument variable value in the same manner that you assign a Cicode variable value, by using the equals ( = ) assignment operator. For example:
PlotProduct ( INT iPackets = 200 , STRING sName = "Packets" )
If you assign a default value for an argument, you may omit a value for that argument when you call the function, (because the function will use the default value from the declaration.) To pass an empty argument to a function, omit any value for the argument in the call. For example, to call the PlotProduct function declared in the previous example, and accept the default string value of "Packets", a Cicode function call would look like:
PlotProduct ( 500 , )
Be aware that the second argument for the function was omitted from the calling code. In this instance, the default value for the second argument ( "Packets" ) would remain unchanged, and so would be used as the second argument value in this particular function call.
If you do call that function and pass in a value for that argument in the call, the default value is replaced by the argument value being passed in. However, the arguments are reinitialized every time the function is called, so each subsequent call to the function will restore the default values originally declared in the function.
If more than one argument is used in a function, each needs to also be separated by a comma. Equally, if a function containing more than one argument is called, each argument needs to be accounted for by the caller. In this case, if an argument value is to be omitted from the call, (to utilise the default value), comma placeholders need to be used appropriately in the call to represent the proper order of the arguments.
For more information on function calls, callers, and calling, see the section titled Calling Functions from Commands and Expressions.
Argument Statements can be separated over several lines to aid in their readability.