RAMMRODD Posted August 6, 2009 Share Posted August 6, 2009 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 Link to comment Share on other sites More sharing options...
MisterX Posted August 6, 2009 Share Posted August 6, 2009 (edited) Use GUICtrlRead($hID) Where $hID is the identifier (control ID) of the control. Edited August 6, 2009 by MisterX Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 6, 2009 Moderators Share Posted August 6, 2009 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
RAMMRODD Posted August 6, 2009 Author Share Posted August 6, 2009 (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 August 6, 2009 by RAMMRODD Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 6, 2009 Moderators Share Posted August 6, 2009 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 WEndNow 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 -> Position3 -> 14 -> 25 -> 3My 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
RAMMRODD Posted August 6, 2009 Author Share Posted August 6, 2009 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 6, 2009 Moderators Share Posted August 6, 2009 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 WEndWhich 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
RAMMRODD Posted August 6, 2009 Author Share Posted August 6, 2009 I think I get it now thanks a lot for wasting your time talking to me Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 6, 2009 Moderators Share Posted August 6, 2009 RAMMRODD, Glad I could be of help. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now