LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with VI...

Solved!
Go to solution

I am unable to run the attached VI because, apparently, i don't have enough cases to accommodate all my selector values.  I strongly disagree!  I have 4 cases for 4 selector values.  The selector values are 0, 1, 2, 3 and so are my cases.  Please could someone enlighten me as to why this error is flagging up.  It's driving me crazy!

 

James

Message Edited by James Mamakos on 05-18-2009 07:54 PM


Never say "Oops." Always say "Ah, interesting!"

0 Kudos
Message 1 of 11
(3,398 Views)
You simply have to select one of them as 'Default'. Right click on the case statement and you will see the option at the bottom of the list.
0 Kudos
Message 2 of 11
(3,392 Views)
May I suggest using a more informative heading for your forum posts in the future. You will attract people that know more about a certain area if the topic of your post has something to do with the content of your post. No worries man. Hope you fix your problem.
---------------------------------
[will work for kudos]
0 Kudos
Message 3 of 11
(3,381 Views)

I am unable to run the attached VI because, apparently, i don't have enough cases to accommodate all my selector values.  I strongly disagree!  I have 4 cases for 4 selector values.  The selector values are 0, 1, 2, 3 and so are my cases.  Please could someone enlighten me as to why this error is flagging up.  It's driving me crazy!

 

 

 

When you use any type of input to a case structure other than an Enum . You must specify a defaut case, just as the help indicates when you click on the run arrow. If you do this it works fine. Just right click on the structure and select make this case default.

 

It is always good to define a default case when using numbers or strings. That way if someone uses your subvi and they accidentally put in a value that you do not anticipate it will know how to handle it, ie throw an error.

 

Hope this helps.




Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 4 of 11
(3,376 Views)

In a situation like this, where you only expect to have 4 real values, it is always better to define a 5th case as the default (perhaps, with a -1 & default).  That case can raise an error.   That way if you wire an invalid piece of data to it through a programming error (such as a 4 or 5, or negative number), an error will occur and alert you.  Otherwise, your default case would run and execute a valid command on the data when it really shouldn't.

 

Since this looks like it is to be used as a subVI, I highly recommend you place an Error In control and Error Out indicator on the front panel and wire them to your connector pane.

Message Edited by Ravens Fan on 05-18-2009 03:11 PM
0 Kudos
Message 5 of 11
(3,373 Views)

Ravens Fan wrote:

Since this looks like it is to be used as a subVI, I highly recommend you place an Error In control and Error Out indicator on the front panel and wire them to your connector pane.


This actually  raises a question i've thought of before, but not yet asked.  Even if a sub-vi has nothing in it that produces an Error cluster, should i still use two of its connectors to wire an Error in and an Error out (connecting them in the BD) despite them just passing the cluster through?

 


Ravens Fan wrote:

In a situation like this, where you only expect to have 4 real values, it is always better to define a 5th case as the default (perhaps, with a -1 & default).  That case can raise an error.   That way if you wire an invalid piece of data to it through a programming error (such as a 4 or 5, or negative number), an error will occur and alert you.  Otherwise, your default case would run and execute a valid command on the data when it really shouldn't.



Dennis Knutson wrote:
You simply have to select one of them as 'Default'. Right click on the case statement and you will see the option at the bottom of the list.

I've left work now, but i expect setting one of them as default should do the trick.  As for creating a separate case to handle unexpected inputs, how would i ensure that it always executed when it should, and not when it shouldn't?  Do you mean that the last case should account for everything below 0, and everything above 3?  Assuming that's right, i've not yet worked out how to make a case execute for all values from a defined number to +/- infinity (whichever direction is required).  Perhaps i've been looking in the wrong place, but i've not found this explained in the help either.



Never say "Oops." Always say "Ah, interesting!"

0 Kudos
Message 6 of 11
(3,357 Views)
Solution
Accepted by JÞB

Exactly,

 

The ring control can optionally allow "undefined values at runtime."  So, the possible values are of type U16 not just 0,1,2,&3.  A bad coersion from a bug or misswire should through a error from the default (undefined value) case.   


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 11
(3,356 Views)

Hi James,

 

"how would i ensure that it always executed when it should"

 

Well, you can set it to "default" as has been mentioned several times before...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 11
(3,347 Views)

James Mamakos wrote:
...

This actually  raises a question i've thought of before, but not yet asked.  Even if a sub-vi has nothing in it that produces an Error cluster, should i still use two of its connectors to wire an Error in and an Error out (connecting them in the BD) despite them just passing the cluster through?

 

...

That is up to you or your employer.

 

Almost all of my sub-VI's use a case structure to trap for previous errors. Although this may seem like over-kill, when I am developing a large application, I want to make sure I detect errors as early as possible to...

1) make trobleshooting the errors easier - since the path between where I had not erro and detected the error has very few elements along the error chain.

2) Kepp my code from being concidered faluty - There is nothing that will break one of my file writting routine than a bad spec of file ref.

3) Dovetailing with the above - enusre that my code is only being called when condition are appropriate - no need to read from the widget if opening a channel to same failed.

 

So with so many error clusters strung together, it becomes more of a problem not passing the error cluster since I would have to rout it around the sub-VI that does not use error clusters.

 

Sure there are exceptions in my code but at least you have another way of looking at error clusters.

 

Ben

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

James Mamakos wrote:

.......

I've left work now, but i expect setting one of them as default should do the trick.  As for creating a separate case to handle unexpected inputs, how would i ensure that it always executed when it should, and not when it shouldn't?  Do you mean that the last case should account for everything below 0, and everything above 3?  Assuming that's right, i've not yet worked out how to make a case execute for all values from a defined number to +/- infinity (whichever direction is required).  Perhaps i've been looking in the wrong place, but i've not found this explained in the help either.


No, you don't understand. A single default case will handle all numeric values that are not currently defined. You've got cases for 0,1,2,3. If you have another case with a value of -1and made that the default, that will handle all values that are less than 0 and all values that are greater than 3. You don't have to use -1. I'm not sure it would make better sense but if you defined a case 4 and made that the default, it too would handle all values less that 0 and all values greater than 3. Sometimes you don't want the default case to throw an error. for example, you might have one case that is normally run and set to default and you would have a couple of special cases.

Message 10 of 11
(3,329 Views)