LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with Case Structures

Solved!
Go to solution

I'm having trouble switching between the true and false case between case structures. I'm trying to write a VI that generates a random number between 0 and 10 once every 0.5 seconds, and then adds the numbers together until the running sum reaches or exceeds 100. At that point it should start to subtract the randomly generated numbers until it reaches 0, then switch to adding them again etc.

 

I am having trouble switching to the 'false' case once the sum excedes 100. If anyone can help with this that would be awesome!

0 Kudos
Message 1 of 10
(3,380 Views)

Move the comparison outside the case structure.

 

Lynn

0 Kudos
Message 2 of 10
(3,363 Views)

Use another shift register to hold which way you are going.  A simple Boolean should work.

 

The generation of the random number should be outside of the case structure (since you are doing that regardless).  But the add/subtract and the comparison to see if you need to switch states should be inside of the case structure.

 

You should also just use 0 to initialize your shift register that holds your current total.  Makes things a little simpler.


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 3 of 10
(3,348 Views)

Thank you for your input so far. My biggest problem is with the Boolean, as I am inexperienced in that area. Can you please elaborate on how adding another shift register helps?

 

Thanks.

0 Kudos
Message 4 of 10
(3,331 Views)
Solution
Accepted by Valsae
To make things simpler exchange the Boolean for an enumeration with only two values that you can call "Count Up" and "Count Down".

Create a second shift register to hold the enumerated value specifying whether to "Count Up" or "Count Down". Initialize the new shift register to count up and in the "Count Up" case in the case structure, increment the data value and the test to see if it is greater than 100. If it's not, don't change the value in the count direction shift register. If the data has exceeded the limit, change the values in the count direction shift register to "Count Down".

In the "Count Down" case, decrement the data value and test for a value less than 0. When the data value drops below the lower limit, change the values in the count direction shift register to "Count Up" and you are done.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 5 of 10
(3,286 Views)

You see, one shift register holds the data, and the other the direction to count on the next iteration. This structure is a very, very simple state machine.

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 6 of 10
(3,283 Views)

 

I don't quite understand your first statement. You suggest that I put an enumeration with respective values for  "Count Up" or "Count Down" respectively inside the case structure? I'm also not quite sure how to test to see if it's greater than 100 or less than 0. I understand that I use a comparison here, but what do I wire it up to?

 

Thank you for all your help so far.

0 Kudos
Message 7 of 10
(3,256 Views)
Simplest is to wire the output of the comparison to a Select function. One input of the Select is the Count Up enum and the other input is the Count Down. The output of course gets wired out to the shift register.
0 Kudos
Message 8 of 10
(3,235 Views)

@Valsae wrote:

I don't quite understand your first statement. You suggest that I put an enumeration with respective values for  "Count Up" or "Count Down" respectively inside the case structure?


You use the enum for the selector of the case structure.  You can then use the shift register to tell the next iteration what to do.


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
0 Kudos
Message 9 of 10
(3,211 Views)
You really need to go through the online tutorials. You are asking some very basic questions that are better handled through training.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 10 of 10
(3,174 Views)