Sign in to follow this  
Followers 0
Fr0stb1t3

Checkbox and Button function help required

6 posts in this topic

Hi all,

Got a bit of a mission on my hands.

I'm a programming newbie mainly because my head says no every time I try!

I've made things in the past which didn't require too much effort, however now I require some help.

I have created a GUI interface with Koda, bitchin app!

Sure beats the hell out of coding then running the script to see if you aligned it correctly.

I'm quite sure that this is basic enough to do for you gurus but it is beyond me.

Anyways, here is my code so far:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "Terminate")

Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Title", 385, 356, 368, 249)
GUISetIcon("Icon.ico")

$Group1 = GUICtrlCreateGroup("Set1", 16, 8, 353, 153)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox 1", 40, 32, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox 2", 40, 48, 113, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox 3", 40, 64, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox("Checkbox 5", 40, 96, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("Checkbox 4", 40, 80, 97, 17)
$Checkbox6 = GUICtrlCreateCheckbox("Checkbox 8", 160, 32, 97, 17)
$Checkbox7 = GUICtrlCreateCheckbox("Checkbox 7", 40, 128, 97, 17)
$Checkbox8 = GUICtrlCreateCheckbox("Checkbox 6", 40, 112, 97, 17)
$Checkbox9 = GUICtrlCreateCheckbox("Checkbox 9", 160, 48, 97, 17)
$Checkbox10 = GUICtrlCreateCheckbox("Checkbox 11", 160, 80, 97, 17)
$Checkbox11 = GUICtrlCreateCheckbox("Checkbox 10", 160, 64, 97, 17)
$Checkbox12 = GUICtrlCreateCheckbox("Checkbox 12", 160, 96, 97, 17)
$Checkbox13 = GUICtrlCreateCheckbox("Checkbox 14", 160, 128, 97, 17)
$Checkbox14 = GUICtrlCreateCheckbox("Checkbox 13", 160, 112, 97, 17)
$Checkbox15 = GUICtrlCreateCheckbox("Checkbox 15", 264, 32, 97, 17)
$Checkbox16 = GUICtrlCreateCheckbox("Checkbox 16", 264, 48, 97, 17)
$Checkbox17 = GUICtrlCreateCheckbox("Checkbox 18", 264, 80, 97, 17)
$Checkbox18 = GUICtrlCreateCheckbox("Checkbox 17", 264, 64, 97, 17)
$Checkbox19 = GUICtrlCreateCheckbox("Checkbox 19", 264, 96, 97, 17)
$Checkbox20 = GUICtrlCreateCheckbox("Checkbox 21", 264, 128, 97, 17)
$Checkbox21 = GUICtrlCreateCheckbox("Checkbox 20", 264, 112, 97, 17)

$Group2 = GUICtrlCreateGroup("Set2", 16, 168, 353, 73)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Checkbox22 = GUICtrlCreateCheckbox("Checkbox 1", 40, 192, 97, 17)
$Checkbox25 = GUICtrlCreateCheckbox("Checkbox 2", 40, 208, 97, 17)
$Checkbox23 = GUICtrlCreateCheckbox("Checkbox 3", 160, 192, 97, 17)
$Checkbox24 = GUICtrlCreateCheckbox("Checkbox 4", 264, 192, 97, 17)

$Checkbox26 = GUICtrlCreateCheckbox("Select all Checkbox", 48, 248, 113, 17)
$Checkbox27 = GUICtrlCreateCheckbox("Select all Set1", 168, 248, 97, 17)
$Checkbox28 = GUICtrlCreateCheckbox("Select all Set2", 272, 248, 97, 17)

GUISetState(@SW_SHOW)

