Jump to content

Recommended Posts

Posted

Im trying to learn about checkboxes but the help file doesnt seem to show me what Im looking for. I´m looking for a way to make a gui with 2 or 3 checkboxes and a button. When the button is pressed a msg box comes up based on which checkboxes are checked. The helpfile only shows how to actually make a checkbox but not do anything with it. I have a working script with checkboxes in it but I cant seem to dissect it like I normally can. The functions in the working script are just too intertwined for me to be able to pick apart. If anyone could post a basic script or tell me if Im looking in the wrong place please let me know

Gui with 3 checkboxes. Click for example box 1 and 3. Press the ¨results button¨ and it brings up a pop up saying ¨checkboxes 1 and 3 are checked¨.

Thanks for your help

chad

  • Moderators
Posted

RAMMRODD,

Because it is raining hard and I am stuck indoors.....

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hCheck1 = GUICtrlCreateCheckbox("Check 1", 10, 10, 100, 20)
$hCheck2 = GUICtrlCreateCheckbox("Check 2", 10, 50, 100, 20)
$hCheck3 = GUICtrlCreateCheckbox("Check 3", 10, 90, 100, 20)

$hButton = GUICtrlCreateButton("Go!", 10, 150, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $sResult = "Checkbox" & @CRLF
            For $i = $hCheck1 To $hCheck3
                If GUICtrlRead($i) = 1 Then $sResult &= 1 + $i - $hCheck1 & @CRLF
            Next
            If $sResult = "Checkboxes" & @CRLF Then $sResult = "No checkboxes" & @CRLF
            $sResult &= "checked"
            MsgBox(0, "Result", $sResult)
    EndSwitch
WEnd

But as Sir Humphrey Ware-Armitage said to Courtney: "Don't expect treats like this all the time!" >_<

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (edited)

I know I shouldnt expect it. I looked at example scripts and the helpfile but couldnt come up with a working example. I avoided it as long as possible, I really did and THANK YOU!

Both

Chad

Pretty sure I got close to what the lines mean please lemme know

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500);creates GUI

$hCheck1 = GUICtrlCreateCheckbox("Check 1", 10, 10, 100, 20);creates checkbox $hCheck1  
$hCheck2 = GUICtrlCreateCheckbox("Check 2", 10, 50, 100, 20);creates checkbox $hCheck2 
$hCheck3 = GUICtrlCreateCheckbox("Check 3", 10, 90, 100, 20);creates checkbox $hCheck3 

$hButton = GUICtrlCreateButton("Go!", 10, 150, 80, 30);creates button $hButton

GUISetState()

While 1

    Switch GUIGetMsg();names switch
        Case $GUI_EVENT_CLOSE;if the x button is pressed it exits
            Exit
        Case $hButton;if the button is pressed it does the stuff under it
            $sResult = "Checkbox" & @CRLF;gives $sResult a default value
            For $i = $hCheck1 To $hCheck3;names the checkboxes to $i
                If GUICtrlRead($i) = 1 Then $sResult &= 1 + $i - $hCheck1 & @CRLF;if $i = true then changes $sResult to something not sure what the &= means. Maybe adds the value to the original value?
            Next
            If $sResult = "Checkbox" & @CRLF Then $sResult = "No checkboxes" & @CRLF;if the value of $sResult has not been changed then it is changed to "no checkboxes"
            $sResult &= "checked";maybe adds "checked" to the end of $sResult
            MsgBox(0, "Result", $sResult);pop up showing $sResult's final value
    EndSwitch
WEnd
Edited by RAMMRODD
  • Moderators
Posted

RAMMRODD,

Pretty close - I have not changed much:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500) ; creates GUI

$hCheck1 = GUICtrlCreateCheckbox("Check 1", 10, 10, 100, 20) ; creates checkbox $hCheck1
$hCheck2 = GUICtrlCreateCheckbox("Check 2", 10, 50, 100, 20) ; creates checkbox $hCheck2
$hCheck3 = GUICtrlCreateCheckbox("Check 3", 10, 90, 100, 20) ; creates checkbox $hCheck3

$hButton = GUICtrlCreateButton("Go!", 10, 150, 80, 30) ; creates button $hButton

