LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

I want to set the value of multiple checkbox's in a for loop.

Can I do something like this?
for(i = 0; i < maxCheckBoxes; i++)
{
sprintf(tempBuff, "PANEL_CHECKBOX%d", i);
setctrlval ( panelHandle, (int)tempBuff, TRUE);
}
0 Kudos
Message 1 of 4
(3,499 Views)
SetCtrlVal() is looking for an integer which it will look up in the constants defined in the UIR .h file. Casting a string as an int doesn't look at the string as a symbol or constant name; it casts the ASCII string as an integer.
One way to set values of controls in a loop is to build an array of the constant names. It's an int array containing the values of the control constants (by constant name), not a string array containing the names. Make sure you use the control constant names, not their value from the UIR .h file: CVI can change those values anytime you edit the UIR file. For example, if your panel constant is PANEL and you have 5 checkboxes CHECKBOX_1 through CHECKBOX_5, your array difinition could be
int nCheckBoxes[] =
{PANEL_CHECKBOX_1,
PANE
L_CHECKBOX_2,
PANEL_CHECKBOX_3,
PANEL_CHECKBOX_4,
PANEL_CHECKBOX_5};

#define NUMCHECKBOXES sizeof(nCheckBoxes) / sizeof(int)
...
int main(int argc, char *argv[])
{
...
}

int SetAllHigh()
{
int i;
for (i=0; i nCheckBoxes[i] = 1;
}

See the attached example for more details.
Message 2 of 4
(3,499 Views)
Thank you, that was very helpful and you were quick to answer.
0 Kudos
Message 3 of 4
(3,499 Views)
Thanks for the thanks (I mean you're welcome). It was a fun little question.
0 Kudos
Message 4 of 4
(3,499 Views)