12-10-2014 07:28 AM
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!
Solved! Go to Solution.
12-10-2014 07:36 AM - edited 12-10-2014 07:38 AM
You can't load enum string values programatically. Do the same thing but with a text ring.
12-10-2014 07:38 AM - edited 12-10-2014 07:39 AM
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!
12-10-2014 07:40 AM
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).
12-10-2014 07:40 AM - edited 12-10-2014 07:41 AM
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 🙂
12-10-2014 07:45 AM
Thank you! I can't believe the solution was so simple.
any disadvantages of using text ring rather than enums?
12-10-2014 07:57 AM
@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.
12-10-2014 08:07 AM
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.
12-10-2014 08:20 AM
got it, thank you!
12-10-2014 08:33 AM
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.