Constants
Constant values are values that remain the same each time the program executes, such as pi, time intervals, fixed text string etc. For example, if a program needs a point to change state after a 2 minute pause, a constant can be used to define the 2 minute time period. Although the time period does decrease from 120 seconds to 0 seconds as the program executes, it is still represented by a constant as the time value is fixed as 120 seconds when the program is executed.
NOTE: Constant variables need to be separated from internal variables, direct variables and function blocks in the VAR lists. This means that if you have a program that uses constants, internal variables, direct variables, and function blocks, you will have at least 4 VAR lists—1 for constants, 1 for internal variables, 1 for direct variables, and 1 for function blocks.
To enter a constant value, you need to use this format:
VAR CONSTANT
<Constant Name> : <Value Type> = <Value including code characters>;
END_VAR
For example:
VAR CONSTANT
Timer:TIME := T#60s;
END_VAR
Where VAR CONSTANT instructs the program that the value is a constant, read only value. Timer is the name of the constant, and TIME is the value type. T# is the code for time values (see Time and Date Values) and 60s is 60 seconds. The s for seconds is lower case, as are time units. END_VAR is used to end the list of constants. If there are other VAR lists after the constant list, the END_VAR should not have a semi-colon at the end. However, if the constant list is the last list of variables for your program, you have to add a semi-colon to the end, like this: END_VAR;
NOTE: Unlike internal and direct variables, constants can only be of a certain data type. Each constant value has to be one of the Built-In Data Types.