$Group3 = GUICtrlCreateGroup("", 16, 272, 353, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label1 = GUICtrlCreateLabel("Select which checkboxes you want.", 48, 288, 291, 17)

$Run = GUICtrlCreateButton("R&un", 104, 320, 75, 25, $WS_GROUP)
$Close = GUICtrlCreateButton("&Close", 192, 320, 75, 25, $WS_GROUP)

While 1
    Sleep(100)
WEnd

Func Terminate()
    Exit 0
EndFunc

What I would like to be able to do is every checkbox has its own set of commands to run.

Example:

Del /q y:\dir\file.txt

Dir x:\dir\dir /b>y:\dir\file.txt

Dir x:\dir /b>>y:\dir\file.txt [appending to current file]

However the second command for the checkbox Dir x:\dir\dir /b>y:\dir\file.txt will be run

on every checkbox, is there perhaps a way to shortcut the coding to a function instead of

coding it in for each one?

Select all Checkboxes I would like them to be able to select all corresponding checkboxes.

And of course the Run button to execute the selected functions or popup a message saying

nothing selected. Respectively the Close button to close the program.

I've trawled through the net to find anything that may help but nothing seems to fit the

bill, so I'm relying on some of you gurus to help me out.

Your help is and will be much appreciated.

Share this post


Link to post
Share on other sites



First off, have you looked into the GUICtrlSetState() and GUICtrlGetState() functions in the helpfile?

Well I was hoping that you would be able to tell by what I have in my script and by my comment of being

a programming newbie that it would give you a heads up to the fact I know of no other commands so do

what I require.

Hence again why I was asking for help. :mellow:

Nor do I have all the time in the world to be trawling through piles and piles of help files.

Thanks for bringing these commands to my attention.

However again like I said I'm a newbie, if someone can use my script and add the features with some

explanation it would help greatly.

Any takers?

Share this post


Link to post
Share on other sites

Well this works, but I'm sure there is a more efficient way to do it. I've only written code for $Checkbox1 to run stuff in the Runs() function because I was tired of typing after I got the SelectCheckBoxes() function working. The first line in that function (the one that's commented) and the GUISetOnEvent function can be used to get other Control ID's.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "Terminate")

Opt("GUIOnEventMode", 1)

Global $Checkbox, $Checkbox1, $Checkbox2, $Checkbox3, $Checkbox4, $Checkbox5, $Checkbox6, $Checkbox7, $Checkbox8, $Checkbox9, $Checkbox10, $Checkbox11, $Checkbox12, $Checkbox13, $Checkbox14, $Checkbox15, $Checkbox16, $Checkbox17, $Checkbox18, $Checkbox19, $Checkbox20, $Checkbox21, $Checkbox22, $Checkbox23, $Checkbox24, $Checkbox25, $Checkbox26, $Checkbox27, $Checkbox28

$Form1 = GUICreate("Title", 385, 356, 368, 249)
GUISetIcon("Icon.ico")

$Group1 = GUICtrlCreateGroup("Set1", 16, 8, 353, 153)
 GUICtrlCreateGroup("", -99, -99, 1, 1)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox 1", 40, 32, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox 2", 40, 48, 113, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox 3", 40, 64, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox("Checkbox 5", 40, 96, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("Checkbox 4", 40, 80, 97, 17)
$Checkbox6 = GUICtrlCreateCheckbox("Checkbox 8", 160, 32, 97, 17)
$Checkbox7 = GUICtrlCreateCheckbox("Checkbox 7", 40, 128, 97, 17)
$Checkbox8 = GUICtrlCreateCheckbox("Checkbox 6", 40, 112, 97, 17)
$Checkbox9 = GUICtrlCreateCheckbox("Checkbox 9", 160, 48, 97, 17)
$Checkbox10 = GUICtrlCreateCheckbox("Checkbox 11", 160, 80, 97, 17)
$Checkbox11 = GUICtrlCreateCheckbox("Checkbox 10", 160, 64, 97, 17)
$Checkbox12 = GUICtrlCreateCheckbox("Checkbox 12", 160, 96, 97, 17)
$Checkbox13 = GUICtrlCreateCheckbox("Checkbox 14", 160, 128, 97, 17)
$Checkbox14 = GUICtrlCreateCheckbox("Checkbox 13", 160, 112, 97, 17)
$Checkbox15 = GUICtrlCreateCheckbox("Checkbox 15", 264, 32, 97, 17)
$Checkbox16 = GUICtrlCreateCheckbox("Checkbox 16", 264, 48, 97, 17)
$Checkbox17 = GUICtrlCreateCheckbox("Checkbox 18", 264, 80, 97, 17)
$Checkbox18 = GUICtrlCreateCheckbox("Checkbox 17", 264, 64, 97, 17)
$Checkbox19 = GUICtrlCreateCheckbox("Checkbox 19", 264, 96, 97, 17)
$Checkbox20 = GUICtrlCreateCheckbox("Checkbox 21", 264, 128, 97, 17)
$Checkbox21 = GUICtrlCreateCheckbox("Checkbox 20", 264, 112, 97, 17)

$Group2 = GUICtrlCreateGroup("Set2", 16, 168, 353, 73)
 GUICtrlCreateGroup("", -99, -99, 1, 1)
$Checkbox22 = GUICtrlCreateCheckbox("Checkbox 1", 40, 192, 97, 17)
$Checkbox23 = GUICtrlCreateCheckbox("Checkbox 2", 40, 208, 97, 17)
$Checkbox24 = GUICtrlCreateCheckbox("Checkbox 3", 160, 192, 97, 17)
$Checkbox25 = GUICtrlCreateCheckbox("Checkbox 4", 264, 192, 97, 17)

$Checkbox26 = GUICtrlCreateCheckbox("Select all Checkbox", 48, 248, 113, 17)
 GUICtrlSetOnEvent(-1, "SelectCheckBoxes")
$Checkbox27 = GUICtrlCreateCheckbox("Select all Set1", 168, 248, 97, 17)
 GUICtrlSetOnEvent(-1, "SelectCheckBoxes")
$Checkbox28 = GUICtrlCreateCheckbox("Select all Set2", 272, 248, 97, 17)
 GUICtrlSetOnEvent(-1, "SelectCheckBoxes")

GUISetState(@SW_SHOW)

$Group3 = GUICtrlCreateGroup("", 16, 272, 353, 41)
 GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label1 = GUICtrlCreateLabel("Select which checkboxes you want.", 48, 288, 291, 17)

$Run = GUICtrlCreateButton("R&un", 104, 320, 75, 25, $WS_GROUP)
 GUICtrlSetOnEvent(-1, "Runs")
$Close = GUICtrlCreateButton("&Close", 192, 320, 75, 25, $WS_GROUP)
 GUICtrlSetOnEvent(-1, "Terminate")

While 1
    Sleep(100)
WEnd

Func Runs()
    If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) = $GUI_CHECKED Then
        MsgBox(0, "", "There is some commands here..")
    EndIf
