LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I reset the cases for a case structure?

Solved!
Go to solution

Hi, this is a somewhat basic question but difficult to ask effectively. I'm trying to do better programming practice, so I've been trying to use state machines rather than doing the trainwreck I normally do with a massive flat sequence structure and loops and stuff.

 

I get the idea and I've been trying to implement it, but I'm running into some practial problems. I have this enum constant with the different states in it, and when I originally hooked it up to the case selector, I was able to do that "add case for every value" thing that you do with the case structure so that it adds cases for each of the enum values.

 

But then, I wanted to add more values to my enum. That was easy, but now I don't see how to seamlessly add more cases to the case structure... I somehow did something and now there are multiple cases for the same enum value...

 

what's the right way to do this?? thank you.

0 Kudos
Message 1 of 7
(3,487 Views)
Solution
Accepted by topic author optoelectro

Did you make the Enum a Type Defined control (Type Def)?  That should alleviate most issues.

 

Not sure how you managed to get multiple cases for the same enum value.  It should be that if you add values to your enum, you can do the "Add Case For All Values" again.


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 7
(3,474 Views)

You can get multiple cases for the same enum value when you delete items from the enum.

For example, suppose you have an enum with values for "Horse", "Cow", "Pig", and you have a case structure with those three cases.  Now if you delete "Pig" from the enum, the case that used to be "Pig" becomes "Cow".

"If you weren't supposed to push it, it wouldn't be a button."
Message 3 of 7
(3,459 Views)

@crossrulz wrote:

Did you make the Enum a Type Defined control (Type Def)?  That should alleviate most issues.

...


Provided ALL of the enum constants in the diagram are instances of the type def'd enum.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 7
(3,433 Views)

Hmm, so I just made the Enum a Type Def, it wasn't that way before... but what does that do exactly? Sorry, I'm not familiar with it.

 

Hah so I typed out a long reply but in the process of doing that figured it out. So a Type Def seems to be like a class or something, right? That's why I had to save this extra stuff when I saved the file.

 

So there still seems to be a clunkiness when you want to connect a new type def enum thing to the case structure, but I've basically solved my problem by making a new one. Why exactly do we need a type def though?

 

I would like to learn more "proper practice" in labview but ofen the time investment to do that doesn't pay off for a long time, and more pressing needs demand I just do what works, even if it's not very elegant or expandable...

0 Kudos
Message 5 of 7
(3,427 Views)

A type def is a control file that every instance of that data can look to and receive changes from. It does not matter whether that data is in the form of control, indicator, or constant, they can all be linked to the typedef.

 

On the other hand, you can create an enum, and then copy it, but don't make it a typedef. Now, add an item to the first enum, it will not show up in the second enum. This has many implications ranging from "a little annoying" to "there goes my afternoon".

 

Now create an enum and save it in a typedef. Create a copy of that enum. Open the typedef and add an item to it. Save and close the typedef, you will see the change in both enums.

Message 6 of 7
(3,411 Views)

And to reiterate with what Ben mentioned a few messages ago.  If you've already started down the path with enum's that are not typedef.  Make sure you make the enum a typedef.  And make sure you go around and replace all instances of the constants, controls, and indicators with a copy of that typedef enu.  Delete the original, drop a new one!

 

Keep an eye out for coercion dots, the red dots you see at the borders of tunnels and terminals.  You do not ever want to see them on a wire that carries enum values.  If you do, that means somewhere in your code, one of those instances (perhaps one case out of many in a case structure) does not match.  You need to hunt it down and kill.  Do it now so it doesn't kill yours or GregoryJ's afternoon.

 

When you need to create a new enum, it is easiest to make it a typedef right then and there so you don't have to waste time fixing all the copies later on.

Message 7 of 7
(3,406 Views)