pl123 Posted June 16, 2010 Posted June 16, 2010 I'm trying to create two buttons, one of which will check all the checkboxes, and the other will uncheck them, but it isn't working. When I click the buttons, nothing happens. GUICreate ("title", 400, 450, 325, 250) GUISetState(@SW_SHOW) ... GUICtrlCreateCheckbox("...", 10, 140, "", "", $BS_AUTOCHECKBOX) GUICtrlCreateCheckbox("...", 10, 160, "", "", $BS_AUTOCHECKBOX) GUICtrlCreateCheckbox("...", 10, 180, "", "", $BS_AUTOCHECKBOX) GUICtrlCreateCheckbox("...", 10, 200, "", "", $BS_AUTOCHECKBOX) GUICtrlCreateCheckbox("...", 10, 220, "", "", $BS_AUTOCHECKBOX) GUICtrlCreateCheckbox("...", 10, 240, "", "", $BS_AUTOCHECKBOX) GUICtrlCreateCheckbox("...", 10, 260, "", "", $BS_AUTOCHECKBOX) GUICtrlCreateCheckbox("...", 10, 280, "", "", $BS_AUTOCHECKBOX) ... The CtrlIDs are 10 for the first one, then 11 for the next, and so on. The last one's 17. So right now, everything's working fine, everything's in the right place. Now, the buttons... GUICtrlCreateButton("Check all", 315, 140, 70, 20, $BS_VCENTER + $BS_CENTER) ;ctrlID = 19 GUICtrlCreateButton("Check none", 315, 160, 70, 20, $BS_VCENTER + $BS_CENTER) ;ctrlID = 20 And here is where I don't understand why it doesn't work. I'm still a beginner with GUIs, so I don't know what's wrong. GUICtrlSetOnEvent (19, "_CheckAll") ... Func _CheckAll() GUICtrlSetState (10, $GUI_CHECKED) GUICtrlSetState (11, $GUI_CHECKED) GUICtrlSetState (12, $GUI_CHECKED) GUICtrlSetState (13, $GUI_CHECKED) GUICtrlSetState (14, $GUI_CHECKED) GUICtrlSetState (15, $GUI_CHECKED) GUICtrlSetState (16, $GUI_CHECKED) GUICtrlSetState (17, $GUI_CHECKED) EndFunc Either I did something wrong with the GUICtrlSetOnEvent, the Func _CheckAll(), or something else. Can someone help me with this problem?
taietel Posted June 16, 2010 Posted June 16, 2010 Check this post: here and here. Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text
Moderators Melba23 Posted June 16, 2010 Moderators Posted June 16, 2010 pl123,First piece of advice - do NOT use raw ControlIds. If ever you need to insert another control in your script, nothing will work!Use variables to store the returned ControlIDs. If you do not want to use a variable for each control (and if not, how are you going to detect when the control is used?) you can use Dummy controls like this:expandcollapse popup#include <ButtonConstants.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUICreate ("TEST", 400, 450, 325, 250) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState(@SW_SHOW) $iStart = GUICtrlCreateDummy() GUICtrlCreateCheckbox("...", 10, 140) GUICtrlCreateCheckbox("...", 10, 160) GUICtrlCreateCheckbox("...", 10, 180) GUICtrlCreateCheckbox("...", 10, 200) GUICtrlCreateCheckbox("...", 10, 220) GUICtrlCreateCheckbox("...", 10, 240) GUICtrlCreateCheckbox("...", 10, 260) GUICtrlCreateCheckbox("...", 10, 280) $iEnd = GUICtrlCreateDummy() $hButton_Check = GUICtrlCreateButton("Check all", 315, 140, 70, 20, $BS_VCENTER + $BS_CENTER) GUICtrlSetOnEvent($hButton_Check, "_CheckAll") $hButton_UnCheck = GUICtrlCreateButton("Check none", 315, 160, 70, 20, $BS_VCENTER + $BS_CENTER) ;ctrlID = 20 GUICtrlSetOnEvent($hButton_UnCheck, "_UnCheckAll") GUISetState() While 1 Sleep(10) WEnd Func _CheckAll() For $i = $iStart To $iEnd GUICtrlSetState($i, $GUI_CHECKED) Next EndFunc Func _UnCheckAll() For $i = $iStart To $iEnd GUICtrlSetState($i, $GUI_UNCHECKED) Next EndFunc Func _Exit() Exit EndFuncMuch better would be code like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> Opt("GUIOnEventMode", 1) Global $aCheckboxID[8] $hGUI = GUICreate("Test", 500, 500) GUICreate ("TEST", 400, 450, 325, 250) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState(@SW_SHOW) $aCheckboxID[0] = GUICtrlCreateCheckbox("...", 10, 140) $aCheckboxID[1] = GUICtrlCreateCheckbox("...", 10, 160) $aCheckboxID[2] = GUICtrlCreateCheckbox("...", 10, 180) $aCheckboxID[3] = GUICtrlCreateCheckbox("...", 10, 200) $aCheckboxID[4] = GUICtrlCreateCheckbox("...", 10, 220) $aCheckboxID[5] = GUICtrlCreateCheckbox("...", 10, 240) $aCheckboxID[6] = GUICtrlCreateCheckbox("...", 10, 260) $aCheckboxID[7] = GUICtrlCreateCheckbox("...", 10, 280) $hButton_Check = GUICtrlCreateButton("Check all", 315, 140, 70, 20, $BS_VCENTER + $BS_CENTER) GUICtrlSetOnEvent($hButton_Check, "_CheckAll") $hButton_UnCheck = GUICtrlCreateButton("Check none", 315, 160, 70, 20, $BS_VCENTER + $BS_CENTER) ;ctrlID = 20 GUICtrlSetOnEvent($hButton_UnCheck, "_UnCheckAll") GUISetState() While 1 Sleep(10) WEnd Func _CheckAll() For $i = 0 To 7 GUICtrlSetState($aCheckboxID[$i], $GUI_CHECKED) Next EndFunc Func _UnCheckAll() For $i = 0 To 7 GUICtrlSetState($aCheckboxID[$i], $GUI_UNCHECKED) Next EndFunc Func _Exit() Exit EndFuncwhere you have IDs for all the checkboxes and can now determine, for example, whether an individual one is checked or not.I also removed the unnecessary $BS_AUTOCHECKBOX style from the checkboxes - according to the help file it is a default forced style. Does this make sense? Please ask if not. 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
pl123 Posted June 16, 2010 Author Posted June 16, 2010 @Melba23 I understand what you mean about the control IDs, and your suggestion works fine for me. Thanks for your help!
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