-

Enumerations (enums)

A variable of a user-defined enum data type can have a value selected from a predefined list. Other variable values are not possible.
Example: the enumeration 'PossibleColors' includes the values Red, Green, and Blue, each of which is an INTeger data type, i.e., Red = 0, Green = 1, and Blue = 2.
In ST, the 'Color' variable which is of the enum data type, is set to INT = 1, i.e., Green if Start = TRUE.

Data type definition
Variable declaration
('Variables'/Data List)
Use in code

Note
If two or more enumerations contain an element with the same name, the ENUM name can optionally be added before the element name, followed by a hash character.
Example: two enumeration contain the element Green.
TYPE
   EnumColor : (Red := 0, Green := 10, Blue := 20) OF INT := Green;
   EnumBackgound : (Red := 255, Green := 128, Blue := 0) OF INT := Green;
END_TYPE
In the code, the statement eColor := EnumBackgound#Green; is unique.

Initializing enumerations

Enumerations can be initialized in two ways:

A variable of the data type 'PossibleColors' would be initialized with the value Green (INT#1).

Further Info
See also the topic "User-defined data types".