From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Enum to array of Booleans

Solved!
Go to solution

Hi everyone!

 

I am looking for a "better" way of doing the following:

 

I have an enum with "ALL" as 0th value, and a number of testcases to choose from.

Now i need the enum represented as an array of booleans and each index corresponds to the i-th enum entry (for i > 0).

If "ALL" is selected all booleans in the array must be true,

for any other selection, only the corresponding array index should be true.

 

enum-to-bool-array.png

 

would love to get some suggestions.

 

thx and regards jwscs

 


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 1 of 4
(3,335 Views)
Solution
Accepted by topic author jwscs

Looks pretty clean, however since you want an array at the end, I would use "array subset" instead of the "index array".

 

Of course you could just use a 2D array diagram constant as a lookup table and index into it using the enum. That's what I probably would do.

 

EnumLUT.png

 

 

 

0 Kudos
Message 2 of 4
(3,318 Views)

The lookup table is also more flexible for more complicated scenarios where code would be complicated.

 

Imagine an enum with the following states:

(1) all

(2) none

(3) A&B

(4) C&E

(5) A&E

(6) …

 

 

 

Message 3 of 4
(3,282 Views)

hi altenbach!

thx for the suggestion, the lookup table is a neat idea.

and regarding the index-array-function, that is the end before each boolean value goes into a case-structure.

 

:cheers:

 

p.s.: i will mark as solved, but guys (and girls, and any sex u may feel like) feel free to come up with other ideas, which i'll then mark as solution too 😉

 

EDIT: gender stuff 😉


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 4 of 4
(3,281 Views)