05-14-2010 04:39 PM
I was looking at the controls[] property of a panel and wanted to use it to create an array of control refs that I could easily pass to subVIs from the main menu. A problem exists in that my main menu uses a tab control with nested tab controls on one of its pages which complicates things in this arena. My program is an event structure based main program that calls subVIs for each event activation, usually a changevalue event from a button.
How do you use the controls property in this case to create a functioning program with the event handler? The controls property of the main panel only gives you those in the panel and not in the containers such as the tab controls.
What is the commonly used approach here?
05-14-2010 05:52 PM
Here is a vi that does part of the job. It gets all controls' names, and all controls of each page of a tab control. You need to go one step further to get the controls on the tab within a tab. To do nested tabs, you would have to check the control type, and if it is a tab control, get its items. This may be a job for a recursive function. The vi is written in LV2009. At least its a start to show how to get controls on a tab.
05-15-2010 08:01 PM
thanks tbob
I have this part done already and am trying to figure out how to do a nested recursion on this exact thing and how to organize the list so that I can later easily recall the refs to controls from within subVIs.
05-17-2010 08:16 AM
I think I can offer two ideas that will help you figure out how yo u want to adress this challenge.
1) Bundle the refs you want explicitly as shown in this image.
After bundling I check to enusre all of the refs are valid (not shown, cluster to array Is ref num).
Yes you have to wire them all yourslef but there a tricks to make that easier.
Benefit: If you move a control from one tab to another, the above does not need to be changed.
In this Nugget I talk about using ccontrol refs and finding refs within refs. THe included sample code...
Will demonstarte usinga single cluster what you may have to go through to get at the refs on the FP. I would be suprised if you used that code "as-is" but it does demontrate the challenge.
Have fun,
Ben
05-17-2010 11:09 AM
AAAIIIIEEEEE!!! My lazy butt is aching after seeing Ben's code. However, it is organized by tab controls while my method would only give a complete list with no organization as to which control belongs to which tab. Id, I wouldn't want to have to make this choice.
05-17-2010 11:52 AM
tbob wrote:AAAIIIIEEEEE!!! My lazy butt is aching after seeing Ben's code. However, it is organized by tab controls while my method would only give a complete list with no organization as to which control belongs to which tab. Id, I wouldn't want to have to make this choice.
Sorry tbob but I can only reply by teasing with the re-use code one of my co-workers wrote.
After getting fed-up with the above two options, he wrote an XControl that once dropped on any FP will create and maintain an Action Engine that has refs to all FP object on all FPs. The enum is populated with a "VIName_ControlName" format to easily choose any FP object from anywhere in the app. So all he has to do is drop the AE,pop-up to create the enum and then choose the ref he wants.
No not allowed to post that code. So you could always duplicate his stuff and never have to wire a ref down again.
Ben
05-17-2010 12:11 PM
If it were me, I would use this gem hidden in vi.lib (with the usual caveats, subject to change by NI, make personal copies, etc).
05-17-2010 12:19 PM
Now why won't NI publicize all of these hidden special VIs? They could be of great use to a lot of programmers. How many other very useful functions lie hidden in vi.lib? How about a weekly nugget to feature a new hidden vi.lib function?
05-17-2010 12:28 PM
05-17-2010 12:32 PM
id wrote:
Thats exactly what I was looking for. I cant seem to find it in my C;\prog files\NI\vi.lib directory though.
On my system it is here:
C:\Program Files\National Instruments\LabVIEW 2009\vi.lib\Utility\traverseref.llb\TRef Get All FP References.vi