LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case Structure

Hi,

i want your help , i am going to create a program this program have 16 cas structure ( if x true ….. else if false …) is there another way to make this program without using so many case structure .

Thank you for your answer .

Best Regard.

 

0 Kudos
Message 1 of 22
(2,621 Views)

I have never actually needed to make such a case structure hierarchy and I don't think you really need it. I am pretty sure that one case structure with 16 cases will do what you want. 

Certified LabVIEW Architect
0 Kudos
Message 2 of 22
(2,609 Views)

If it's all boolean cases, you can create an array and convert to number, thus only having 1 case structure with more cases instead of many nested ones.

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 22
(2,599 Views)

@Emna20 wrote:

Hi,

i want your help , i am going to create a program this program have 16 cas structure ( if x true ….. else if false …) is there another way to make this program without using so many case structure .

 


If then .. else .. else ...

 

This does not require nested case structures, it's simply several cases in one case structure.

 

if a==1 then ...

 else if a ==2...

 else if a ==3...

 else if a ==4...

 

One structure with multiple cases

 

if a==1 then

 ...

 else if b ==1 then

  ...

  else if c ==3 then

   ...

   else if a ==4 then

   ...

 

4 nested case structures...

 

Nested structures should be limitted. The way to avoid this depends very much on the details.

0 Kudos
Message 4 of 22
(2,582 Views)

This is another example where attaching your code would have resulted in a very speedy answer and "teaching demonstration" of "an alternate way of thinking" about this problem.  We don't know what your Cases actually involve.  If it involves a choice between a small subset of a larger set (say, a choice if an integer, call it "N", is 1, 2, 3, ... 16), you can make a Case Statement with N wired into the "?" input, and Cases for 1 .. 16.  But this Case Statement will be "broken" because you don't have a Case for all possible Values (for example, no "17" case, and no "-1234" case).  This is where the "Default" case comes in handy (think of it as the "ultimate Else".  You can either program 16 "correct" cases and leave "Default" to send an Error Message ("Unexpected Case"), or you can have a Case "1, Default".

 

Look at the JKI State Machine, which uses Strings for State names.  The Default is an Error message saying "Unexpected State" (or something like that).  [The alternative State choice, an Enum, creates a pre-determined finite set of States, so you only need as many Case Statements as you have States, and no Default is needed].

 

Bob Schor

0 Kudos
Message 5 of 22
(2,558 Views)

Hi,

Thank you for your response .

you find below the program , 

Best Regard.

 

0 Kudos
Message 6 of 22
(2,532 Views)

Here is One way to avoid the nested case structures...

 

Frozen_0-1584974868702.png

 

---------------------------------------------
Certified LabVIEW Developer (CLD)
There are two ways to tell somebody thanks: Kudos and Marked Solutions
Message 7 of 22
(2,526 Views)

That is scary. Don't do it like that!

 

I you have 4 booleans, you have 16 combinations. So convert the 4 booleans to an array, convert the array to number. Wire the number to case selector.

 

Add a case for each of those numbers.

 

If there are groups of similar things to execute (for instance if the 2nd boolean is true) you might end up with a few parallel case structures.

0 Kudos
Message 8 of 22
(2,523 Views)

Pretty sure  was talking about the original code... not the cod snippet I posted. LOL

(IE his description is the code I posted)

---------------------------------------------
Certified LabVIEW Developer (CLD)
There are two ways to tell somebody thanks: Kudos and Marked Solutions
Message 9 of 22
(2,520 Views)

@Frozen wrote:

Pretty sure  was talking about the original code... not the cod snippet I posted. LOL

(IE his description is the code I posted)


Yes, that crossed.

0 Kudos
Message 10 of 22
(2,511 Views)