03-22-2010 03:57 PM
Is there any function available in CVI to check if a checkbox is selected / checked or not?
Solved! Go to Solution.
03-22-2010 04:03 PM
03-24-2010 10:54 AM
This is not working with me? For this function "GetCtrlVal" the CVI help gives "When the control ID is for a list box or ring control, GetCtrlVal returns the value of the currently selected list item."
But I wanted to check if a checkbox is checked or not?
03-24-2010 11:19 AM
1) There is no contradiction. If you read the help carefully, it says: GetCtrlVal obtains the current value of a control... the following text 'When the control ID is for a list box...' is for the special cases of a list box and ring control only.
Hence, if you do not have a list box or ring control, then GetCtrlVal simply obtains the current value of a control, including a checkbox.
2) If it doesn't work for you, you should post the code you are using. You might want to check first if you are using the correct panel handle and control id.
03-24-2010 11:19 AM
If you are using the checkboxes associated with a List Box control, you need to use the IsListItemChecked() function.
JR
03-24-2010 11:41 AM
Attached is the screen shot of the user interface I am using in CVI:
In user interface the checkbox (CHECKBOX_4) is placed on the panel (Main_Menu)
Below is the way I defined the both:
#define Main_Menu 1
#define Main_Menu_CHECKBOX_4 11
Below is the code I used for knowing whether the checkbox is checked or not:
GetCtrlVal(Main_Menu, Main_Menu_CHECKBOX_4, &iIsChecked2);
03-24-2010 11:52 AM - edited 03-24-2010 11:56 AM
you should not define the constants yourself, this is already done by the UIR editor. These constants can be found in the corresponding include file of your UIR.
So if your UIR file name is my_gui.uir, the corresponding include file is my_gui.h; you need to include this file into your project:
at the top of your C file, add the line
#include "my_gui.h"
03-24-2010 12:26 PM
You must use the panel handle as the first parameter to GetCtrlVal, not a value you make up yourself. This is the return value from your LoadPanel() call.
I think you should work through a few of the basic CVI shipping examples to give you an idea of how to approach a CVI program.
JR
03-24-2010 01:03 PM
When I try to complite the project the below is the error I am getting, if I do not define the "Main_Menu_CHECKBOX_7":
__TestMain.c - 1 error
188, 27 Undeclared identifier 'Main_Menu_CHECKBOX_4'.
Or other way how to generate the corresponding include file for the .uir files?
03-24-2010 01:24 PM
from the help file:
LabWindows/CVI automatically generates the necessary header file every time you save a .uir file.
So: generate an include file, include it in your source code, and in your source code, only use the constants as defined in the include file. If you continue to receive undeclared identifiers, check your source code if you have missed changing a panel or control id.
Good luck.