Example Programs

cancel
Showing results for 
Search instead for 
Did you mean: 

Find Enum Item from String Input

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
Comments
Rob_Ward
NI Employee

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
Knight of NI Knight of NI
Knight of NI

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
Active Participant Olivier_L
Active Participant

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


Active Participant Todd_Lesher
Active Participant

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".

Member David_Grucza
Member

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.