Need Help With Case Statemet

In our teams code we have four case statements inside of each other and as a programmer I know that that is not ideal. I was wondering if anyone could help me solve this issue. We use Global Variables but do any of you know a way to make it so we don’t have it like this.





What are you trying to get to happen here?

If all your case statements are true/false only, and the actions inside are just setting one output, you might do better using a combination of Select blocks (the labview equivalent of an if/then/else) and appropriate boolean operators to get a final result.

Alternately, you could use a series of select blocks to choose a named state (using an ENUM value) that you feed to one case statement to pick the final result.

This is for our collector. With the collector we would find the tote getting caught on one side and we would not really be able to get the tote unstuck quickly. So we made it so that one collector wheel would move forward and the other one would spin backwards. So the code is making it do that but there needs to be a better solution then that. it was a quick fix at a competition that we were going to solve sooner but never got to it. and I don’t know how to fix it

My first suggestion would be to select the loop containing the logic and click the cleanup button on the toolbar. It is the one with the small broom on it. That way we will be able to se how the logic and variables are attached.

In the attached image, I show three alternate ways to combine the logic and select values. i generally use one of the top two. If it is not only values that are changing, but alternate code, I’ll use something more like the bottom one.

By the way, the most important thing is that the code makes sense to you and works correctly. These alternate ways of writing it are suggestions, but be sure you understand them before redoing anything.

I like to do this by writing the code in parallel, right next to the existing code. Then you can look at the old and new side-be-side and reason about it. You can review a truth table, sketch a graph, or whatever helps you to understand it and prove that the old and new code work the same. You can even leave most of the old and new code in, run them and compare the results as you run code.

Greg McKaskle





Thank you guys. I figured it out. I posted a photo of how I fixed it.