Skip to main content

Variable: VAR_EXTERNAL

External variables are global variables that are "imported" into a POU.

You declare these variables between the keywords VAR_EXTERNAL and END_VAR. If the global variable does not exist, then an error message is printed.

Important

CODESYS does not require you to declare a global variable as external in order to use it in a POU. The keyword exists only for maintaining compliance with IEC 61131-3.

Syntax

<POU keyword> <POU name>
VAR_EXTERNAL
    <variable name> : <data type>;
END_VAR

Initialization is not permitted.

Example 88. Example
FUNCTION_BLOCK FB_DoSomething
VAR_EXTERNAL
        iVarExt1 : INT; (* 1st external variable *)
END_VAR