LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to increment/count in LabView


@MadScientist wrote:

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.



Hey MadScientist.

 

Variables are implicitly created when you instanciate a front panel object. You can reference these objects as variables by right clicking on the object reference and selecting Create > Local Variable. If you didn't want this local variable to be shown on the front panel, i.e. you only want to use it for code control, you can right click on the front panel object for the variable and select Advanced > Hide Indicator.

 

However, the use of local variables in LabVIEW are generally regarded as bad programming practice as they contravene Dataflow; you have to remember you need to program differently when you're programming in LabVIEW as to how you would in a text based language. Many situations where you'd want to make use of a local variable you could actually avoid through proper use of dataflow!

 


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

0 Kudos
Message 11 of 18
(10,477 Views)

I tried everything I can think of, including placing the constants and variables in diffferent locations (outside loops, outside the main program loop, in arrays etc..) and nothing has worked - all of these cause the original value to be read instead of adding 1 to the value and incrementing it each time. Do I need to write to an array and read the new value from a separate array or something? This is so easy to do in C++, it's one of the fundamentals - it's not even funny how difficult it is to do in Labview.

0 Kudos
Message 12 of 18
(10,458 Views)

Almost inevitably it isn't difficult to do in LabVIEW!

See below: One of these increments a constant by a given number of times, the other increments the value from a control.

You can operate within the for loop to access the number as it is incremented, or on the output(s) to use the final value.

increment.png

 

 

0 Kudos
Message 13 of 18
(10,456 Views)

here is the code for counter up and down with increment of 1

0 Kudos
Message 14 of 18
(2,859 Views)

AT LAST! 😀😀😀

 

I've been waiting 10 years for this!  Now I can finally increment a variable in LabVI... .. .

 

Oh crap.  It's in LabVIEW 2020 and I'm using 2019.  Well, maybe next year...

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
Message 15 of 18
(2,855 Views)

@MadScientist wrote:

I tried everything I can think of, including placing the constants and variables in diffferent locations (outside loops, outside the main program loop, in arrays etc..) and nothing has worked - all of these cause the original value to be read instead of adding 1 to the value and incrementing it each time. Do I need to write to an array and read the new value from a separate array or something? This is so easy to do in C++, it's one of the fundamentals - it's not even funny how difficult it is to do in Labview.


Can you show your code? This is so easy to do in LabVIEW, it's one of the fundamentals - it's not even funny how difficult it would be to do in C++. Have you looked at any of the training materials at the top of this forum? What are these "variables" that you say that you are placing? The variable is the wire in LabVIEW. There is no "variable type" either. A wire will have a datatype based upon the connected data. For instance, if you put a numeric constant on the block diagram it will initially have a I32 representation. If you want to change it to DBL then you right click on it, select representation, then select DBL. The constant and the wire will change to DBL.

 

Here is a picture of how easy it is to accomplish. I intentionally made it a picture so that you would have to reproduce it yourself. I also ran it with some sample data and have shown some results. 

 

johntrich1971_0-1626957989440.png

johntrich1971_1-1626958018489.png

 

0 Kudos
Message 16 of 18
(2,829 Views)

Just FYI John: rwajahat was responding to a post that is 10 years old.  And yes, you are right that this is LabVIEW 101 and any tutorial would explain how it's done.  Hopefully MadScientist has it figured out by now. 🤓

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 17 of 18
(2,816 Views)

@NIquist wrote:

Just FYI John: rwajahat was responding to a post that is 10 years old.  And yes, you are right that this is LabVIEW 101 and any tutorial would explain how it's done.  Hopefully MadScientist has it figured out by now. 🤓


Oops, didn't notice that. 🤣

Message 18 of 18
(2,813 Views)