Obtaining Enum Elements in String Format 您所在的位置:网站首页 标志枚举输出字符串怎么计算 Obtaining Enum Elements in String Format

Obtaining Enum Elements in String Format

2024-07-03 00:45| 来源: 网络整理| 查看: 265

There are several methods to obtain both string indications of all items of an enum, as well as determining only the currently selected item. Use the snippet and method descriptions below to learn a few ways to approach this question.

聽Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.聽

Method 1: Property Node with an Enum Control or IndicatorIn 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 IndicatorThis 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 IndicatorIn 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 IndictatorWire 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.In the example above, a constant is used, but this could be replaced with a local variable to the control as this method works with cotrols (or indicators)

Method 5: LAVA's OpenG聽Get Strings from Enum.vi function with an Enum Constant, Control, or IndictatorThis 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).(If you do not have OpenG Library, you can use a Diagram Disable Structure聽to disable the last method but still be able to explore the others.)



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有