GUISetState() ; shows GUI

While 1

    Switch GUIGetMsg() ; checks values returned by GUIGetMsg in the following case statements
        Case $GUI_EVENT_CLOSE ; if the x button is pressed it exits
            Exit
        Case $hButton ; if the button is pressed it does the stuff under it
            $sResult = "Checkbox" & @CRLF ; gives $sResult a default value
            For $i = $hCheck1 To $hCheck3 ; sets $i to the Control indices if the check boxes
                ; We work through the checkboxes in turn
                If GUICtrlRead($i) = 1 Then $sResult &= 1 + $i - $hCheck1 & @CRLF ; see text!!!!!!!!!!!!!!!!!!!
            Next
            If $sResult = "Checkbox" & @CRLF Then $sResult = "No checkboxes" & @CRLF ; if the value of $sResult has not been changed then it is changed to "no checkboxes"
            $sResult &= "checked" ; adds "checked" to the end of $sResult
            MsgBox(0, "Result", $sResult) ; pop up showing $sResult's final value
    EndSwitch
WEnd

Now for the "$sResult &= 1 + $i - $hCheck1 & @CRLF" bit....

$hCheck1 is the Control Index of the first checkbox - its value will depend on how many controls have been created beforehand, but when I look here it is "3". When we loop through the checkboxes, $i is set to the Control Index values of the 3 boxes. If we find that a box is checked, we know the value of the Control Index (the value of $i) but we need to manipulate it to get the checkbox number.

The first checkbox has a Control Index of $hCheck1, so we know that if $i has that value we need to get it to "1" - the same sort of logic is true for the rest. Let us take the actual value of the checkbox ControlIDs in this example and see what we need to do:

Control Index -> Position

3 -> 1

4 -> 2

5 -> 3

My solution was based on the fact that we know (because we coded it that way!) that the first and lowest value of $i will be $hCheck1 (the the Control Index of the first checkbox), the second value will be $hCheck2 etc. So the maths becomes very simple:

$i = $hCheck1 (3). Subtract the lowest value of $i which is $hCheck1 (3) which gives us (0). However, we need a value of (1) so add 1. Result = 1 !!!

$i = $hCheck2 (4). Subtract the lowest value of $i which is $hCheck1 (3) which gives us (1). However, we need a value of (2) so add 1. Result = 2 !!!

$i = $hCheck3 (5). Subtract the lowest value of $i which is $hCheck1 (3) which gives us (2). However, we need a value of (3) so add 1. Result = 3 !!!

Thus the code reads: 1 + $i - $hCheck1 (OK I changed the order a bit to make it look prettier >_< ) The @CRLF is just to make each number appear on a new line.

I hope that all makes sense!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Is the number of controls based on the items you've already created in the code? Or is it more complicated than that. Im thinking its harder than that.

  • Moderators
Posted

RAMMRODD,

A full description of ControlIDs is given in the Help file: AutoIt -> Function Reference -> Window management -> Controls.

In short: when creating its own GUIs, Autoit allocates the first available ControlID number to the control just created. Try running the following:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hCheck1 = GUICtrlCreateCheckbox("Check 1", 10, 10, 100, 20) ; creates checkbox $hCheck1
    ConsoleWrite("ControlID $hCheck1: " & $hCheck1 & @CRLF)
$hCheck2 = GUICtrlCreateCheckbox("Check 2", 10, 50, 100, 20) ; creates checkbox $hCheck2
    ConsoleWrite("ControlID $hCheck2: " & $hCheck2 & @CRLF)
$hCheck3 = GUICtrlCreateCheckbox("Check 3", 10, 90, 100, 20) ; creates checkbox $hCheck3
    ConsoleWrite("ControlID $hCheck3: " & $hCheck3 & @CRLF)

$hButton = GUICtrlCreateButton("Go!", 10, 150, 80, 30) ; creates button $hButton
    ConsoleWrite("ControlID $hButton: " & $hButton & @CRLF)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Which shows that if you want to use the For...Next trick in the code I posted before, you have to make sure that your controls are created consecutively - if they are not you can run into all sorts of problems... >_<

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • Moderators
Posted

RAMMRODD,

Glad I could be of help.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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
  • Recently Browsing   0 members

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