10.6. Enumerator

We have used case structures before with boolean (True, False) cases. A case structure can also switch on integers and enumerators.

enumerator

An enumerator (enum, for short) is a special type of integer with a finite set of values where, in addition to each of value representing an integer numer, the values are given a textual name. The names of the possible values can give meaning in some sense to each value, which makes programs easier to read and write.

In LabVIEW, create an enumerator with an enum constant which is found under Programming | Numeric. Right click on the enum to add values to the enum. The Edit Items option pulls up a table editor that is an easy way to set the values and names of the enumerator.

../_images/enum_items.png

When the enumerator is replicated in multiple places, such as in a Finite State Machine, you should convert the enumerator to a Type Def. As a Type Def, when the enum is changed the changes are made to each instance of the enum.

10.7. Enumerator with a Case Structure

When creating an Action Engine, the enum is usually only defined once, so leaving it as simple variable is acceptable. However, when creating a Finite State Machine, several copies of the enum will likely be needed, so it is advised that the enum be made into a Type Def so that any changes to its values will be reflected in each usage instance.

  1. Connect the enum to the selection terminal of a case structure.
  2. Right click on the edge of the case structure’s pull down case selector and select Add Case for Every Value.
../_images/enum_case.png