LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

changing enum values

Solved!
Go to solution

1. I want to make an enum with the []strings being set from file (a text file containing "option 1,option 2,option 3...").
I already have a vi which gets the file and gives an array with the options, but it seems like I can't change the enum's []strings propety from within the program.

I thought about using a second vi that upon running will open my main vi, change the enum's []strings, run the main program and terminate itself, but that seems like a lot of troubles for something that's supposed to be simple.

is there a simpler way of doing it?

attached are the vi, a snip of the vi, and an example list.

 

2. after I'll have that working- I have a tab control where many of the tabs are using enums with the same list. do I have to creat a property node for each enum or is there a better way?

 

thanks!

Download All
0 Kudos
Message 1 of 10
(8,428 Views)

You can't load enum string values programatically. Do the same thing but with a text ring.

PaulG.

LabVIEW versions 5.0 - 2020

“All programmers are optimists”
― Frederick P. Brooks Jr.
Message 2 of 10
(8,406 Views)
Solution
Accepted by shayelk

You can't change enum values run time. Have you tried using a menu ring or text ring (see attached). 

 

Bit more detail here on trying to change enums 

http://digital.ni.com/public.nsf/allkb/24C62D0FFA55132C8625694B006FCF17

 

 

 

Edit: What Paul said!

Message 3 of 10
(8,401 Views)
Solution
Accepted by shayelk

If you want a number for the data type, the use a Ring.  If you want the string for the data type, then use a Combo Box.  They work the same way.  It is just a matter of what you want your data to be.

 

For your many items using the same list, I would create an array of references to those controls.  You can then use a FOR loop to update all of their lists (autoindex on the array of references).


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
Message 4 of 10
(8,393 Views)

You cannot edit the Enum values in run time. Instead you can try using the Ring control.

 

Edit: I took so long that already 3 replies came 🙂

-----

The best solution is the one you find it by yourself
Message 5 of 10
(8,391 Views)

Thank you! I can't believe the solution was so simple.
any disadvantages of using text ring rather than enums?

0 Kudos
Message 6 of 10
(8,385 Views)

@shayelk wrote:

any disadvantages of using text ring rather than enums?


Enums are set at compile time.  Therefore, they become self-documenting code.  You can wire an enum into a case selector and you will be able to choose your case based on the string in the enum.

 

Rings are set at run time.  Therefore you don't have the self-documenting code like the enum.  But you can change the list on the fly.

 

Personally, I prefer the combo box over the ring.  The ring's data type is a number.  But almost always, what I need is the string.  So instead of getting the item list and then indexing out the item based on the value of the ring, I just use a combo box which just gives me the string.  Makes my life a lot simpler.  Plus you can type in a combo box (it is a string data type after all) and it will autocomplete for you.

 

So as a complete generality, enums should be used by programmers (ie, only in code and APIs) while Combo Boxes and Rings should be used for user interfaces.  Again, that is a generality and does not apply anywhere close to 100% (probably more like 75%) of the time.


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
Message 7 of 10
(8,358 Views)

Enums are more readible with cast structures. Rather than getting '1' or '3' as your case names, you get 'Blue' or 'Orange'. 

Text rings give a U16 number which relates to the index of strings it holds, so if you wanted named cases you could alway use string case structure and then it's input would be the index (see attached)

Also since enum's can't be changed programmaticaly, they are safer to program, because there is a known amount of enum states. The number of entries of text ring can change run time and therefore (potentially) have unhandled states in your programme. 

 

Message 8 of 10
(8,353 Views)

got it, thank you!

0 Kudos
Message 9 of 10
(8,348 Views)

rthomas101 wrote:  Text rings give a U16 number which relates to the index of strings it holds

You can change the data type of the ring to be an I32 and then you won't have the coersion when trying to index out your string.

 

Or just use the combo box.Smiley Tongue


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
Message 10 of 10
(8,342 Views)