LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to increment/count in LabView

Guys,

Could someone give me example code as to how to increment a variable through each iteration of a loop.  For example, I want the first iteration of the loop to output a 0 and then  the next iteration output 1, and then the next iteration output 2 and so on and so forth and go on for like this for let's say 50 iterations.  The last number would be 49.  Thanks.

Andy
0 Kudos
Message 1 of 18
(50,163 Views)
I may not just want to add 1 to it the entire time either....sometime I may want to add a decimal constant to 0.  So that the first iteration outputs a 0 and then the next iteration outputs a 0.5....I added this b/c I'm not sure if this will add to the complexity of the code or not.  Thanks for anyone's help.
0 Kudos
Message 2 of 18
(50,157 Views)
I don't know if you are looking for something as simple as this, but here is a couple of things you could to achive an incramental value (just put 50 in the ctrl.. or wire a constant of 50 to the N in the for loop).

*edit*

didn't see your second post. Instead of the +1 inc primative you can simply use an add primative (multiply, or any calculation you want).
The shift register is the key. (The left tunnel has the value you wired to the right tunnel of the shfit register the previous iteration, and starts with the value wried from outside the loop the first iteration. Note: see the help for more details on how shift registers work)

Message Edited by Lorenz03Tx on 05-09-2006 11:24 AM

0 Kudos
Message 3 of 18
(50,159 Views)
Hey bud,

Is there anyways you can send me a .vi with that code you just showed me on the .jpg but with it adding 0.5 instead of 1.  Thanks
0 Kudos
Message 4 of 18
(50,145 Views)
You need to use the "double" variable type, as the type in the image is integer. See the image attached.

Message Edited by Novatron on 05-09-2006 01:04 PM

0 Kudos
Message 5 of 18
(50,136 Views)

I want to do the same, but there is no such thing as a double variable type in my palete. I can only choose constant and this doesn't work. Can anyone send me a VI with the double variable in it?

0 Kudos
Message 6 of 18
(49,498 Views)

Right-click it, representation, DBL.

0 Kudos
Message 7 of 18
(49,496 Views)

The problem is, I cannot create variables at all! Where are they in the palete? I can only make local variables related to front panel objects, can't make numerical variables other than controls or indicators, but these don't work (can only read or write).

 

I can create a constant and then make a shift register in the loop and remove the constant and then it works, but to reset the count I have to put the constant back and re run the VI so it goes back to 1.

0 Kudos
Message 8 of 18
(49,484 Views)
What you are looking for is a wire. Those things called variables related to controls and indicators are really functions for the controls and indicators.
=====================
LabVIEW 2012


0 Kudos
Message 9 of 18
(49,477 Views)
Grr. Getting used to the mobile interface and wasn't done. Your shift register is uninitialized. Wire a constant to the left side of the shift register outside of the loop.
=====================
LabVIEW 2012


0 Kudos
Message 10 of 18
(49,474 Views)