01-04-2017 12:45 PM
I am making a vi where I have a case structure with 10 cases. Instead of manually (via mouse) adding the 8 missing states, is there a way to add a sequence of them quickly?
Solved! Go to Solution.
01-04-2017 12:50 PM
If you are using an enum, there is the right-click option to "Add Case for Every Value".
01-04-2017 12:53 PM - edited 01-04-2017 12:58 PM
If you use an enum and create all states you can right click and add cases for every value. It is also usefull to pass any tunnels through from an unused case. So you do not have to connect all tunnels each time. Use duplicate case.
01-04-2017 02:01 PM
One note is to make sure indexing is correct. LabVIEW starts at zero, so if the inputs are to be numbers then make sure your counting starts in the right place.
01-05-2017 07:00 AM
I think you "don't get it". If you want your Case Statement to be a small set of sequential numbers starting from 0, then
A "smarter" way to do a fixed subset of cases (say, 8 Cases) is to define an Enum (as has been suggested). The beauty of an Enum is that you can assign "User-meaningful Labels" that will (under the hood) be represented as sequential integers starting from 0. So if you wanted, for example, Days of the Week, you could code up 0 through 6 (or 1 through 7, with Default being "This number is not legal"), but you could also make an Enum of "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" (you could even do Dimanche, Lundi, Mardi, Mercredi, ..., which may be more meaningful to you), which is much more mnemonic.
Bob Schor
Bob Schor
01-05-2017 07:04 AM - edited 01-05-2017 07:06 AM
@Bob_Schor - I got it. I used the enum. I don't need a fancy label, I needed to be fast to get the job done. I'm from the MatLab world so I think starting at 1, not 0, and I made a mistake, and then figured out what I did wrong. I ended up needing 20 cases and I numbered them from 1 to 20. When I wrapped it in the for loop, it was indexing from 0 to 19, and that confused me because element 20 became element 0.
I wanted to share the mistake, so that others could spend 10 seconds reading the thread and not spend 5 minutes figuring out their mistake - to make them more productive.
Happy Thursday. 🙂