LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Enum values as string

I need to customize the Enum's values with string. but by default, it is Numeric but i need to have string in place of numeric in values

0 Kudos
Message 1 of 9
(1,911 Views)

Hi Siva,

 

to get the selected enum item as string you just use FormatIntoString and wire the enum value to its input:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 9
(1,895 Views)

I'm not sure Gerd's solution is what you were looking for. On first read I thought it was what you look for but I think you look more for something like the Combo Box. If you disable "Allow Undefined Strings" it very much behaves like an enum.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 9
(1,882 Views)

A Enumeration is always a "named numeric list". If you want the text from an Enum, use Format into string, if you want a list of strings, use Combo box or ring control.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 9
(1,866 Views)

A ring allows run time editing of strings too.

 

You can actually edit an enum's strings (even in an exe IIRC), but only if the control is idle (either a ctl that's not in a running VI or a control on a VI that's not running). So that significantly narrows down the usefulness of this (to cases where a combobox or ring are more practical)...

 

If you want the strings of an enum (often), I'd modify a copy of Enum to Array of Enums.vim to Enum to Array of String.vim:

wiebeCARYA_0-1693986553254.png

 

Every now and then a right click menu can be used, as a menu has the same look as an enum. You can catch the mouse down? event, and if it's a left click change it to a right click. Now every control can have enum-ish behavior. Of course you'd need to catch the menu selection event. The menu can be stored in the control, and optionally be modified in the menu activation event. 

 

Message 5 of 9
(1,864 Views)

@wiebe Why so advanced?

Get Enum Names.png

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 9
(1,839 Views)

@Yamaeda wrote:

@wiebe Why so advanced?

Get Enum Names.png


Because going over variants will make things terribly slow. Relatively anyway.

 

Converting to variant is slow, but those variant type VIs have 1 or more CLFN, slowing down things even more.

 

The .vim code might actually be constant folded, resulting in 0 overhead during execution. This would make it as fast as a string array constant.

 

EDIT:

 

wiebeCARYA_0-1693994776004.png

Note that the .vim executes 50M times (vs 50K) and is still 40% faster.

Message 7 of 9
(1,830 Views)

wiebe@CARYA wrote:

wiebeCARYA_0-1693994776004.png

Note that the .vim executes 50M times (vs 50K) and is still 40% faster.


Dayum! That's a big difference! Though if performance is an issue i guess you can do something with First call and caching.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 8 of 9
(1,780 Views)

@Yamaeda wrote:

wiebe@CARYA wrote:

wiebeCARYA_0-1693994776004.png

Note that the .vim executes 50M times (vs 50K) and is still 40% faster.


Dayum! That's a big difference! Though if performance is an issue i guess you can do something with First call and caching.


Or make the .vim 😄.

Message 9 of 9
(1,718 Views)