LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using GetControlIndexByName to get Reference

What I want to do:

(Using LabVIEW 2013)

I want to give my SubVI a string.  IE: "Numeric 4"

I want the SubVI to return a reference to the Control named "Numeric 4" on my Front Panel.

What I attempted to do:
ThisVI + SearchString ->  GetControlIndexByName -> ControlIndex
ThisVI -> Panel -> Controls[] ->  ControlRefArray[]

ControlRefArray[ ControlIndex ]  ->  RESULT!

 

Where this went wrong:
It actually worked at first in an isolated Test Scenario.  But then I implemented it into my program and it stopped working.  That's because my program has these controls within TabControls.

What I'd get:

SearchString = "Numeric 4"
ControlIndex = 12
ControlRefArray [] = { Stop, Start, Search String, TabControl }

 

indexing ControlRefArray [ 12 ] would return an invalid reference, since ControlRefArray is only 4 elements.

 

Where I need help:

I'm aware I can, for each ref in Controls[] check the ClassName to see if it's TabControl.  If so,  Pages[] -> Controls[] and contantonate my results and recurse if need be. 


However, I don't know if that will work for all cases.  Is there an easier way to do this? 

And yes, I want a reference so I can Val(Sign) the control.

 

 

I guess the pertinent question is:

What good is "GetControlIndexByName" when its result doesn't even match up with the Controls[] values?  The Help Tip says it can be used for GetControl and SetControl Methods... but I don't see how it does that when you can just use the string.

Thanks

~Andy

0 Kudos
Message 1 of 4
(2,199 Views)

MGI (on VIPM) has a VI called Get VI Control Ref that returns an array of all controls in a VI, including ones located within tab controls.  It returns array of references and array of control names.  Sounds like the perfect solution for you.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 4
(2,187 Views)
You are correct that the problem is the tab control. The best solution is to not use the tab. Do some checking on the forum and you will find that tab controls cause lots of problems.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 3 of 4
(2,182 Views)

@Dyskresiac wrote:

Is there an easier way to do this?

There's a shipping VI which does the traversal for you and has some filtering options (I think only by class, but there might be others). It should be on the scripting palette if you have scripting enabled, but if not, it should be in vi.lib\utility. It's called Traverse for References (or something similar. Search if you can't find it). I don't know if you would consider it easier.

 

 


@Dyskresiac wrote:

What good is "GetControlIndexByName" when its result doesn't even match up with the Controls[] values?


It was designed to allow setting and getting the value quickly when you know the index, not to complement VI server work. That's why it uses an index instead of a reference. As such, the index is related to all the controls on the FP, as opposed to the the Controls[] property. If you want to use it (for instance, if you have a VI where you want to set the value of many controls quickly), you need the get the index separately.


___________________
Try to take over the world!
0 Kudos
Message 4 of 4
(2,142 Views)