LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating ENUM dynamically from string Array

Solved!
Go to solution

Hello,

 

I was wondering if it was possible to create an ENUM dynamically? For example, I would like to read in values from a string array and use each element to add a new item in the ENUM control. If this isn't possible, how do I configure a case structure to read in the values from a string array like an ENUM would normally be able to? It would help tremendously if I didn't have to manually enter the string name for each particular case. Thanks so much.

 

 

Download All
0 Kudos
Message 1 of 9
(20,628 Views)

Search the forum, you'll find this question has been asked many times before.

Short answer is: no, it's not possible to populate an enum at runtime. Also, if you don't know what values the enum can have at runtime what cases should the case structure have?

So if you know the values at design time, you can use an enum. If not, use a ring.

 

Hope this helps,

Daniel

 

0 Kudos
Message 2 of 9
(20,618 Views)
Solution
Accepted by topic author Newbie217

Ditto Dan's comments.

 

If you are asking because you just want to save a lot of work at edit time you could wrie all of your strings to a ring and then afterwards right-click and choose replace >>> enum and the object will change to an enum with all of the ring's strings.

 

Remember to include default case since you are dealing with strings.

 

I hope that helps,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 3 of 9
(20,593 Views)

However if you have a lot of strings and want to create an enum, you can do this one initial time.

 

See the LabVIEW code repository.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 4 of 9
(20,580 Views)
Using the Ring approach and converting it to an ENUM after works great! Thank you! Basically, what I was trying to accomplish was a way of obtaining all the variable labels to setup a case structure. This works great!
0 Kudos
Message 5 of 9
(20,547 Views)

great idea for saving time!

0 Kudos
Message 6 of 9
(17,774 Views)

Presumably you are the same person on LAVA that claimed to have code to take an array and make it into an strict type def enum.  A) your code doesn't work because it cannot be encorporated into projects (password protected, etc), B) If you are going to provide solutions on a public help forum why do a password protect on the code.

0 Kudos
Message 7 of 9
(14,360 Views)

Hi muzza,

 

who is "you" when you answer in a very old thread?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 9
(14,325 Views)

The words in that post sound very familiar, but I couldn't find the thread. I wonder if this is a spambot about to happen...

0 Kudos
Message 9 of 9
(14,308 Views)