Jump to content

Help with the CheckBox script


Recommended Posts

Hi All! I'm a beginner in this AutoIT. I am creating a sample CheckBox than when check and OK button is clicked it will display what checkbox is selected. I have made a form through KODA and generated sample code but i don't know how to write that will do the script.

Please I need your expert tips...Thanks in advance.

Here is the generated code:

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Form1", 391, 158, 245, 531)

GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")

GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")

GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")

GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")

$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 32, 32, 89, 25)

GUICtrlSetOnEvent($Checkbox1, "Checkbox1Click")

$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 32, 80, 97, 17)

GUICtrlSetOnEvent($Checkbox2, "Checkbox2Click")

$Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 32, 120, 97, 17)

GUICtrlSetOnEvent($Checkbox3, "Checkbox3Click")

$OK = GUICtrlCreateButton("OK", 192, 42, 89, 32, 0)

GUICtrlSetOnEvent($OK, "OKClick")

$Exit = GUICtrlCreateButton("Exit", 192, 90, 89, 32, 0)

GUICtrlSetOnEvent($Exit, "ExitClick")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

Sleep(100)

WEnd

Func Checkbox1Click()

EndFunc

Func Checkbox2Click()

EndFunc

Func Checkbox3Click()

EndFunc

Func ExitClick()

Exit

EndFunc

Func Form1Close()

EndFunc

Func Form1Maximize()

EndFunc

Func Form1Minimize()

EndFunc

Func Form1Restore()

EndFunc

Func OKClick()

EndFunc

Link to comment
Share on other sites

What exactly is your question?

i have my window with three checkboxes on it and with Exit and OK Button. What i want to happen is i can select and deselect the checkboxes and when i clicked on OK button it will give me message which checkbox is/are selected.

Link to comment
Share on other sites

i have my window with three checkboxes on it and with Exit and OK Button. What i want to happen is i can select and deselect the checkboxes and when i clicked on OK button it will give me message which checkbox is/are selected.

i have my simple code like this:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()

Local $checkCN, $msg, $msgbox, $main, $window

$window = GUICreate("My GUI Checkbox")

$checkCN = GUICtrlCreateCheckbox("CHECKBOX 1", 10, 10, 120, 20)

GUISetState()

While 1

$main = GUIGetMsg()

If $main = $GUI_EVENT_CLOSE Then Exit

$msg = GUICtrlRead($checkCN)

If $msg = $GUI_CHECKED Then

MsgBox(0, "", "It is checked")

Exit

EndIf

WEnd

EndFunc

When i checked the box it will show me message. This works fine. BUt how do get back on the main form. Becasue this will totally if you click on the OK button. I wanted to go back on the main form when ok is click from the message.

Link to comment
Share on other sites

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 391, 158, 245, 531)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 32, 32, 89, 25)
;GUICtrlSetOnEvent($Checkbox1, "Checkbox1Click")
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 32, 80, 97, 17)
;GUICtrlSetOnEvent($Checkbox2, "Checkbox2Click")
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 32, 120, 97, 17)
;GUICtrlSetOnEvent($Checkbox3, "Checkbox3Click")
$OK = GUICtrlCreateButton("OK", 192, 42, 89, 32, 0)
GUICtrlSetOnEvent($OK, "OKClick")
$Exit = GUICtrlCreateButton("Exit", 192, 90, 89, 32, 0)
GUICtrlSetOnEvent($Exit, "ExitClick")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
Sleep(100)

WEnd

Func Checkbox1Click()

EndFunc
Func Checkbox2Click()

EndFunc
Func Checkbox3Click()

EndFunc
Func ExitClick()
Exit
EndFunc
Func Form1Close()

EndFunc
Func Form1Maximize()

EndFunc
Func Form1Minimize()

EndFunc
Func Form1Restore()

EndFunc
Func OKClick()
msgbox(0,"","1 means checked, 4 means unchecked"&@crlf&@crlf&GuiCtrlRead($CheckBox1)&@crlf&GuiCtrlRead($CheckBox2)&@crlf&GuiCtrlRead($CheckBox3))
EndFunc

