LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

using control boxes to control other control boxes

Hello,
 
3 control boxes. I put a number in the 1st control box, it calculates some numbers then setctrlval of the 2nd control box.
I want to input a number in teh 3rd control box, do some calculation have the 3rd control box setctrlval of the 1st control box
and I want to have the 1st control box setctrlval of the 2nd control box based of the new number that was put in the 1st control box
by the 3rd control box.  Is there a way to do this with events or am I going to have to write a separate functions to do this
Thank you.
 
0 Kudos
Message 1 of 3
(2,807 Views)

You can force the execution of a callback using CallCtrlCallback inside another function. So, for example, the callback for your control box 3 can look as the following:

int CVICALLBACK Box3 (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
int  val, newval;

 if (event != EVENT_COMMIT) return 0;

 GetCtrlVal (panel, control, &val);

 // Calculate on "val"

 newval = val + 2;

 SetCtrlVal (panel, PANEL_BOX1, newval);

 CallCtrlCallback (panel, PANEL_BOX1, EVENT_COMMIT, 0, 0, 0);

 return 0;

}

What you must be careful is to avoid racing conditions, that is box3 calls box1 callback that calls box3 callbact that calls box1 callback.... A condition like this will lead you to a stack overflow in a few seconds. If chaining the calls can lead you to a condition like this you must use a flag to stop reciprocal calling in some moment; callbackData parameter can be useful in this case: if you pass a non-null value in this parameter it may mean that the routine is called by another routine instead of invoket on a control's event, sot you may want not to execute some part of the code.
 
Hope this helps
Roberto

Message Edited by Roberto Bozzolo on 01-30-2006 05:22 PM



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?
Message 2 of 3
(2,807 Views)
Roberto
 
Thanks a lot that was what I was look for.
The Call Control Callback worked perfect.
Thank You
0 Kudos
Message 3 of 3
(2,795 Views)