LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to initialize a case structure to have 10 states quickly

Solved!
Go to solution

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?

0 Kudos
Message 1 of 6
(3,789 Views)

If you are using an enum, there is the right-click option to "Add Case for Every Value".


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 6
(3,786 Views)
Solution
Accepted by topic author EngrStudent

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.all Cases.png

Message 3 of 6
(3,783 Views)

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.

0 Kudos
Message 4 of 6
(3,727 Views)

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

  1. Open a Case Statement and wire an I32 to the selector (just to get it into "numeric" instead of "True/False") mode.  You'll get two cases, 0 (default) and 1.
  2. Do the first two cases.
  3. Right-click and choose "Add Case After".  Presto, a blank Case 2.
  4. Repeat Step 3 as often as needed.

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

0 Kudos
Message 5 of 6
(3,685 Views)

@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.  🙂

0 Kudos
Message 6 of 6
(3,680 Views)