From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to error check if the checkbox is checked or not?

Solved!
Go to solution

How do I error check if my checkbox is checked or not? I have three of them, I just need to figure out how to error check them if all three never get checked... I tried to do an error check with a boolean function and it still errored out even if I checked one.

 

So, I just realized that it seems I have a bug or something because my program also doesn't hit my callback function for the checkboxes at all. It just passes right through them.

 

Any help would be nice. Thanks

0 Kudos
Message 1 of 7
(2,441 Views)

If it is in hot mode, a checkbox responds to EVENT_COMMIT events; inside the callback you can simply call GetCtrlVal to get the status: value is 1 if checked, 0 otherwise. 



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 7
(2,428 Views)

Can you paste here the block of code which reads the checkbox state? You can send the whole callback if it is not too long. 

S. Eren BALCI
IMESTEK
0 Kudos
Message 3 of 7
(2,424 Views)

int CVICALLBACK check_sn (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_LEFT_CLICK:
GetCtrlVal (panelHandle, PANEL_chk_sn, &IsChecked);
sn = IsChecked;

break;
}
return sn;
}
int CVICALLBACK check_operator(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:

GetCtrlVal (panelHandle, PANEL_chk_operator, &IsChecked);
operator = IsChecked;


break;
}
return operator;
}

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

GetCtrlVal (panelHandle, PANEL_chk_partid, &IsChecked);
partid = IsChecked;


break;
}
return partid;
}

0 Kudos
Message 4 of 7
(2,415 Views)
Solution
Accepted by mpwbs

First, You shouldn't return checkbox state from the callback. Callback normally must return zero. Nonzero returns causes events to be "swallowed". 

Second, change the EVENT_LEFT_CLICK to EVENT_VAL_CHANGED. Your callback is called before the state is changed, therefore you cannot get the new value. 

S. Eren BALCI
IMESTEK
Message 5 of 7
(2,410 Views)

So, all of them to VAL_CHANGED? I was playing around with the click event to see if that was the issue or not.

0 Kudos
Message 6 of 7
(2,403 Views)

If all three callbacks are belonging to checkboxes, yes, you can convert them to EVENT_VAL_CHANGED. 

Make sure you return 0 also, from those callbacks.

After you call GetCtrlVal, the recent value of the checkbox should be in the variable.

S. Eren BALCI
IMESTEK
Message 7 of 7
(2,398 Views)