LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
BruceAmmons

Equivalent of Switch statement in C

Status: Declined

Any idea that has received less than 2 kudos within 2 years after posting will be automatically declined.

I would like to see a case statement that would work like a switch statement in C.  You could wire a cluster of information to the input that has all the data of interest in it, such as the values of A, B, C, and D.  Each page of the case statement would have a complex logic statement that defined what it handled, such as "A<3 and B>4".  If this was false, it would drop through to the next case.  If none of the cases were true, it would drop down to the default case which would always be last.

 

Another possibility instead of a cluster would be using one input for each variable, just like the formula node uses.  You could enter a name for each input that would be used in the case statements.

 

This would have saved me a bunch of time in a recent program, where there were three possible values for A and three for B, as well as C and D.  The cases ended up being nested four deep, which is something of an editing nightmare.  The ability to do multiple comparisons within a single case statement would have been wonderful.

 

It might be a little confusing to keep track of the order/priority of the cases.  We might need some sort of tool for viewing the whole list of cases and editing each case, sort of like editing the list of values for an enum.

 

This idea was inspired by JeanPierre's request for an if else statement.

 

Bruce

Message Edited by Bruce Ammons on 07-30-2009 10:42 PM
Bruce Ammons
Ammons Engineering
13 Comments
tst
Knight of NI Knight of NI
Knight of NI

It doesn't really matter how it's called in other langauges. We need something which will work for LV, which might mean something different from text-based languages.

 

In the thread where Bruce originally posted this idea there was a link to the following suggestion, made by NI long ago:

 

I have no idea what I think about this or Bruce's suggestion, but if I'm understanding correctly, this is basically the same thing.


___________________
Try to take over the world!
Tom_Hawkins
Member
Couldn't this be rather easily handled using a state machine? I'd rather build on the powerful state machine pattern than add extra complication to the case structure. 
Darren
Proven Zealot
Status changed to: Declined

Any idea that has received less than 2 kudos within 2 years after posting will be automatically declined.