LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Darren's Weekly Nugget 03/02/2009

This nugget is the second in a series of nuggets on Case structures.  Today I will discuss Case structures that use Numeric data types for their selector values.

 

Numeric selector

You can wire any integer or floating-point numeric value to the selector of a case structure (note that complex numerics, and numerics with units, are not supported).  If you wire a floating-point value to the selector, it will be coerced to the nearest integer value.  You can specify cases for single values, multiple values (separated by commas), ranges of values (denoted with '..'), and multiple ranges of values:

 

 

As you can see, a range that does not include a lower bound or an upper bound will include all numeric values below/above the specified bound.  So a range of '..-1' includes all negative values up to and including -1, and a range of '1..' includes all integers of value 1 and higher.  I like using this notation instead of doing something like wiring my numeric to a "Less than 0?" function and then using the boolean output of that for a boolean Case structure...it saves some room on the diagram.

 

Another interesting tidbit about Numeric Case structures is that you can show the radix, which helps if you're dealing with non-decimal values:

 

 

Message Edited by Darren on 03-02-2009 04:35 PM
Download All
Message 1 of 7
(9,726 Views)

Another use for a numeric case structure is if you want to execute a case based on one of several booleans. You can build the booleans into an array and then use Search 1D Array to find the index of the first T boolean, which you can then feed into the selector.


___________________
Try to take over the world!
0 Kudos
Message 2 of 7
(9,637 Views)

This simple test of tst's idea was done in 8.5.

 

- Brad

0 Kudos
Message 3 of 7
(9,593 Views)

And if you want to support running different cases if multiple Boolean values are selected, you can use the Boolean Array To Number function with cases based on the binary value of the number (this is a decent use case for showing the Radix, as I mentioned above):

 

 

Message Edited by Darren on 03-03-2009 02:52 PM
Message 4 of 7
(9,580 Views)

Darren wrote:

And if you want to support running different cases if multiple Boolean values are selected, you can use the Boolean Array To Number function with cases based on the binary value of the number (this is a decent use case for showing the Radix, as I mentioned above):

 

 

Message Edited by Darren on 03-03-2009 02:52 PM

Just curious because I think I am misunderstanding. How are these options selected? Because isn't 11 in binary = 3 in base 10? So why is 100 used for the case when option 3 is selected?

 

.............Nevermind.....stupid mistake 🙂 I was looking left to right  for cases 1 2 3

Message Edited by for(imstuck) on 03-05-2009 12:28 PM
0 Kudos
Message 5 of 7
(9,470 Views)
Ahhhh memories 🙂  That's the way we had to poll FP buttons in a loop before the event structure was invented...




Copyright © 2004-2023 Christopher G. Relf. Some Rights Reserved. This posting is licensed under a Creative Commons Attribution 2.5 License.
0 Kudos
Message 6 of 7
(8,466 Views)

Darren wrote:

And if you want to support running different cases if multiple Boolean values are selected, you can use the Boolean Array To Number function with cases based on the binary value of the number (this is a decent use case for showing the Radix, as I mentioned above):

 

 

Message Edited by Darren on 03-03-2009 02:52 PM

If you type cast that numeric as an enum you can get descriptive names for the cases.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 7 of 7
(8,451 Views)