From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

enum reference

Just a casual question which has arisen today at work....

Is it possible to cast an enum reference to another class in order to get a standardized structure which can then be built into an array with values from other enums which would otherwise be incompatible?  I thought maybe someone has already done this or knows how it can be done.  There's been a bit of activity casting into undefined types (cursor label position comes to mind), so I thought there might be someone willing to share a gem.

It would be great to be able to treat enums generically in this way by reducing them to a common denominator and then having access to an index along with the strings of the enum.

Cluster with index and an array of strings or something similar?

Curious,

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 1 of 10
(3,806 Views)

How about the attached, which someone attached here as a workaround for RT, where the reference would be no good? It uses the Type Descriptor to get the strings. You can probably dig around some more to get the values.

Another possible option would be the OpenG data tools, which may also deal with this.


___________________
Try to take over the world!
Message 2 of 10
(3,797 Views)
Fantastic,

That does the job.

Given the fact, however, that an enum can have a discontinuous series of values (0,3,12) corresponding to a specific string, is there any way to actually get the information regarding which string is linked to which enum value?

I know you've already mentioned it should be possible to dig around for more values, but i don't see where the valid enum values are to be stored in the type descriptor.

What I'm basically looking at is setting an enum VALUE based on the STRING read.  This seems, at the moment, to be something which has to be done on an enum-by-enum basis.  A generic method would be much more useful though......

Still curious

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 3 of 10
(3,787 Views)

I'm not sure I understand.

Some further digging shows that an enum can not have discontinuous values and that it can not have duplicate values. If this is so, you can READ its Strings[] property and use Search 1D Array to know which value to assign it. Isn't that right?


___________________
Try to take over the world!
Message 4 of 10
(3,782 Views)
Again 5 stars,

You're right.  I don't know where I got the idea that an enum can have discontinuous values.  I think I maybe edited an index value and without double-checking that it was really changed assumed that it had been confirmed.  That an enum can't have duplicate values whould be obvious even to ME (with the possible exception of mondays....)

Oh well, it seems that the index of an enum is really always 0....x.  This does indeed make things MUCH easier.

Thanks tst.

Shane.

PS I reckon you've given away your gender.  Would a female ever have mightymouse as their avatar?
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 5 of 10
(3,771 Views)

@shoneill wrote:
PS I reckon you've given away your gender.  Would a female ever have mightymouse as their avatar?

Just as much as a male would have Lucy (my previous, and probably future, avatar as she didn't get enough time) as his avatar. And if you're thinking of masculine characters, don't Sam & Max fit better?

___________________
Try to take over the world!
0 Kudos
Message 6 of 10
(3,765 Views)
OK, I think I missed Lucy.......

Sam and Max always fit anyone of sporadic violent nature....

Shane
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 7 of 10
(3,757 Views)
You probably got the idea that enums can have discontinuous values from the fact that rings can.  This makes rings much more useful than enums in GUIs.  In fact, I never use enums in a serious GUI because they cannot be localized - the text string is becomes part of your code and cannot be changed dynamically.
0 Kudos
Message 8 of 10
(3,740 Views)
The fact that the enum's "values" are fixed is, for me at least, one of the endearing features of the enum.  I use enums where I want to rule out unwanted changes after writing the software.

Side question:  Can the indices (values) and text of a (Strict typed) ring be changed at run-time?

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 9 of 10
(3,728 Views)
No, they can't. If you try to create a property node for a strictly typed menu ring, you'll see that the Strings[] property is read only.
0 Kudos
Message 10 of 10
(3,714 Views)