05-11-2011 04:37 PM
Hi,
I am trying to update the value of a control on one panel when the value of another control on a different panel is changed. The two panels are saved in two different .uir files, so there are two associated .h files generated by CVI. The problem is that, inside the callback function for the control that is being modified (Ctrl_Id_A on Panel_A), when I call SetCtrlVal(Panel_B, Ctrl_Id_B, Value); 'Panel_B' and 'Ctrl_Id_B' (which have the same numeric values as Panel_A = 1 and Ctrl_Id_A = 2 in their respective .h files) are being interpreted as Panel_A and Ctrl_Id_A. I never understood how CVI makes this distinction, eg. knowing which of PANEL_A = 1 and PANEL_B = 1 is being referred to, but didn't worry about it since I never needed cross-communication between panels until now. Any help on how to implement this would be greatly appreciated. Thanks!
Solved! Go to Solution.
05-12-2011 12:27 AM
This is a basic issue on which you can find tons of forum posts
The online help for the function recitates:
int SetCtrlVal (int panelHandle, int controlID, ...);
Parameters
Input | ||
Name | Type | Description |
panelHandle | int | Specifier for a particular panel that is currently in memory. You obtain this handle from LoadPanel, NewPanel, or DuplicatePanel. |
controlID | int | The defined constant, located in the .uir header file, that you assigned to the control in the User Interface Editor, or the ID returned by NewCtrl or DuplicateCtrl. |
value | ... | New value of the control. The data type of value must match the data type of the control. |
That is, you must not use the panel constant name in the first parameter of SetCtrlVal, use the panel handle instead. The system guarantees that all panel handles are unique throughout the whole application whichever is the number of panels used in every moment.
int SetCtrlVal (int panelHandle, int controlID, ...);
Sets the value of a control to a value you specify.
When you call SetCtrlVal on a list box or a ring control, SetCtrlVal sets the current list item to the first item that has the value you specify. To set the current list item through a zero-based index, use SetCtrlIndex.
When you call SetCtrlVal on a text box, SetCtrlVal appends value to the contents of the text box and scrolls the text box to display value. Use ResetTextBox to replace the contents of the text box with value.
Note This function updates the displayed value immediately. Use SetCtrlAttribute with ATTR_CTRL_VAL to set the control value without immediately updating the displayed value. For this reason, SetCtrlAttribute with ATTR_CTRL_VAL is generally faster than SetCtrlVal. However, if the control in which you are setting the value is the active control in the panel, SetCtrlAttribute with ATTR_CTRL_VAL displays the value immediately. |
Note This function is not valid for graph and strip chart controls. |
Input | ||
Name | Type | Description |
panelHandle | int | Specifier for a particular panel that is currently in memory. You obtain this handle from LoadPanel, NewPanel, or DuplicatePanel. |
controlID | int | The defined constant, located in the .uir header file, that you assigned to the control in the User Interface Editor, or the ID returned by NewCtrl or DuplicateCtrl. |
value | ... | New value of the control. The data type of value must match the data type of the control. |
05-12-2011 06:07 AM - edited 05-12-2011 06:07 AM
For your reference, in this discussion I give some concepts on how panels and controls are addressed.
Additional useful forum discussions can be found here : it's the list of results of a forum search for "panel handle constant name": there you can find several useful posts that you may want to read to better understand panel handle concepts.
05-13-2011 12:04 PM
Thank you!