LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write "user-friendly" value of enum control

I have a VI that generates various stimuli, defined in an enum control called "Stimulus".  I have a "stimulus" variable which holds the particular value of the control.  Generating code is very nice, because wiring the "stimulus" to the Case Statement selector shows me the "user-friendly" name of each stimulus (Sinusoid, Trapezoid, Random Walk, etc.) instead of the enum values (0, 1, 2 ...).
I am writing a Config file that describes my test, and want to output the stimulus value.  If I simply wire the variable "stimulus" to the Write Config data terminal, it gives me the numeric enum value (e.g. 0).  I'd like to get the "User-Friendly" value, defined in the Enum control (e.g. Sinusoid).  Short of hand-coding the strings in myself, is there a way to get the (string) values directly from the TypeDef control?

Bob Schor
0 Kudos
Message 1 of 7
(3,437 Views)
Just use a Format Into String function:





Message Edited by smercurio_fc on 03-04-2008 10:08 AM
0 Kudos
Message 2 of 7
(3,433 Views)
Hi Bob,

use the "format into string", wire the enum as input, "%s" as foirmat and you get the text of that enum value...
But when loading the config back you have to convert this string back to enum (=integer) value...
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 7
(3,431 Views)
As GerdW mentions, in the other direction you will need to find the numerical value of the enum based on the strings. You will need to search the array of strings of the enum to get the numerical value, which you can then typecast to the enum, as shown in this example:

The "antenna config" enum in this example is a typedef. I would strongly recommend making your enum a typedef as well in this case.


Message Edited by smercurio_fc on 03-04-2008 10:14 AM
0 Kudos
Message 4 of 7
(3,427 Views)
You can also use Scan From String with an enum constant as the default value. Include an error value in your enum to test if there was a match, or you can look at the error out to see if the Scan from String function failed.




Message Edited by Phillip Brooks on 03-04-2008 12:41 PM
Message 5 of 7
(3,404 Views)
That's what's so great about LabVIEW. So many ways to do things, and so little time... Smiley Very Happy
0 Kudos
Message 6 of 7
(3,390 Views)
Many thanks, and I'm embarrassed that I didn't "think of the obvious" (I tried typecasting, but that didn't work ...).  I'm also pleased to see that at least one responder (Phillip Brooks) is a fan of Nicholas Wirth (Pascal, Modula, maybe even Algol?), judging by his signature ...

Bob Schor
0 Kudos
Message 7 of 7
(3,375 Views)