10-07-2011 10:17 AM
Hello,
I want to read more textbox using a For loop. My problem is that the names of Textbox are defined (#define...) and I can not move the counter in the call of GetCtrlVal.
Ex:
for(i=0;i<50;i++)
{
GetCtrlVal(panelHandle,Constant_Name_Of_Textbox_With_i; val);
}
I can not really achieve this by using several ways. Thank you for a method to correct my problem.
Thanks
Solved! Go to Solution.
10-07-2011 10:40 AM
Hi,
1) If you happen to use LabWindows/CVI 2010 you can use arrays of User Interface controls, see https://decibel.ni.com/content/docs/DOC-14829
2) You can also create your controls programmatically, allowing indexed control ids.
3) And you can also assign your control array manually, such as control_id [ 50 ] = { constant_textbox_1, ...}
10-07-2011 11:43 AM - edited 10-07-2011 11:44 AM
Another option is to use GetCtrlAttribute with the ATTR_CTRL_STYLE and check to see whether the control is a textbox or not. Instead of blindly looping through the controls you can also get the first control ID by using GetPanelAttribute with the ATTR_PANEL_FIRST_CTRL attribute to get the first control, and then GetCtrlAttribute with ATTR_NEXT_CTRL to get the next control. I would probably do something like this:
GetPanelAttribute (panel, ATTR_PANEL_FIRST_CTRL, &control_id);
while(control_id > 0)
{
GetCtrlAttribute (panel, control_id, ATTR_CTRL_STYLE, &control_style);
if(control_style == CTRL_TEXT_BOX_LS || control_style == CTRL_TEXT_BOX)
{
//things to be done with the textbox controls
}
GetCtrlAttribute (panel, control_id, ATTR_NEXT_CTRL, &control_id);
};
Hope this helps.
10-08-2011 06:08 AM
Thanks for your response
I will test your methods and i send the results.
Thanks
10-09-2011 02:59 AM - edited 10-09-2011 03:01 AM
Hi,
i use another method, it is not so universal like one from tstanley,but it is more straightforward for me.
const int UI_ControlArray[50]=
{Constant_Name_Of_Textbox_1,
Constant_Name_Of_Textbox_1,
Constant_Name_Of_AnotherTextBoxt,
...
};
...
for(i=0;i<50;i++)
{
GetCtrlVal(panelHandle,UI_ControlArray[i]; val);
}
This method can be easily modified to use struct (in array) for access multiple controls in each cykle.
Edit: i later see that Wolfgang mention this way already, so this is just example 🙂
10-10-2011 07:27 AM
Hi,
I use the first method (ControlArray) :
for (int i=0; i<3;i++)
{
GetCtrlVal(panelHandle, GetCtrlArrayItem(ctrlarray,i), val);
....
}
Thank you for your help