Jump to content

Getting value on checkbox


PHPWarner
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...