Example Code

Find Enum Item from String Input

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This VI demonstrates how to convert the string into the appropriate enum value.

 

Description

You would need to turn this into a subVI, then take the subVI output and use that as the case structure input. There is  a neater way: you can bundle it into a cluster, and then unbundle from your type defined enum placed inside a cluster shell.

 

Requirements

  • LabVIEW 2012(or compatible)

 

Steps to Implement or Execute Code

  1. Set the Combo Box.
  2. Run the VI.

 

Additional Information or References

VI Snippet

 

BD.png

**This document has been updated to meet the current required format for the NI Code Exchange.**

 

Joel G
Applications Engineer
National Instruments UK & Ireland

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Rob_Ward
NI Employee (retired)
on

Hey Joel.

This will work too using the "Scan From String" function, but if your text doesn't match any of the entries in the enum, you will get an error 85 message.

Scan+From+String+-+enum.png

Rob

Robert Ward
Applications Engineer, NI
crossrulz
Knight of NI Knight of NI
Knight of NI
on

I am also a fan of just using the Scan From String.  It does everything your code does, but faster and a whole lot smaller.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Olivier_L
Active Participant
Active Participant
on

Whaou!

This trick with Scan from string is exactly what I needed!!

Actually, I used it from enum to string, but didn't know how to use it from string to enum.

The fact is that when you use an executable (particularly in RT), you can't access to "Strings[]" property because UI is removed, so property nodes don't work anymore. This trick will save my life ^^

Olivier L. | Certified LabVIEW Developer


Todd_Lesher
Active Participant
Active Participant
on

One caveat: if the enum contains "One", Two", "Three", and the string scanned from is "Oneasdf", scan from string will return the enum value "One".

David_Grucza
Member
Member
on

For Reference: You can simply cast an Integer to an Enumeration. I'd include a snippet, but it doesn't seem to want to upload.

MarceloA
Member
Member
on

Hi

 

maybe you can use this solution

Anmerkung 2020-02-05 133050.pngAnmerkung 2020-02-05 133104.png