LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

uir header file control's definition value

How doe i control how the UIR header files assigns the control #defines.

I would like to group controls together so i can loop through the group to change its attributes/values. But as i add or remove controls, the values defined for the controls alter as well.
If there is no direct control, can some give me the guidelines that CVI uses when it auto generates the header.

Sample code would be:
for (i = PNL_NUMERIC_8; i < (PNL_NUMERIC_8+20); i++) {
SetCtrlVal(pnl, i, 0);
}

This assumes that PNL_NUMERIC_8 is the start of my group and has 20 members.

Note: Most of the time it will be in order. But as other users edit/rename the UIR and the code, the order sequence of the controls out of place.
0 Kudos
Message 1 of 15
(6,034 Views)
Abui,

You cannot control the numerical values assigned to a #define in a UIR header, but an alternate way to go about it would be to store each of the control values into an array, and loop through the array. For example, a group of 3 controls could be changed like so:

#define NUM_CONTROLS 3
int CtrlArr[NUM_CONTROLS] = {PNL_NUMERIC_1, PNL_NUMERIC_2, PNL_NUMERIC_3}

for ( i = 0; i < NUM_CONTROLS; i++)
{
SetCtrlVal (CtrlArr[i], i, 0);
}
0 Kudos
Message 2 of 15
(6,020 Views)
Don't try to control the conolt values, just store them in an array then operate on the array..
e.g.

int myControls[10];
int i;

myControls[0] = PANEL_NUMERIC;
myControls[1] = PANEL_NUMERIC_2;
myControls[2] = PANEL_NUMERIC_3;
myControls[3] = PANEL_NUMERIC_4;

for (i=0; i <= 3; i++)
SetCtrlVal(panelHandle, i, 0);
0 Kudos
Message 3 of 15
(6,018 Views)
Correction in my original post in this thread, change SetCtrlVal(CtrlArr[i], i, 0) to SetCtrlVal(panel, CtrlArr[i], 0)
0 Kudos
Message 4 of 15
(6,011 Views)
Hi Abui,
I respectfully disagree with Dave and Al. There is a direct correlation between the tab order of each control and the order of the #define in the GUI header file.

Go back to your GUI and set numeric_8 to any tab order number. Then make sure to set numeric_9 one tab order higher than numeric_8. And continue until all of the controls in the desired group of controls have a numeric_8+n tab order. Any developer that follows behind you in adjusting the GUI must make sure that the tab orders remain in order for that specific group of controls. What you did in your sample code will work if you do this.

The tab order is somewhat strange in how it works. If you add a new control to the GUI, it tends to appear at higher tab order numbers but isn't always the highest. I haven't figured out how that works. But I do know that if you select a control, and then copy and paste another one just like it, the new control takes the old control's tab order number and the old control gets bumped up once. This means you will need to reorder the tabs.

The advantage to using the tab order trick is that you can use it all over your code. For example, if you have 8 command buttons, you can set all of their callbacks to be the same, then compare the control number in the callback to the control number of the lowest tab order control:

int CVICALLBACK cx_selectchan (int ai_panel, int ai_control, int ai_event, ...) {
int li_whichButton;

if (EVENT_LEFT_CLICK == ai_event) {
li_whichButton = ai_control - PNL_CB_MYLOWESTTABORDERBUTTONHERE;
...
}
return 0;
}

This makes it especially nice when you are using an array to feed data into the 'array' of controls on the GUI. Of course, they are not an array of controls, but the tab order allows you to address them as if they were. This also keeps you from having to hard code the order of the controls into your code somewhere. If you later add more controls to the gui just make their tab order is higher or lower than those in the group.

Good luck,
Orlan
0 Kudos
Message 5 of 15
(6,006 Views)
Thanks cosmo...the #define is controlled by the tab order. I've tried it before but didnt get it to change. I just realized that you have to save the file before labwindow will regenrate the header.
0 Kudos
Message 6 of 15
(5,971 Views)
While it is absolutely true what cosmo says about the relation between the tab order and the control ID in the .H file, I must disagree with him in suggesting to rely on it. A few years ago I made an application with several panels and several controls on the panels to customize dinamically. I relied on controls order with the mechanism described by Cosmo to build simple and elegant for loops to set attributes... After some months had to maintain the application and make some modifications: it was painful! Simply adding one control on a panel altered all the mechanism; besides it I had to note down on a paper initial and final control for each panel for limiting the for loop (on the panels there were indicators and decorations that didn't need customization), place a note on each panel to remember this particular mechanism...

I then moved to the array approach finding it more user friendly and safe.

Moreover, the possibility to create lists of controls and operate on all controls in the list with one command only simplified the code a lot: look into the toolbox and discover how powerful SetAttributeForList and similar commands are!

Message Edited by Roberto Bozzolo on 05-12-2005 11:12 PM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 7 of 15
(5,933 Views)
There are as many ways to program as there are programmers. Some ways are riskier than others. Some ways appear elegant to the original programmer but are a nightmare to anyone else supporting the code. Some are just a question of style. I agree with Roberto (as usual).
Cosmo is using an undocumented feature of the UI editor. There is no garantee in any future version of CVI that this behavior will be consistent.
Caution flags should go up when you say things like "The tab order is somewhat strange in how it works. .... I haven't figured out how that works."
The tab order of your group of controls can change when you make an edit not even related to your group. So every time you make a UI change, you need to reverify the tab order.
Cosmo says an advantage is the you can use the tab order trick all over your code. That sounds to me like a risk rather than an advantage. If anything goes wrong with your scheme, you now have a lot of places that need to be fixed. If you put the control IDs into a global array, you can use that array anywhere you want.
Cosmo says that using the tab order allows you to address a group of controls as if they were an array. Why not just use an array?
Cosmo has found a method that works well for him and did a good job explaining it. I would just urge caution.
0 Kudos
Message 8 of 15
(5,927 Views)
First, I agree that relying on tab order is risky coding.

I would suggest NI to add a new feature to the tool. "Grouping" controls together like drawing applications to maintain the order of their #defines. That way adding new controls wont accidently get define in the groups sequence.
What do you guys think.
0 Kudos
Message 9 of 15
(5,918 Views)
Wow,
Luckily I keep my flak jacket on hand at all times.

It is not officially 'documented', but the major and minor versions of CVI since 2000 all do it. And maybe they will drop the behavior in 7.1.2, or 7.5.0. But, since we always fully test our old code on the newest CVI RTE and IDE before we deploy it, it's not a problem, right? 😆

The tab order is not some claymore mine pointed at the programmer. If a coworker forgets to add or remove a control from the static array, the behavior might be just as undesirable as a coworker that forgets to recheck the tab order. And I shouldn't send up red flags. The CVI help file on tab order echoes what I said; I simply disagree with the specific reference to adding a new control and it taking (implied always) the highest tab order. I don't know why, but my copy of CVI 7 sometimes does otherwise. That was the reference to 'I don't know...'.

Once the H file is made for a UIR, it is set into concrete until you change--or make CVI think that you have made a change--to the UIR. Simply editing a control or its properties won't affect the tab order. You can always make the control list an array. That should never fail with future versions of CVI. I was simply suggesting that perhaps it could be done (debateably reliably) with the code that was originally written.

Now, if anyone has seen a situation where editing a control or its properties (other than tab order) caused a change to the tab order, please let me know and I will abandon my ship completely and shun the approach as well.

Orlan
0 Kudos
Message 10 of 15
(5,898 Views)