LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to find where local variable is defined?

Solved!
Go to solution

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?  

0 Kudos
Message 1 of 11
(259 Views)
Solution
Accepted by topic author colorimeter

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"

 

BowenM_0-1617998350363.png

 

 

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.

 

BowenM_0-1617998504911.png

 

In your case, you're going to be looking for instances of "Write".

 

0 Kudos
Message 2 of 11
(247 Views)

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. 


aputman
LabVIEW 2017
LabVIEW Programming
0 Kudos
Message 3 of 11
(232 Views)

Very helpful for me in understanding what the existing code is doing. Thanks.

0 Kudos
Message 4 of 11
(229 Views)

@aputman, but not all local variables are defined on the front panel, right?

0 Kudos
Message 5 of 11
(227 Views)

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.

Message 6 of 11
(220 Views)

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? 

0 Kudos
Message 7 of 11
(184 Views)

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.  


aputman
LabVIEW 2017
LabVIEW Programming
Message 8 of 11
(168 Views)

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" 

0 Kudos
Message 9 of 11
(164 Views)

@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.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 10 of 11
(119 Views)