LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

triangular select function to select case

Solved!
Go to solution
Message Edited by smercurio_fc on 03-16-2009 10:32 AM
0 Kudos
Message 11 of 35
(1,587 Views)
How many cases do I have to put into the case structure?  So you are thinking when it is a non-case value that it will execute the state at the end of the state machine?
0 Kudos
Message 12 of 35
(1,575 Views)
I don't remember a case statement not requiring a default but if that is truly the case, it should take you about 60 seconds to test it and see what happens. Just create an integer front panel control and wire it to a case statement. In each case, put a popup with an appropriate message - in case 0, the message would be 'Case 0'. In case 1, the message would be 'Case 1'. Run the VI with the control set to 0, then run it with the control set to 1, and then run it with the control set to 2.
0 Kudos
Message 13 of 35
(1,561 Views)

BME genuis wrote:
How many cases do I have to put into the case structure? 

As many as you had in your original code. 9 I believe you said you had. You don't need to have any code in the cases. You just need the cases. 

 


So you are thinking when it is a non-case value that it will execute the state at the end of the state machine?

I don't honestly remember 100%. It's been a long time since I've used LabVIEW 5. 

 

You could, of course, deal with the situation differently if you want something a bit more robust. You could, for instance, have an outer case structure that handles if the value is above 10.

 

Message Edited by smercurio_fc on 03-16-2009 11:36 AM
0 Kudos
Message 14 of 35
(1,557 Views)
None of my state machines have a Default case in their case structures.  Do you have to set a default case? Can you send me some code Dennis on how to do what you say?
0 Kudos
Message 15 of 35
(1,541 Views)
I tried to make a little program like you said but when I don't have a Default case it says an error.."no case for some selector values".  However in my main program none of my case structures have a Default case and there is no error??
0 Kudos
Message 16 of 35
(1,535 Views)
What do you have connected to the case selector? Is it an ordinary numeric or an enum?
0 Kudos
Message 17 of 35
(1,520 Views)
Ordinary numeric control.  Should I use an enum and do I have to have a default case?
0 Kudos
Message 18 of 35
(1,506 Views)

If you use an enum, you define all of the values contained in that enum...ergo, you can (and should) specify a case for each value of your enum.  That way you can guarantee that you won't be feeding values to your case structure that aren't handled by the structure.  If you aren't going to code up a case for each value of your enum, then you should use a default case.

 

If you aren't going to use an enum as described above, then you should certainly specify a default case. 

 

The key here is that, by having a default case, you know exactly what your code will do in all circumstances, even unexpected ones.   That's very important, particularly if you're planning on ever using the code for anything.  Random, unexpected behavior is very annoying to the user (and to the programmer).

 

I'm curious about the discrepancy that exists in your posts -- supposedly the case structures inside your main VI don't require a default case, but when you try to code up the very simple examples posted here to test case structure behavior in 5.1.1, LabVIEW tells you that a default case is required.  I presume that you are using the same copy of LabVIEW in both instances?  If so, then there is a detail here that's missing.  What is it? 

0 Kudos
Message 19 of 35
(1,497 Views)
That is exactly right.  I do not have a default case in the state machine that can have a non-case value going to the case selector.  And when I try in the same version of Labview to not use an enum and instead an ordinary numeric it wont let me but when I make one of the cases a default then it lets me???
0 Kudos
Message 20 of 35
(1,490 Views)