Jump to content
Sign in to follow this  

Check If All Checkboxes Are Checked

Recommended Posts

G'day everyone

I'm trying to create a GUI in which the user has to check all checkboxes and press the OK button before the script continues. I just don't know how to check if the user has checked all the checkboxes. My solution doesn't work... I thought that since if the state of the checkbox is changed, it returns the value 1, then all I have to do is check if the sum of the values equal the number of checkboxes. Unfortunately, I don't know the syntax to do that (and I can't find it under the math functions in the Help file).

Here's what I have (the last bit doesn't work, but you'll get the idea):

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode 
$mainwindow = GUICreate("Hello World", 200, 100)

$checkCN1 = GUICtrlCreateCheckbox ("Checkbox 1", 20, 20)
$checkCN2 = GUICtrlCreateCheckbox ("Checkbox 2", 20, 40)
$checkCN3 = GUICtrlCreateCheckbox ("Checkbox 3", 20, 60)
$checkCN4 = GUICtrlCreateCheckbox ("Checkbox 4", 20, 80)

$okbutton = GUICtrlCreateButton("OK", 20, 100, 60)
GUICtrlSetOnEvent($okbutton, "OKButton")

While 1

Func OKButton()

Dim $a, $b, $c, $d, $e

$a = GUICtrlGetState ($checkCN1)
$b = GUICtrlGetState ($checkCN2)
$c = GUICtrlGetState ($checkCN3)
$d = GUICtrlGetState ($checkCN4)

$e = ($a+$b+$c+$d)

  $e = (4)
  MsgBox(0, "GUI Event", "You ticked all four boxes")
  MsgBox(0, "GUI Event", "You did not tick all four boxes")

Any ideas? I really miss an abundance of GUI examples in the Help file.



Share this post

Link to post
Share on other sites

You need to use GUICtrlRead()

$a = GUICtrlRead($checkCN1)
    $b = GUICtrlRead($checkCN2)
    $c = GUICtrlRead($checkCN3)
    $d = GUICtrlRead($checkCN4)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
Live for the present,
Dream of the future,
Learn from the past.

Share this post

Link to post
Share on other sites

GuitCtrlGetState() returns the current state of the check box. This will return $GUI_CHECKED or $GUI_UNCHECKED when called, not a 1 if checked and a 0 in uncecked.

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...