LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem type cast enum

Solved!
Go to solution

Hello, can you help me?

In this simple VI the indicator *(type *) &x 2 of function type cast is not corresponding at input data cluster.

When I run VI the outut is 2.

Thanks a lot.

Michele

0 Kudos
Message 1 of 8
(2,673 Views)
Solution
Accepted by MicheleU

When nothing is found in the Search array the output is -1. I guess -1 translates to Enum 2.

So, depending on how you want to differentiate between No button pressed and '0' pressed you need to change some things. 

So, assuming you want to show the selected button as Enum and no button pressed = 0, then you can do like this:

data cluster type cast.png

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 8
(2,665 Views)

So when you don't click any buttons, the True value isn't found.

The returned value is "-1".

 

When you click the buttons, I guess you get the results you expect?

 

The problem is because when you take -1 and pass it to the U16 conversion, you get the maximum value (65535).

This then coerces to the largest value in the enum (which is the closest), which is 2.

error data cluster type cast enum.png


GCentral
0 Kudos
Message 3 of 8
(2,662 Views)

Seems like you should just use a Radio Buttons instead.  It will do all of the work for you.


GCentral
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
0 Kudos
Message 4 of 8
(2,656 Views)

Have you did any probing to see what the problem is? Did you notice that your Search Array gives an output of -1 when all values are FALSE? Did you notice that this gets changed to 65535 when you convert to an unsigned integer? It is unclear what you are trying to do. Do you need to handle cases where two of the controls are TRUE? Or all three are TRUE? 

0 Kudos
Message 5 of 8
(2,653 Views)

This method of coerce, coerces to the closest value.

 

-1 -> 0

100 -> 2

 

snip.png

 

mcduff

Message 6 of 8
(2,599 Views)

@mcduff wrote:

This method of coerce, coerces to the closest value.

 

-1 -> 0

100 -> 2

 

snip.png

 

mcduff


Take care with this, if you keep the to U16 then the -1 becomes ~65k and so is now closer to 2 than 0 (so it's the same behaviour as the current VI).

 

Maybe if the OP tells us what they're wanting to do we could suggest a simpler/more robust method?


GCentral
0 Kudos
Message 7 of 8
(2,580 Views)

Your solution is perfect for me.

Thanks a lot.

0 Kudos
Message 8 of 8
(2,532 Views)