LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

text to enum

Hello,
I get a string from a configuration file with read key.vi and I want to put that value into a control which is a strict type def.
My type def contains only an enum with the items "A", "B" and "BOTH". Then I read "BOTH" from the file.
How do I select the corresponding string in my enum?
I tried a lot of things, casting, property nodes...
It sounds so simple!...
Thanks
0 Kudos
Message 1 of 8
(4,516 Views)
Use the property Strings[] by creating a property node. The string array are the strings visible in the enum.
0 Kudos
Message 2 of 8
(4,516 Views)
Indeed too simple... Use "Scan from String" function, wiring your enum type to default value and %s for format string.


LabVIEW, C'est LabVIEW

Message 3 of 8
(4,516 Views)
Hi,

I think as you said the Problem seems Simple and Solution should be a simple one too. Unless I am not understanding your problem correctly.

I would Use the "STRINGS" Property of the Control to give me a String Array of Items in your enum control. I would then Input this to "Search 1D Array" Function. as Array Input. The Element I am searching for is the Value obtained from Config file.

The Output of the Search 1D Array would be the index which I would wire to "Value" Property of my Control. So Now based on Value I read from File My enum will show corresponding Value.

One Note though. If the Value Coming from Config file is not found within the "Strings" array the Search Function will output -1. You may have to build functionality to handle this cas
e.

Good Luck!!

Mache
Good Luck!

Mache
Message 4 of 8
(4,516 Views)
I think you should use Jean Pierre's Solution. It is very elegant.

Regards,

Mache
Good Luck!

Mache
0 Kudos
Message 5 of 8
(4,516 Views)
Nice trick, thanks a lot.

Martin
0 Kudos
Message 6 of 8
(4,516 Views)
Strings of enumerated types cannot be changed during runtime. Writing to the
Strings[] property node is ignored (an error code 1000 is generated).

Enums are types. They can be used to wire to a case, and the case names
change because it is a enum type, the names cannot change during runtime!

Use a menu ring or text ring instead. A menu ring and text ring are U16 (see
for yourself in the diagram). A enum is a <> type. The text ring looks the
same for the user.

When you wire a text or menu ring to a case the names will not show up in
the case (because the names can change during runtime!).

Change the text of a text or menu ring using the Strings[] property.

Regards,

Wiebe.



"mstlaurent" wrote in message
news:506500000008000000365700
00-1027480788000@exchange.ni.com...
> Hello,
> I get a string from a configuration file with read key.vi and I want
> to put that value into a control which is a strict type def.
> My type def contains only an enum with the items "A", "B" and "BOTH".
> Then I read "BOTH" from the file.
> How do I select the corresponding string in my enum?
> I tried a lot of things, casting, property nodes...
> It sounds so simple!...
> Thanks
0 Kudos
Message 7 of 8
(4,516 Views)
As Wiebe says, you get the error code 1000,
is there a way to avoid this?
Best regards, Stefan
0 Kudos
Message 8 of 8
(4,516 Views)