Calling a Method Permalink

Syntax for calls:

<return value variable> := <POU name> . <method name> ( <argument passing> );

<return value variable>

Variable for the return value

The type has to match the return type of the method.

Note: In the case of methods which do not have an explicit return type, the first declared output is used as the return value. A method does not return a value only if neither the return type nor the output are declared. However, a compiler error is not generated in either case.

<POU name>

Identifier of the function block instance under which the method is arranged

<method name>

Identifiers of methods

<argument passing>

Comma-delimited list with the actual arguments

One argument is passed to each parameter (variable) of the method:

<parameter name> := <actual argument>

  • Each declared input/output or input is assigned the actual argument. The argument can be a value (literal), an expression, or a variable with matching type.

  • The actual argument (variable of the same type) is assigned to each declared output is assigned. The argument has to be a variable with the matching type.

  • Passing an argument for an input or an input/output can be omitted.

    Therefore, the number of arguments in the list may be less than the number of parameters (scope of input or input/output). In particular, if it is an optional parameter for which a default or initial value was specified in the declaration, then passing an argument can be omitted.

    Hint: If you get help from the Input Assistant when calling the method, then it will notify you about existing initial values.

  • It is optional to pass an argument with the specification of the parameter with name and assignment operator.

    Specifying only the argument is sufficient. The order of the variables in the declaration then determines which argument is passed to which parameter.

Example

Declaration

METHOD PUBLIC DoIt : BOOL
VAR_INPUT
        iInput_1 : DWORD;
        iInput_2 : DWORD;
        sInput_3 : STRING(12);
END_VAR

Call with passing an argument to a parameter

bFinishedMethod := fbInstance.DoIt(sInput_3 := 'Hello World ', iInput_2 := 16#FFFF, iInput_1 := 16);

When the method is called, the return value of the method is assigned to a locally declared variable.

Example

If you omit the names of the input variables, then the assignment of the arguments results from the declaration order.

Declaration

METHOD PUBLIC DoIt : BOOL
VAR_INPUT
        iInput_1 : DWORD;
        iInput_2 : DWORD;
        sInput_3 : STRING(12);
END_VAR
IF iInput_1 = iInput_2 THEN
	DoIt := TRUE; // explicit return value
END_IF

Call with passing an argument according to the order in the declaration

bFinishedMethod := fbInstance.DoIt( 16, 16#0010,'Hello World ');