Trust me to make SkyNet with AutoIt...

Link to comment
Share on other sites

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 391, 158, 245, 531)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 32, 32, 89, 25)
;GUICtrlSetOnEvent($Checkbox1, "Checkbox1Click")
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 32, 80, 97, 17)
;GUICtrlSetOnEvent($Checkbox2, "Checkbox2Click")
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 32, 120, 97, 17)
;GUICtrlSetOnEvent($Checkbox3, "Checkbox3Click")
$OK = GUICtrlCreateButton("OK", 192, 42, 89, 32, 0)
GUICtrlSetOnEvent($OK, "OKClick")
$Exit = GUICtrlCreateButton("Exit", 192, 90, 89, 32, 0)
GUICtrlSetOnEvent($Exit, "ExitClick")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
Sleep(100)

WEnd

Func Checkbox1Click()

EndFunc
Func Checkbox2Click()

EndFunc
Func Checkbox3Click()

EndFunc
Func ExitClick()
Exit
EndFunc
Func Form1Close()
Exit
EndFunc
Func Form1Maximize()

EndFunc
Func Form1Minimize()

EndFunc
Func Form1Restore()

EndFunc
Func OKClick()
msgbox(0,"","1 means checked, 4 means unchecked"&@crlf&@crlf&GuiCtrlRead($CheckBox1)&@crlf&GuiCtrlRead($CheckBox2)&@crlf&GuiCtrlRead($CheckBox3))
EndFunc

That should do it.

Trust me to make SkyNet with AutoIt...

Link to comment
Share on other sites

That worked. I manage to make my script to what i want to happen. This is the new code.

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Form1", 391, 158, 245, 531)

GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")

GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")

GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")

GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")

$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 32, 32, 89, 25)

GUICtrlSetOnEvent($Checkbox1, "Checkbox1Click")

$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 32, 80, 97, 17)

GUICtrlSetOnEvent($Checkbox2, "Checkbox2Click")

$Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 32, 120, 97, 17)

GUICtrlSetOnEvent($Checkbox3, "Checkbox3Click")

$OK = GUICtrlCreateButton("OK", 192, 42, 89, 32, 0)

GUICtrlSetOnEvent($OK, "OKClick")

$Exit = GUICtrlCreateButton("Exit", 192, 90, 89, 32, 0)

GUICtrlSetOnEvent($Exit, "ExitClick")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$Check1 = GUICtrlRead($Checkbox1)

$Check2 = GUICtrlRead($Checkbox2)

$Check3 = GUICtrlRead($Checkbox3)

$msg = GUIGetMsg()

Select

Case $msg = GUIGetMsg()

If $msg= $GUI_EVENT_CLOSE Then

Form1Close()

EndIf

EndSelect

WEnd

Func Checkbox1Click()

Select

Case $Check1 = GUICtrlRead($Checkbox1)

If $Check1 = $GUI_CHECKED Then

MsgBox (0, "", "Checkbox 1 is selected")

Else

MsgBox (0, "", "Checkbox 1 is deselected")

EndIf

EndSelect

EndFunc

Func Checkbox2Click()

Select

Case $Check2 = GUICtrlRead($Checkbox2)

If $Check2 = $GUI_CHECKED Then

MsgBox (0, "", "Checkbox 2 is selected")

Else

MsgBox (0, "", "Checkbox 2 is deselected")

EndIf

EndSelect

EndFunc

Func Checkbox3Click()

Select

Case $Check3 = GUICtrlRead($Checkbox3)

If $Check3 = $GUI_CHECKED Then

MsgBox(0, "", "Checkbox 3 is selected")

Else

MsgBox(0, "", "Checkbox 3 is deselected")

EndIf

EndSelect

EndFunc

Func ExitClick()

Exit

EndFunc

Func Form1Close()

Exit

EndFunc

Func Form1Maximize()

EndFunc

Func Form1Minimize()

EndFunc

Func Form1Restore()

EndFunc

Func OKClick()

Checkbox1Click()

Checkbox2Click()

Checkbox3Click()

EndFunc

Thanks for the help. From this i will go further to learn more...

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...