EndFunc

Func SelectCheckBoxes()
    ;ConsoleWrite(@GUI_CtrlId & @LF)
    Switch @GUI_CtrlId
        Case 32
            If BitAND(GUICtrlRead($Checkbox26), $GUI_CHECKED) = $GUI_CHECKED Then
                For $n = 5 To 31
                    GUICtrlSetState($Checkbox + $n, $GUI_CHECKED)
                Next
            Else
                For $n = 5 To 31
                    GUICtrlSetState($Checkbox + $n, $GUI_UNCHECKED)
                Next
            EndIf
        Case 33
            If BitAND(GUICtrlRead($Checkbox27), $GUI_CHECKED) = $GUI_CHECKED Then
                For $n = 5 To 25
                    GUICtrlSetState($Checkbox + $n, $GUI_CHECKED)
                Next
            Else
                For $n = 5 To 25
                    GUICtrlSetState($Checkbox + $n, $GUI_UNCHECKED)
                Next
            EndIf
        Case 34
            If BitAND(GUICtrlRead($Checkbox28), $GUI_CHECKED) = $GUI_CHECKED Then
                For $n = 26 To 31
                    GUICtrlSetState($Checkbox + $n, $GUI_CHECKED)
                Next
            Else
                For $n = 26 To 31
                    GUICtrlSetState($Checkbox + $n, $GUI_UNCHECKED)
                Next
            EndIf
    EndSwitch
EndFunc

Func Terminate()
    Exit 0
EndFunc

- 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

Well this works, but I'm sure there is a more efficient way to do it. I've only written code for $Checkbox1 to run stuff in the Runs() function because I was tired of typing after I got the SelectCheckBoxes() function working. The first line in that function (the one that's commented) and the GUISetOnEvent function can be used to get other Control ID's.

That is freakin awesome.

Thanks somdcomputerguy, I don't quite understand what you mean regarding:

"The first line in that function (the one that's commented) and the GUISetOnEvent function can be used to get other Control ID's."

I can understand the tired fingers. :mellow:

Where you have the msgbox popping up when a selectbox has been selected and the script has been run,

what do I need to put inplace to run the 3 commands which were shown in my original post.

I have also seen some issues in the way that the checkboxes were listed. (Out of order)

I have since corrected.

Your help is much appreciated.

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