This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Obtaining Enum Elements in String Format

Updated Jan 8, 2019

Reported In

Software

  • LabVIEW

Issue Details

I have an enumerated data type and would like to obtain its elements in string format. Can I obtain the string data based on a user’s selection? Is there a LabVIEW function that can accomplish this?

Solution

There are several methods to obtain both string indications of all items of an enum, as well as determining only the currently selected item.


Method 1: Property Node with an Enum Control or Indicator
In case an enum control or indicator exists, create a Property Node for the enum and select the RingText.Text property. This property returns the currently selected item as a string.

Method 2: Property Node with an Enum Control or Indicator
This method is the same as method 1, except that it uses a Reference to define which Control/Indicator to use. You can create a Reference by right-clicking a Control's/Indicator's terminal on the Block Diagram and selecting Create » Reference.

Method 3: Property Node with an Enum Control or Indicator
In case an enum control or indicator exists, create a Property Node for the enum (like in method 1 or 2) and select the Strings[] property. This property returns an array of strings for all items of the specified enum. In case you want to pick only the currently selected one, use the Index Array function with the enum wired to the index terminal to access the desired string.


Please be advised that Property Nodes do not work with constants on the Block diagram. The previously mentioned methods do therefore not work with constants. The following two methods whatsoever work with enum constants as well.

Method 4: Format Into String with an Enum Constant, Control, or Indictator
Wire the enum to the Format Into String function input, with a format string value of %s wired to the format string input. This function will return the string value associated with the currently selected enum value.

Method 5: LAVA's OpenG Get Strings from Enum.vi function with an Enum Constant, Control, or Indictator
This method uses a VI from OpenG LabVIEW Data Library named Get Strings from Enum__ogtk.vi. Wiring an enum converted to variant, it will return all strings as well as the currently selected one. LAVA's OpenG LabVIEW Data Library is available through VI Package Manager (VIPM).

WAS THIS ARTICLE HELPFUL?

Not Helpful