08-24-2010 06:24 AM
Is there anyway that a subVI can reference the controls on a parent VI's Front panel? Without this ability it is hard to reduce the complexity of a VI by using subVIs when a front panel control is involved. Variable Property Nodes do not appear to have the ability to reference a control in a parent VI. Is there any way to solve this?
Solved! Go to Solution.
08-24-2010 06:33 AM
There are two ways to do this:
1. Use the connector pane to give the control reference to the subVI.
2. Open a VI reference to the parent VI or get the reference through the connector pane. Use the Property node VI:Controls[] to get the references to all controls. You must use a loop to get the right control by checking the label. AFAIK the sequence is in tabbing order so you can use an index.
08-24-2010 06:38 AM
Can you so me a sample of #2?
08-24-2010 07:05 AM
This evening (GMT+2), which LV version?
08-24-2010 08:30 AM
You can use the OpenG function 'Current VIs Parents Ref' which returns the VI that calls this VI to create the following code:
Ton
08-24-2010 11:08 AM
Ton provided the code you need.
Instead of the OpenG function you can use Open VI Reference from the Application control palette.
Be aware that you must use the full qualified VI name if the VI is part of a LV library, e. g. MyLibrary:MyVI.vi.
08-24-2010 11:33 AM
or rather than use the OPEN VI Reference, you can set a static property node in the parent VI and pass that VI reference easy and done...
But if the parent VI is already in memory, you need only the VI name (string input) rather than a fully qualified path (path input)
Advantage to the first method I proposed, it works if the VI is not saved, a clone, etc.
08-24-2010 11:38 AM
Generally speaking I tend to "push" the reference down into the sub-VI rather than make it "reach up" to get it. By pushing it dwon I can redirect the functionality at a new control without mods to the sub-VI. By "reaching up" the sub-VI has to be modified to look for other widgets or even if the customer points out a typo in the control name.
just my 2 cents worth,
Ben
08-24-2010 01:28 PM
@Ben wrote:
Generally speaking I tend to "push" the reference down into the sub-VI rather than make it "reach up" to get it. By pushing it dwon I can redirect the functionality at a new control without mods to the sub-VI. By "reaching up" the sub-VI has to be modified to look for other widgets or even if the customer points out a typo in the control name.
just my 2 cents worth,
Ben
I agree with Ben. Here is an example of how I usually do this. The main vi passes a reference to the subvi, who then sets the value of the reference.
Save both to same folder. When opening Main, it will look for Subvi. Just point to it.
08-24-2010 04:27 PM
I will try your suggestion.