The enumerated type, or enum, is a container for a finite set of user-named values. Each item in the set has both a string and a numeric value.

On the diagram, an enum appears as a pull-down list of names represented as numeric data.

You can use the named values to drive the logic of your program. For example, you can wire an enum constant or control to the selector of a Case Structure to create cases that correspond to each item in the enum.

You can use the numeric values within the enum for numeric calculations or comparisons. If you wire an enum control to a numeric node or indicator, the enum value is coerced to a numeric value. All arithmetic functions except Increment and Decrement treat enum data the same as an unsigned integer.

Use Cases for Enum Data

You can use an enum to create a limited set of meaningful, human-readable values that your program can use to make decisions.

For example, you can add an enum control to the panel to provide a pull-down list that a user can cycle through to make selections. The enum control in the following image allows a user to select a day of the week.

Many uses for enums do not involve placing an enum control on the panel. For example, an enum constant on the diagram might represent the current state of a program, and the program might make different user interface options available based on the current value of the enum constant.

Coercion of Numeric Data to Enum Data

If you wire a numeric value to an enumerated type indicator, the numeric data is coerced to enum data according to the following rules:

Numeric Data Type Being Coerced to Enum Data

Result

Signed integer

Negative numbers change to equal the first enumerated value.

Out-of-range positive numbers change to equal the last enumerated value.

Unsigned integer

Out-of-range unsigned integers change to equal the last enumerated value.

Floating-point

The floating-point value is coerced to the closest numeric value in the enumerated type indicator.

Out-of-range floating-point values change to equal the last enumerated value.