07-21-2011 09:00 AM
@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!
07-22-2011 03:39 AM
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.
07-22-2011 03:47 AM
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.
07-21-2021 03:00 PM
here is the code for counter up and down with increment of 1
07-21-2021 03:22 PM
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...
07-22-2021 07:48 AM
@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.
07-22-2021 09:10 AM
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. 🤓
07-22-2021 09:21 AM
@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. 🤣