LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I increment the label of a control panel?

I would like to place data into several controls in one panel. These controls are labeled CTR_0 through CTR_63 . I would like to use a function like:

int value[64]

for (x=0; x<64; x++)
SetCtrlValue (panelHandle, PANEL_CTR_x, value[x]);

Anyone have an idea short of setting each one on a seperate line?

Any help would be appreciated.
0 Kudos
Message 1 of 6
(3,885 Views)
zener,
with the modification I have made in your function, you can solve your problem. But it works only, if the control IDs of your controls CTR_0 through CTR_63 are in consecutive order. You can achieve this by sorting them in the user interface editor with "edit -> tab order".

int value[64]

for (x=0; x<64; x++)
SetCtrlValue (panelHandle, PANEL_CTR_0 + x, value[x]);
Message 2 of 6
(3,885 Views)
When I have a larger amount of equal controls (e.g. channels), I usually
place only one of the controls into the .uir file, and then build the
remaining controls programmatically in a loop, using the DuplicateCtrl()
function. The advantages are, that I can set (and change) the control
attributes (position, size, label, colors, callbackfunction ... ) only at
one place in the .uir file, and besides I can store the control ids in an
array from where the controls can be easily accessed.

digOutPanel = LoadPanel (0, "DigitalPanel.uir", DIGO_PANEL);

/* buttons for digital outputs */
GetCtrlAttribute (digOutPanel, DIGO_PANEL_SETOUT, ATTR_WIDTH, &width);
GetCtrlAttribute (digOutPanel, DIGO_PANEL_SETOUT, ATTR_LEFT, &left);
digOutSet[0]=DIGO_PANEL_SETOUT;
for(
i = 1; i < MAX_DO; i++)
{
sprintf(buf, "%02d", i);
digOutSet[i] = DuplicateCtrl (digOutPanel, DIGO_PANEL_SETOUT,
digOutPanel, buf, VAL_KEEP_SAME_POSITION, left + (width+2)*i);
}

Regards,
Manfred


zener schrieb in im Newsbeitrag:
50650000000800000026180000-984882144000@quiq.com...
> I would like to place data into several controls in one panel. These
> controls are labeled CTR_0 through CTR_63 . I would like to use a
> function like:
>
> int value[64]
>
> for (x=0; x<64; x++)
> SetCtrlValue (panelHandle, PANEL_CTR_x, value[x]);
>
> Anyone have an idea short of setting each one on a seperate line?
>
> Any help would be appreciated.
0 Kudos
Message 3 of 6
(3,885 Views)
One simple way to do this is to have an array of integers holding the control IDs and using it to access the controls throughout your program.
For example:

int ctl[70]; //Dimension the array at module level or in an include file for all modules

ctl[0] = PANEL_CTR_0; // Fill the array
ctl[1] = PANEL_CTR_1;

for (x=0; x<64; x++)
SetCtrlValue (panelHandle, ctl[x], value[x]);

You could fill the array when starting the program. I put in the array all control IDs I need in my program even if they belong to different panels. Be careful to use the correct array index with respect to the panel, or you will catch a lot of errors (example: if controls for panel1 are loaded from ctl[1] to ctl[10] and controls for panel2 from ctl[20] to ctl[30], if you use SetCtrlV
al (panel1, ctl[20], x) you are most likely to catch an error for invalid type).
Roberto


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?
0 Kudos
Message 4 of 6
(3,885 Views)
I normaly use the following code, to have the array of id's build up:

int ctl_id[] = {PANEL_CTR_0, PANEL_CTR_1...}

If you ad an new control to the panel, you just have to add the new ID.

Stephan
0 Kudos
Message 6 of 6
(3,885 Views)
You have to use an attribute called "ATTR_CST_NAME". That attribute gives the constant name of a control : it's the name you have types inside the panel ( if created with the editor ). After you can scan for the name "CTR_1" ( for example) from ATTR_PANEL_FIRST_CTRL ( panel attribute ) to ATTR_PANEL_FIRST_CTRL + ATTR_PANEL_NUMS_CTRL ( panel attribute ) and compare each constant name with CompareStrings() :

exemple :

int f( int va_hPanel, char *va_psCstName )
{
....
vl_iStat = GetPanelAttribute (va_hPanel, ATTR_NUM_CTRLS, &vl_iCount);
if( vl_iStat!=UIENoError )
goto End_GetCtrlFromCstName;

vl_iFirst=-1;
GetPanelAttribute (va_hPanel, ATTR_PANEL_FIRST_CTRL, &vl_iFirst );
if( vl_iFirst<0 )
goto End_GetCtrlFromCstName;

for( vlr_i1=vl_
iFirst; vlr_i1<=vl_iCount+vl_iFirst; vlr_i1++ )
{

vl_iStat = GetCtrlAttribute( va_hPanel, vlr_i1, ATTR_CONSTANT_NAME, vl_sName );
if( vl_iStat!=UIENoError )
continue;

vl_iStat = CompareStrings (va_psCstName, 0, vl_sName, 0, 0);
if( vl_iStat==0 )
{
// ctrl found
return vlr_i;
}
}

// not found
vlr_i1 = 0;
End_GetCtrlFromCstName:

return vlr_i1;
}
That function returns the control id from it's constant name :
i = f( hPanel, "CTR_2" );

So, you can modify it to do what you what.
0 Kudos
Message 5 of 6
(3,885 Views)