LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert string data to enum

I have a enum defined. And I read a string from a file.

I would want to know how to convert the string to its corresponding enum value without using a case structure.

Thank you very much.
0 Kudos
Message 1 of 9
(6,091 Views)
Hi,

Use the Scan From String function. Wire the enum to the default value.

Regards,

wiebe.


"mprogram" wrote in message
news:506500000008000000EBC30000-1077587809000@exchange.ni.com...
> I have a enum defined. And I read a string from a file.
>
> I would want to know how to convert the string to its corresponding
> enum value without using a case structure.
>
> Thank you very much.
Message 2 of 9
(6,091 Views)
You could read the enum's strings and then use Search 1D Array as per the attached.
=====================================================
Fading out. " ... J. Arthur Rank on gong."
Message 3 of 9
(6,091 Views)
Nice solution. Thanks!
0 Kudos
Message 4 of 9
(6,091 Views)
Thank you very much for your help. It was really useful
0 Kudos
Message 5 of 9
(6,095 Views)
How about the other way around.  I have an enum value from radio buttons I'd like to convert to a string.  The labels of the radio buttons are:
  • NORMAL
  • SINGLE
  • BURST
  • DCYCLE
The output type is Unsigned Long(0 to 4,294,967,295), enum{NORMAL, SINGLE, BURST, DCYCLE}. I assume it outputs something along the lines of "0 NORMAL", "1 SINGLE" etc IF properly converted to string form. I can then strip the "1 " and use the enum value to include in a concatenated string to create a command to send to a Pulse Generator. I tried using the type cast function and the flatten function with no inputs other than the radio button output. Then simply placed the output from the converter to a string indicator to check operation. It appears that I get " " or " []" (four spaces, or 3 spaces and a box). I'm clueless, but investigating. Whose got ideas?
0 Kudos
Message 6 of 9
(5,686 Views)
Wire it into a Format Into String primitive and you will get the string value.

___________________
Try to take over the world!
Message 7 of 9
(5,684 Views)
http://forums.ni.com/ni/board/message?board.id=170&message.id=163308&query.id=79970#M163308

I JUST figured this out... I had NO idea it would be that simple.  How in the WORLD is it doing that??!?!?  LabVIEW really has amazed with a lot of the things I assume are going to be more complicated than they turn out.  Works PERFECT!!!!!!!

Thanks for the help!
0 Kudos
Message 8 of 9
(5,681 Views)


@Radiance_Jon wrote:

How in the WORLD is it doing that??!?!?

That's fairly simple. The enum wire carries the names with it, as well as the current value. All the primitive needs to do is extract the strings and index out the correct element.

You could write it yourself like this:


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