Sign in to follow this  
Followers 0
PHPWarner

Getting value on checkbox

8 posts in this topic

Hello,

I need little help for checkboxes on GUI. Here is my sample form:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 206, 158, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 32, 16, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 32, 40, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 32, 64, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox("Checkbox4", 32, 88, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("Checkbox5", 32, 112, 97, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

My question is, when I want to get value (checked or not) on $Checkbox1 with GUICtrlRead($Checkbox1) is it showing that label, Checkbox1 but I want to get checked or not value on one of the checkboxes. So how can I get value for checkboxes or radio buttons?

Thank you so much.

Share this post


Link to post
Share on other sites



One addition to my question.

Is it possible to check all or check none options? If yes, how to do it?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can use line like this to see if a checkbox is checked. Use $GUI_UNCHECKED to see if its not.

GUICtrlRead($Checkbox1) = $GUI_CHECKED

Use this function to check or uncheck the box automatically

GUICtrlSetState
Edited by snowmaker

- 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

#4 ·  Posted (edited)

It is getting error on GUICtrlRead($Checkbox1) = $GUI_CHECKED

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Form1", 231, 215, 462, 210)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 32, 16, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 32, 40, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 32, 64, 97, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Checkbox4 = GUICtrlCreateCheckbox("Checkbox4", 32, 88, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("Checkbox5", 32, 112, 97, 17)
$Button1 = GUICtrlCreateButton("Button1", 24, 136, 89, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Button2", 120, 136, 81, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUICtrlRead($Checkbox1) = $GUI_CHECKED
            GUICtrlSetState($Checkbox1, $GUI_CHECKED)
    EndSwitch
WEnd
Edited by PHPWarner

Share this post


Link to post
Share on other sites

Well the error message probably says something useful, but I can't read it from here..


- 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

Okay, it seems to be checked value is 1 and unchecked value is 4. Please update me if I am wrong.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Form1", 231, 215, 462, 210)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox Test 1", 32, 16, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox Test 2", 32, 40, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox Test 3", 32, 64, 97, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Checkbox4 = GUICtrlCreateCheckbox("Checkbox Test 4", 32, 88, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("Checkbox Test 5", 32, 112, 97, 17)
$Button1 = GUICtrlCreateButton("Button1", 24, 136, 89, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Button2", 120, 136, 81, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            MsgBox(0, "Checkbox Test 1", GUICtrlRead($Checkbox1))
            MsgBox(0, "Checkbox Test 2", GUICtrlRead($Checkbox2))
            MsgBox(0, "Checkbox Test 3", GUICtrlRead($Checkbox3))
            GUICtrlSetState($Checkbox1, $GUI_CHECKED)
            MsgBox(0, "Checkbox Test 1", GUICtrlRead($Checkbox1))
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Those values are correct. I use an If..Then statement to act on whether a checkbox is checked or not.


- 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

Thank you so much.

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  
Followers 0