03-02-2009 04:34 PM - edited 03-02-2009 04:35 PM
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:
03-03-2009 11:37 AM
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.
03-03-2009 02:29 PM
This simple test of tst's idea was done in 8.5.
- Brad
03-03-2009 02:52 PM - edited 03-03-2009 02:52 PM
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):
03-05-2009 12:25 PM - edited 03-05-2009 12:28 PM
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
05-14-2009 01:32 PM
05-14-2009 02:51 PM
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