Userdefined Functions
Function Definition
FUNCTION <name> : <returntype>
VAR_INPUT
<variable declarations>
END_VAR
VAR_OUTPUT
<variable declarations>
END_VAR
VAR_IN_OUT
<variable declarations>
END_VAR
VAR
<variable declarations>
END_VAR
VAR_EXTERNAL
<variable declarations>
END_VAR
<statements>
END_FUNCTION
Declares a function. Thereafter, it is callable by its name. The declaration of the return type is optional. If it is supplied, the function returns a value of the given type. The return value is defined within the function body by an assignment to the function name.
The function may have input, output and in-out parameters. The order of declaration is significant. It is used for nonformal calls. Declared variables are only used within the function body. External variables are imported from global scope. Variables and parameters are not persistent, i.e. they do not retain their value between two calls.
Nonformal Function Call
<functionname>(<expression>, …, <expression>)
Nonformal function call. The order of expressions must match the number and order of declared parameters.
Formal Function Call
<functionname>(
<inputParamName> := <expression>,
<outputParamName> => <variableName>,
<inputParamName> := <variableName>)
Formal function call. Parameters are identified by their name. If a declared parameter is not listed, it is implicitly set to its default value.
Do not Mix Formal with Nonformal Mixing formal with nonformal function calls leads to invalid |