LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Enum Numbering?

I can't seem to find anything on this, so I'm assuming it's not allowed.  I would like to create an enum with custom numbering.  Say I wanted a enum of baud rates.  Ideally, it would look like this:

Enum   Value   Desired Value
4800       0       4800
9600       1      9600
19200      2      19200

Is there anyway to do this?  I feel it's right in front of me, but I can't seem to find it!

Thanks,
Derek
0 Kudos
Message 1 of 9
(5,134 Views)

I did something like that. I used a Text box instead of Enum. As long as the values are unique it should work.

Daniel Keyser


"I reject your reality and substitute my own"
Adam Savage
"Mythbusters"
0 Kudos
Message 2 of 9
(5,129 Views)
Enum value can only be sequential and positive. (U8, U16 and U32).

You want to use the ring control like Dan said.

Regards,
André (CLA, CLED)
0 Kudos
Message 3 of 9
(5,123 Views)

You're not missing anything - this can't currently be done. See here.

You can use a ring, but a ring does not label case structures and its values are not automatically preserved through typedef changes (you can preserve them if you change the datatype, e.g. by changing the representation, but you have to be careful).

One option would be adding the numeric value into the enum string and then converting the enum to a string and parsing it out, like shown in the attachment.


___________________
Try to take over the world!
0 Kudos
Message 4 of 9
(5,121 Views)
Thanks for the info and suggestions.  It seems such a shame not to allow enums to have non-sequential ordering.  I did a search through the group, but didn't think to use the search term "sparse."

tst - I think I'll probably use your suggestion, but I'll have to make sure that the enum name is stored in the INI file, and not the index.

Thanks for all your help!
Derek
0 Kudos
Message 5 of 9
(5,103 Views)
I just wanted to provide a simple example of how to save my Baud Rate enum to an INI while preserving the name as mentioned in my above post.  I've attached a screenshot showing how to do this.  It requires OpenG since it uses the "Read Key (variant)" and the "Write Key (variant)" VIs.

Thanks,
Derek

0 Kudos
Message 6 of 9
(5,083 Views)
Hi Derek,

what about using "format into string" and "scan from string" to get the enum's text? Kind of workaround, but works...

Ohh, tst did the same before 🙂


Message Edited by GerdW on 11-06-2007 05:34 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 9
(5,082 Views)
Okay - let's see if the image gets attached this time...
0 Kudos
Message 8 of 9
(5,080 Views)
Another option is using a VI to do the conversion, as shown here.

___________________
Try to take over the world!
0 Kudos
Message 9 of 9
(5,046 Views)