LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

buffer to hold integer value w/sub main vi

I have a main vi that calls several subvi's. I figured out how to parse out the indicator value of the subvi to the main vi - then add this subvi value to a main vi variable, however, when my main vi goes back to call the subvi and when control passes back to the main vi's while loop, the variable is overwritten instead of adding the additional counts via the add x+y operator. How do I keep a static integer value in the main in order to add to have the subvi value added to it?
Thanks
0 Kudos
Message 1 of 2
(2,462 Views)
Sounds like you need to use shift registers.

If your main in running in a while loop, right click somewhere on the while loop, and you'll see a dropdown that includes "add shift register". A shift register is "memory" that takes the last value (register on the right of the while loop) to the next iteration of the loop (left register of the while loop). This will allow you to retain the value you had. Wire the left shift register to your x+y operator, along with your subVI output. Connect the output of the x+y to your main variable. Also wire the output of the x+y to the right shift register.

You'll want to wire a value to the left shift register OUTSIDE of your while loop which will give it an initial value when the while loop runs its first iteratio
n.

You could also do this without shift registers, by wiring your main VI variable into your x+y, along with your subVI, and wiring the output of the x+y back to your main VI variable. While I wouldn't call it bad practice, I generally try to avoid such things because:

1) You have to make sure you initialize your variable to a known value BEFORE your loops start;

2) You have to be careful that no other code is writing to this variable

Mark
0 Kudos
Message 2 of 2
(2,462 Views)