Jump to content
Sign in to follow this  

Check to see if any checkboxes are checked

Recommended Posts


I know there is a way to do this, I did it a long time ago, i just cant remember how to do it. >_<

When any one of my checkboxes are checked it will popup with a go message and when none are checked it comes up with an error.

If GuiCtrlRead($Chk1) = $GUI_UNCHECKED Then
    MsgBox(0, "Error", "Please Check Something!")
    MsgBox(0, "Completed", "Completed!")

So on the first line it should be something like this, but I know that wont work. I cant remember but maybe I used a "BIT" like "BITOR" or something like that.

If GuiCtrlRead($Chk1 or $Chk2) = $GUI_UNCHECKED Then

Any ideas?

Share this post

Link to post
Share on other sites

I'm sure there are other ways, but this works for me..

If BitAnd(GUICtrlRead($Chk1), $GUI_CHECKED) Then

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post

Link to post
Share on other sites

Without seeing your whole script and knowing things like the number of Checkboxes you want checked, I just offer the following simple example.

If GuiCtrlRead($Chk1) = $GUI_UNCHECKED or GuiCtrlRead($Chk2) = $GUI_UNCHECKED Then
Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.


What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)


Share this post

Link to post
Share on other sites
When any one of my checkboxes are checked it will popup with a go message and when none are checked it comes up with an error.


Then you would have to use an loop( recommended FOR - NEXT loop ) to check each control. I don't think there is something using BitOR or stuff like that...


#include <GUIConstantsEx.au3>


Func Example()
    Local $msg
    GUICreate("My GUI Checkbox") ; will create a dialog box that when displayed is centered

    ;I created all the checkboxes(in sequence i.e. one after the other) using a For Loop
    ;so that I can use the controlID of the First and the Last
    ;when verifying that at least a single checkbox is checked.

    ;You can even use an array to store all your check boxes's controlID
    ;and use it while verifying in the for loop.
    Local $iFirst = GUICtrlCreateCheckbox("CHECKBOX 1", 10, 5, 120, 20)
    For $i = 0 To 6
        GUICtrlCreateCheckbox("CHECKBOX " & $i + 2, 10, 30 * ($i + 1) + 2, 120, 20)
    Local $iLast = GUICtrlCreateCheckbox("CHECKBOX 9", 10, 30 * ($i + 1) + 2, 120, 20)

    GUISetState() ; will display an  dialog box with 1 checkbox

    ; Run the GUI until the dialog is closed
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then

            ;Note this part is the important and required part
            For $i = $iFirst To $iLast
                If GUICtrlRead($i) = $GUI_CHECKED Then
                    Return MsgBox(0, "Completed", "Completed!"); atleast one is checked.

            ;reached here that means nothing is checked.
            MsgBox(16, "Error", "Please Check Something!")  ;show the error and continue the loop


    Until 0

EndFunc   ;==>Example

Note: When Controls are created the return value is the ControlID(an integer uniquely identifying the control) and this integer is relative to the sequence of controls created( ==> if the first checkbox is assigned a ControlID say '5' then the second is assigned a ControlID '6' and so on...) .

Hence, it is very easy to use the ControlID of the first and last checkbox created in a For-Next loop.

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.