LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how can I realize this function?

dear sir:
My program need this kind of function:
There are two radio buttons and a check box on a panel,when I
check radio button1 and check box,I write 1 to Enable_1(a variable),if
check box is unchecked ,I write 0 to Enable_1. then I check radio
button2,the status of the
check box should be unchecked. If i check it(check box)I write 1 to
Enable_2(another variable),otherwise write 0 to Enable_2.
And now I check radio button1,check box should be former
status.accordingly if I check radio button2,check box alse should be
former status.
Who can help me to correct my program?
Thanks!
#include /* Needed if linking in external compiler;
harmless otherwise */
#include
#include "check.h"
static int panelHandle;
int
Enable_1,Enable_2;
int Enable_3,Enable_4;
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0) /* Needed if linking in external
compiler; harmless otherwise */
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "check.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
return 0;
}


int CVICALLBACK Choose (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:

switch(control)
{
case PANEL_RADIOBUTTON_1:
SetCtrlVal(panel,PANEL_CHECKBOX,Enable_1);
DefaultCtrl(panel,PANEL_RADIOBUTTON_2) ;
break;
case PANEL_RADIOBUTTON_2:
SetCtrlVal(panel,PANEL_CHECKBOX,Enable_2);
DefaultCtrl(panel,PANEL_RADIOBUTTON_1) ;
break;

}

break;
}
return 0;
}

int CVICALLBACK close (int panel, int
control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface(0);
break;
}
return 0;
}
0 Kudos
Message 1 of 3
(3,256 Views)
Hi Tyro,
if I've understood this correctly, the answer is to have a callback for the radio buttons that only gives you the exclusivity (only one radio button at a time working) and updates the checkbox with the current value of Enable_1 or Enable_2 as appropriate. You then use a callback for the checkbox to find out which radio button is pressed, and then write this to the Enable_1 or Enable_2 as appropriate.
I've created an example (CVI 6.0)

Hope that helps (also done the code snippet below just in case)

S.

int CVICALLBACK CheckBoxCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int radio_1 = 0;
int radio_2 = 0;
int checkbox = 0;
switch (event)
{
case EVENT_COMMIT:
{
GetCtrlAttribute (panel, PANEL_RADIOBUTTON_1, ATTR_CTRL_VAL, &radio_1);
GetCtrlAttribute (panel, PANEL_RADIOBUTTON_2, ATTR_CTRL_VAL, &radio_2);
GetCtrlAttribute (panel, PANEL_CHECKBOX, ATTR_CTRL_VAL, &checkbox);
if (radio_1==1)
{
Enable_1 = checkbox;
}
if (radio_2==1)
{
Enable_2 = checkbox;
}
}
break;
}
return 0;
}

int CVICALLBACK RadioButtonCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
{
switch(control)
{
case PANEL_RADIOBUTTON_1:
{ // make sure we've de-selected the old control
SetCtrlAttribute (panel, PANEL_RADIOBUTTON_2, ATTR_CTRL_VAL, 0);
SetCtrlAttribute (panel, PANEL_CHECKBOX, ATTR_CTRL_VAL, Enable_1);
}
break;
case PANEL_RADIOBUTTON_2:
{ // make sure we've de-selected the old control
SetCtrlAttribute (panel, PANEL_RADIOBUTTON_1, ATTR_CTRL_VAL, 0);
SetCtrlAttribute (panel, PANEL_CHECKBOX, ATTR_CTRL_VAL, Enable_2);
}
break;
}
}
break;
}
return 0;
}
// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 2 of 3
(3,256 Views)
thanks for everyone who saw this message,i have solved it.
0 Kudos
Message 3 of 3
(3,256 Views)