08-01-2011 01:31 PM
Hello,
I have around 700 text string displays in different tabs in my application which displays some angle values. I am using SetCtrlVal function to display the buffer contents. The problem is, I have 700 displays and I have to use 700 SetCtrlVal functiions to display them. Is any smart way to use one SetCtrlVal function in a while loop with variable constant names for text displays in the function parameter.
thanks,
Sandeep
08-01-2011 03:32 PM - edited 08-01-2011 03:36 PM
If you are using CVI2010 you can benefit from the control arrays facility.
Alternatively, you could create a list of control IDs and use it in a loop:
int ctrls[10];
ctrls[0] = PANEL_CONTROL01;
ctrls[1] = PANEL_CONTROL02;
....
ctrls[9] = PANEL_CONTROL10;
for (i = 0; i < 10; i++) {
sprintf (msg, "%.1f", angle[i]);
SetCtrlVal (panelHandle, ctrls[i], stringArray[i]);
}
The alternative of using SetAttributeForCtrl or SetAttributeForList is not feasible in your case since you are using strings: these commands are powerful but can treat only integer values.
08-01-2011 03:44 PM
Thanks Roberto. That should help.
One more question. I have some logic running which will tell me if the angle value is within a limit say +/- y. I want to color the text with red if the angle is out of limit else will be black. So I will have to use SetCtrlAttribute to change the text color. My question is that whether can I use this function same as SetCtrlVal you mentioned above?
Thanks,
Sandeep
08-01-2011 04:12 PM
Yes, you can. You may have problems if the panel your controls are on is set as "Conform to system colors": in this case the code won't honour SetCtrlAttribute statement but will return no error.
08-01-2011 04:25 PM
Thank you Roberto, I have disabled the "Conform to system colors" and works well. Thanks for the tip.