05-18-2009 01:48 PM - edited 05-18-2009 01:54 PM
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
Solved! Go to Solution.
05-18-2009 01:57 PM
05-18-2009 02:04 PM
05-18-2009 02:09 PM
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.
05-18-2009 02:10 PM - edited 05-18-2009 02:11 PM
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.
05-18-2009 02:43 PM
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.
05-18-2009 02:45 PM
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.
05-18-2009 03:03 PM
05-18-2009 03:06 PM
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
05-18-2009 03:15 PM
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.