LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

if statement

Solved!
Go to solution

This is supposed to be very easy but I can't figure it out. Here's what I wanna do in labview:

 

if (variable == 0){

x = x - 5;

}

else if (variable == 1){

x = x + 5;

}

 

This looks very simple but I'm just not good enough with the whole "graphical programming language" concept.

I'm attaching what I came up with but that seems to keep two different "x"s. Every time I switch "variable" from 0 to 1, x resets to zero; it shouldn't.

 

Any help is appreciated.

0 Kudos
Message 1 of 3
(2,326 Views)

Don't use those hard to read feedback nodes.  They are too confusing.  Use shift registers instead.  Look at the attached vi.  The add function is common to all cases so pull it out.  Use the case to just select the number to be added.  Also put a delay in your main loop to avoid using 100% CPU time.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 3
(2,313 Views)
Solution
Accepted by topic author cartonn30gel

Your problem is that each case has its own feedback node. They don't share data, each one keeps its own history!

 

All you need to do is move the feedback node outside the inner case so it is shared by all cases.

 

(And please put a small wait in the UI loop).

Message 3 of 3
(2,301 Views)