LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
rimfire44

Replication of case structure code as you add cases for all enumeration values

Status: Declined

Any idea that has not received any kudos within a year after posting will be automatically declined. 

I often create enumeration driven case structures where the cases are very similar, often with a single tiny change between cases.

 

Currently you have the options to duplicate a case or to automatically create a case for each enumeration value.  It would be very useful to have a third option that melds the two options. Call it something like "Duplicate case for every value".  This way you could create a single case, hit the button, and have all your cases ready to go for the minor changes.

5 Comments
altenbach
Knight of NI

Well, if the cases only differ by a tiny change, only the changed code belongs inside the case structure. All shared code belongs outside the structure, right?

rimfire44
Member

Suppose the piece of code inside the case structure is a property node tied to a particular control?  Linking it to the correct control is a darned tiny change that can't be done outside the structure without creating a heck of a mess that the case can handle simply. I can provide other examples, but hopefully this illustrates the point. 

 

Intaris
Proven Zealot

Bad example.  Exactly that CAN be handled outside the case structure.....  Doesn't even NEED a case structure, you can do it with an array index......

 

Still, it doesn't actually detract from the idea itself which is IMHO valid.  Is it a corner case? Sure.  Is it worth NI R&D time? For me personally, no.  But I'm not going to argue agianst it because it IS valid, just not important.

Darin.K
Trusted Enthusiast

There are definitely situations in which all cases share common pieces of code, for example the common state machine has an enum output in each case typically.   Other cases might include mapping an enum to a sibling object for dynamic dispatching.  The nice thing about duplicating all of these cases is that the objects wind up in the same place which looks good.  (I do really miss BD paste-replace though).  Yet another example is having a set of several controls which have different enabled states based on the value of an enum.  Every case is the same set of constants feeding out to the PropNodes, only the values are different.

 

I am old-fashioned and only tend to let LV autogenerate code that I can immediately see and use.  This means I am often happy with having a default case which I duplicate N times by hand.   Inevitably, half way through the cases I realize there is one more piece of code I want to have in common.  I can add it to the 'Default' case and at least all new cases I create going forward have it. 

 

In short I agree with the OP that there are common use cases which lead to sharing the same or very similar code amongst many cases.  Personally I just would not use this particular option to get there.

Darren
Proven Zealot
Status changed to: Declined

Any idea that has not received any kudos within a year after posting will be automatically declined.