LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

As Few Case AS possible

Solved!
Go to solution

Hi all,

 

Please let me know what is the best way to tackle the simple problem below with as few case structure as possible.

 

input: a 1D array of 2 elements.

ideal (if possible): there would be a case structure with 3 cases plus a default case.  The condition would be if element 1 or element 2 from the input satistify case 1-execute case 1, same for case 2, same for case 3, and if none of the element satisfy any case, execute the else case.

 

Note: I only want to run the default structure only if none of the element in the array match any of the cases.

 

 

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 1 of 7
(3,069 Views)

Reader digest version

 

Use a compare if eaqual configured to compare elements and then case the boolean array as a number wired to the case structure. The cases should be configured for the possilbe values.

 

Maybe someone will draw this up.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 7
(3,065 Views)

Here is a picture of Ben's solution:

 

20257i154CADB44FC41C84

 

If this isn't what you are looking for, then tell us what the 3 conditions are that will cause the 3 cases to execute.  Could it be like A<B or A>B or A=B, where A is the first array element and B is the second?

- tbob

Inventor of the WORM Global
Message 3 of 7
(3,041 Views)
Solution
Accepted by topic author jyang72211

Very close to what I was thinking.

 

here you go.

 

20263iBE8646B0CF1D3F1C

 

The "0" case is the default and catches the no match.

 

"1" "3" catches when the first matches or both match.

 

"2" catches the second matchine only.

 

That is three cases by my count.

 

Ben

 

 

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

Hi all,

 

My situation is slightly different, but I took what you guys showed me and created the attached.  Please take a look and see can I refine it some more.  Thanks!

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 5 of 7
(3,012 Views)

Using binary for the case is a nice touch.

 

If that logic does what you want Its OK but I did not exactly see what you are trying to match up so for the sake of those that follow you, you may want to add some text explaining your logic in plain speak.

 

Another thing you can add is an enum to make reading the case easier. After caseting the nimeric as a U32 (or is it I32) you can type cast the numeric as the enum. THe enum can be set up so that you have a clear way of defining the condition.

 

For example;

 

In the code I showed I set up a case to handle the values "1" and "3" in the same case. If I had type cast it as an enum where the value "3" had the text "Both match", you would not have to understand boolean to understand that case was intended to handle the condition when both values matched up.

 

Ben

 

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

The type casting is a good call.

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 7 of 7
(2,955 Views)