Constant variables - CONSTANT
Constant variables are declared in the global variable lists or in the declaration part of programming objects. In implementations, constant variables can be accessed for reading via the instance path, but not for writing.
Syntax
<scope> CONSTANT
<identifier> : <data type> := <initial value> ;
END_VAR
<scope> : VAR | VAR_INPUT | VAR_STAT | VAR_GLOBAL
<data type>: <elementary data type> | <user defined data type> | <function block>
<initial value> : <literal value> | <identifier> | <expression>
Always assign an initialization value when declaring a constant variable. After that, the constant can no longer be written.
Sample:
Declaration:
VAR CONSTANT
cTaxFactor : REAL := 1.19;
END_VAR
Call:
rPrice := rValue * cTaxFactor;
You can only access constant variables in a read-only implementation. Constant variables are located to the right of the allocation operator.
See also: