LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Last enum value via coerce to type

So I wanted to get an opinion on the robustness of this method of finding the last value of an enum.

Enum last value.png

I have a basic idea of what the coerce to type does. However, I can't help but get nervous when I test the edges of a function that I don't fully understand what's happening under the hood.

 

Fun note: If it's a robust concept, it allows you to iterate over every value of an enum.

Enum every value.png

Get enum values.png

Josh
Software is never really finished, it's just an acceptable level of broken
0 Kudos
Message 1 of 5
(1,978 Views)

@JW-JnJ wrote:

Fun note: If it's a robust concept, it allows you to iterate over every value of an enum.


So does Enum to Array of Enums.vim...

 

Range Limits for Type.vim does most of this. But you still have to convert to I32 and add 1.

 

As NI uses this exact method (see there vims), I'd say it's the way to do it.

Message 2 of 5
(1,953 Views)

You might enjoy looking at the Natt Sequence.  I'm fairly certain the Enum To Array Of Enums.vim is included in LabVIEW 2020.

 

EDIT: Yep, that VIM was added in LabVIEW 2020.  Look in the Numeric->Conversion palette.  Also added was the Range Limits For Type.vim in the Numeric palette.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 5
(1,946 Views)

@crossrulz wrote:

You might enjoy looking at the Natt Sequence.  I'm fairly certain the Enum To Array Of Enums.vim is included in LabVIEW 2020.

 

EDIT: Yep, that VIM was added in LabVIEW 2020.  Look in the Numeric->Conversion palette.  Also added was the Range Limits For Type.vim in the Numeric palette.


Cool. I didn't see the range limits vim when I migrated to a newer LabVIEW recently. Also, it seems that range limits vim does the coerce from infinity so I guess it's a viable thing to do. Thanks.

 

Edit: I JUST migrated to 2020, so I'm still catching up.

Josh
Software is never really finished, it's just an acceptable level of broken
0 Kudos
Message 4 of 5
(1,936 Views)

I'll admit the other options laid out here are probably better.  But here is the first solution I thought of.  It doesn't use VIMs, and so older versions of LabVIEW can do this too.

 

Example_VI_BD.png

 

This function returns all enum values as an array of strings.  Using the delete from array will give you the last one.  Or if you want it as an enum you can get the size of this array then use coerce to type.

0 Kudos
Message 5 of 5
(1,910 Views)