取消
显示结果 
搜索替代 
您的意思是: 

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 项奖励
1 条消息(共 9 条)
7,531 次查看
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.
2 条消息(共 9 条)
7,531 次查看
You could read the enum's strings and then use Search 1D Array as per the attached.
=====================================================
Fading out. " ... J. Arthur Rank on gong."
3 条消息(共 9 条)
7,531 次查看
Nice solution. Thanks!
0 项奖励
4 条消息(共 9 条)
7,531 次查看
Thank you very much for your help. It was really useful
0 项奖励
5 条消息(共 9 条)
7,535 次查看
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 项奖励
6 条消息(共 9 条)
7,126 次查看
Wire it into a Format Into String primitive and you will get the string value.

___________________
Try to take over the world!
7 条消息(共 9 条)
7,124 次查看
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 项奖励
8 条消息(共 9 条)
7,121 次查看


@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!
9 条消息(共 9 条)
7,105 次查看