05-15-2025 05:40 AM
Good morning everyone, I premise that I am new to Labview, however, I am working on a project and can't figure out how to use local/global variables. This project contains loops and for, and I need to update a variable in multiple places. For now, I have been using the local variables, calling them in the project, however, conflicts arise as this value is not being updated correctly. I guess this is not the right method, so I kindly ask for your help: I need to update a value multiple times within the same project. Thank you!!!
Translated with DeepL.com (free version)
05-15-2025 05:49 AM
Hi giuli,
@giuli_ wrote:
I am working on a project and can't figure out how to use local/global variables.
You shouldn't need local/global variables at all (or not so often)!
Instead your program should rely on "THINK DATAFLOW", as the wire is the variable!!!
@giuli_ wrote:
This project contains loops and for, and I need to update a variable in multiple places.
For now, I have been using the local variables, calling them in the project, however, conflicts arise as this value is not being updated correctly.
So you try to access local/global variables in parallel from different places in your code and you wonder why you run into race conditions?
That's why I recommend to not use locals/globals at all (or not so often)…
@giuli_ wrote:
I guess this is not the right method, so I kindly ask for your help: I need to update a value multiple times within the same project.
You need to make sure you prevent parallel access to the same resource (aka prevent race conditions)!
You might even show your current code to get more detailed and specific suggestions!
05-15-2025 08:00 AM
If you have multiple loops attempting to update the same local/global variable, you have a major design issue as it points to the loops being broken up too much. You might want to consider combining loops into a single loop.
At a very generic level, you should not be using local or global variables. I would need to know a lot more about your application to make any meaningful suggestions beyond that.
05-15-2025 10:22 AM
@giuli_ wrote:
Good morning everyone, I premise that I am new to Labview, however, I am working on a project and can't figure out how to use local/global variables. This project contains loops and for, and I need to update a variable in multiple places. For now, I have been using the local variables, calling them in the project, however, conflicts arise as this value is not being updated correctly. I guess this is not the right method, so I kindly ask for your help: I need to update a value multiple times within the same project. Thank you!!!
Translated with DeepL.com (free version)
Once you show us your code, we can tell you what you are doing wrong.
Local variables are just secondary taps for front panel elements and the code determines when they get read or written and that is determined by dataflow. For example if the local is before or after the loop, it will only get read before the loop starts or after the loop has finished, respectively.
Local variables should not be confused with "variables" in text based code. Their use is typically limited to UI tasks. In LabVIEW, "the wire is the variable".