LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case structure help

But how can I write two state names in one false case. Program may freeze to decide which state to run next. Can you give me some example code with your suggested idea. I did not understand quite well.

0 Kudos
Message 11 of 23
(3,417 Views)

Hello,

        Can I use many case structures inside a case structure which are in a while loop. Is that wrong in matters of efficiency.

0 Kudos
Message 12 of 23
(3,388 Views)

Can you post as a snippet?  Not everyone has LV2011 installed, yet.

Or save back to an earlier version such as 8.5 to cover more people.

0 Kudos
Message 13 of 23
(3,383 Views)

Here you can see.

0 Kudos
Message 14 of 23
(3,381 Views)

In general if you have multiple nested structures or several structures in a single while loop you could probably come up with a better architecture. It is not always a question of efficiency. In fact it is possible to write some very obscure code that is more efficient than a standard design pattern. But code should be designed to be read by humans. You might want to do some weird things if they are the most efficient and your VI requires that level of efficiency.

 

You should always put programmer efficiency ahead of program efficiency whenever you can. And by programmer I mean not only the guy writing the code. I am most concerned with the guy reading the code. Always think of his efficiency. The computer does not care one bit about your design pattern.

 

=====================
LabVIEW 2012


0 Kudos
Message 15 of 23
(3,374 Views)

Steve beat me to a similar reply.

 

Yes, you can put nested Case Structures, but why??

I see it often in programs that I am called upon to fix.  Those nested Case Structures (and Stacked Sequence Structures) are the first thing to go (be removed) from the block diagram.  In all situations, a simplified version of the code was written.

 

Can you describe the logic that you are trying to implement and we'll help you avoid becoming a Rube Goldberg candidate..

http://forums.ni.com/t5/BreakPoint/Rube-Goldberg-Code/td-p/399999

 

0 Kudos
Message 16 of 23
(3,373 Views)

I am just using JKI state machine concept but in some situations, I need to use case structure inside a case. So, I just wonder weather I can go in that way or not. After reading your messages, I come to know that I can do that.

0 Kudos
Message 17 of 23
(3,364 Views)

When I have multiple conditions that need to be checked rather than nesting case structures I like to combine them into a Boolean array and convert that to a number. I use this number to select a case within a single case structure however it allows me to use fairly complex combinational logic to drive my decision.

 

Boolean Array For Case Selection.png



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 18 of 23
(3,360 Views)

@shjukheter wrote:

I am just using JKI state machine concept but in some situations, I need to use case structure inside a case. So, I just wonder weather I can go in that way or not. After reading your messages, I come to know that I can do that.


If you have case structures in your states then you might ask yourself the question "do I need to define more states". The answer may very well be no but it is worth asking.

=====================
LabVIEW 2012


0 Kudos
Message 19 of 23
(3,358 Views)

A single case structure within a case is acceptable if need to chose th enext state based on some combination of conditions. Sometimes it is far more readable and maintainable to have that logic in a single case rather than getting overly complex with multiple states that are nearly identical and essentially differ only in which state they trigger next.

 

Now having tons of cases within cases or deep nesting is not a good thing. But there is nothing bad about ising a case structure to chose the next state.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 20 of 23
(3,353 Views)