From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
04-09-2021 02:44 PM
I am a beginner trying to understand a complex set of existing LabVIEW code, which includes local variables. I know how to use Find to search the block diagram for instances of a local variable such as SomeNumber. However I would like to see where the local variable is defined, like SomeNumber=7. How can I search for this?
Solved! Go to Solution.
04-09-2021 03:01 PM - edited 04-09-2021 03:01 PM
I'm going to start with the standard admonition that local variables should almost never be used. There are some uses for them, but "defining" a value is almost always incorrect.
Now, to your question: You can right click on the control or indicator on either the front panel or the block diagram and select "Find -> Local Variables"
From there, it will bring up a dialog box showing you all of the local variables, and whether or not they read or write. You can then double click or slick and select "Go To" and it will highlight that local variable on your block diagram.
In your case, you're going to be looking for instances of "Write".
04-09-2021 03:11 PM
Or you can right click the local variable and click Find -> Control (or Terminal) to find the front panel control that defines the local variable.
04-09-2021 03:11 PM
Very helpful for me in understanding what the existing code is doing. Thanks.
04-09-2021 03:12 PM
@aputman, but not all local variables are defined on the front panel, right?
04-09-2021 03:18 PM
A local variable is just another way of accessing the data that is a control or indicator on the front panel besides its block diagram terminal.
There is no such thing as a local variable without a front panel entity attached to it.
04-09-2021 04:13 PM - edited 04-09-2021 04:14 PM
In the code I'm looking at, it seems like there are instances where a string is assigned to a local variable within the block diagram. But the local variable is ultimately used to display the string as a status update on the front panel. Does that still count as a front panel connection?
04-09-2021 04:32 PM
The local variable does not display anything on the front panel, in and of itself. It can't exist on it's own without linkage to a front panel object. Period. The "status update" on the front panel is a string control/indicator and the local variable is derived from that object. It's a way to write to the front panel object from multiple locations. The use of the term variable in "local variable" is probably a bit unfortunate because it gives people the impression that it is used to store a value. That mindset almost always leads to bad coding practices, race conditions, etc. The use case that you detail, at least as I understand it, as a status indicator, is a good use case for local variables. That doesn't mean there isn't a better method but I imagine it works just fine.
04-09-2021 04:43 PM
Yes to this: "The use of the term variable in "local variable" is probably a bit unfortunate because it gives people the impression that it is used to store a value"
04-10-2021 05:12 AM
@colorimeter wrote:
Yes to this: "The use of the term variable in "local variable" is probably a bit unfortunate because it gives people the impression that it is used to store a value"
I think NI recognized this, because in LV NXG, they did away with local variables (in name, at least). Duplicate terminals were the NXG equivalent.