stick3r Posted November 22, 2018 Posted November 22, 2018 Hi, I have this script and I need to reset all checkboxes to UNCHECKED when button is pressed. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Global $Form = GUICreate("Checklist", 190, 407, 1233, 178) Global $text = "" Global $CheckBox GUICtrlCreateTab(1, 1, 190, 365) GUICtrlCreateTabItem("TAB 1") Global $InputCaseID1 = GUICtrlCreateInput($text, 80, 25, 80, 21) Global $lblCaseID = GUICtrlCreateLabel("Case ID", 8, 30, 68, 18) Global $CheckBox1 = GUICtrlCreateCheckbox("1111111", 8, 48, 110, 17) Global $CheckBox2 = GUICtrlCreateCheckbox("2222222", 8, 72, 110, 17) Global $CheckBox3 = GUICtrlCreateCheckbox("333333333", 8, 96, 110, 17) Global $CheckBox4 = GUICtrlCreateCheckbox("444444444", 8, 120, 110, 17) Global $CheckBox5 = GUICtrlCreateCheckbox("55555555", 8, 144, 110, 17) Global $CheckBox6 = GUICtrlCreateCheckbox("666666666", 8, 168, 110, 17) Global $CheckBox7 = GUICtrlCreateCheckbox("77777777", 8, 192, 150, 17) Global $CheckBox8 = GUICtrlCreateCheckbox("888888888", 8, 216, 150, 17) Global $CheckBox9 = GUICtrlCreateCheckbox("99999999", 8, 240, 110, 17) Global $CheckBox10 = GUICtrlCreateCheckbox("45646", 8, 264, 110, 17) Global $CheckBox11 = GUICtrlCreateCheckbox("4345634", 8, 288, 97, 17) Global $CheckBox12 = GUICtrlCreateCheckbox("4563456", 8, 312, 97, 17) Global $CheckBox13 = GUICtrlCreateCheckbox("456456", 8, 336, 97, 17) GUICtrlCreateTabItem("TAB 2") Global $InputCaseID2 = GUICtrlCreateInput("", 80, 25, 80, 21) Global $lblCaseID = GUICtrlCreateLabel("Case ID", 8, 30, 68, 18) Global $CheckBox14 = GUICtrlCreateCheckbox("AAAAAAA", 8, 48, 110, 17) Global $CheckBox15 = GUICtrlCreateCheckbox("PPPPPPPPP", 8, 72, 110, 17) Global $CheckBox16 = GUICtrlCreateCheckbox("BBBBBBBB", 8, 96, 110, 17) Global $CheckBox17 = GUICtrlCreateCheckbox("CCCCCCCCCCCCC", 8, 120, 110, 17) Global $CheckBox18 = GUICtrlCreateCheckbox("DDDDDDDDDDDDD", 8, 144, 110, 17) Global $CheckBox19 = GUICtrlCreateCheckbox("EEEEEEEEEE", 8, 168, 110, 17) Global $CheckBox20 = GUICtrlCreateCheckbox("FFFFFFFFFFF", 8, 192, 150, 17) Global $CheckBox21 = GUICtrlCreateCheckbox("GGGGGGGGGG", 8, 216, 150, 17) Global $CheckBox22 = GUICtrlCreateCheckbox("HHHHHHHHH", 8, 240, 110, 17) Global $CheckBox23 = GUICtrlCreateCheckbox("IIIIIIIII", 8, 264, 110, 17) Global $CheckBox24 = GUICtrlCreateCheckbox("JJJJJJJ", 8, 288, 97, 17) Global $CheckBox25 = GUICtrlCreateCheckbox("KKKKKKKKKKK", 8, 312, 97, 17) Global $CheckBox26 = GUICtrlCreateCheckbox("LLLLLLLLL", 8, 336, 97, 17) GUICtrlCreateTabItem("") Global $CheckBoxAlwaysOnTop = GUICtrlCreateCheckbox("Always on Top", 8, 380, 97, 17) Global $btnReset = GUICtrlCreateButton("RESET", 104, 365, 75, 41) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $CheckBoxAlwaysOnTop _SetAlwaysOnTop() Case $btnReset For $i = 7 To 19 Step 1 ;Remove checked CheckBoxes GUICtrlSetState($CheckBox&$i, $GUI_UNCHECKED) Next For $i = 23 To 35 Step 1 GUICtrlSetState($CheckBox&$i, $GUI_UNCHECKED) Next GUICtrlSetData($InputCaseID1, "") GUICtrlSetData($InputCaseID2, "") EndSwitch WEnd Func _SetAlwaysOnTop() If GUICtrlRead($CheckBoxAlwaysOnTop) = $GUI_CHECKED Then WinSetOnTop($Form, "", 1) ;On top Else WinSetOnTop($Form, "", 0) ;Not on top EndIf EndFunc ;==>_SetAlwaysOnTop My question is: Why this For loop for GUICtrlSetState($CheckBox&$i, $GUI_UNCHECKED) does not work properly I have $CheckBox1, $CheckBox2.......till $CheckBox26 and with For $i = 1 To 26 it does not work. It only unchecks few of them, but not all. Later I have discovered that For $i = 7 To 19 removes $CheckBox1 to $CheckBox13 and For $i = 23 To 35 removes $CheckBox14 to $CheckBox26 Any idea why?
Moderators Melba23 Posted November 22, 2018 Moderators Posted November 22, 2018 stick3r, AutoIt uses an array to store the ControlIDs of its controls (the value returned by the GUICtrlCreate* call) and these ControlIDs are actually the index number of the control in that array. If you look at the actual values returned, you will see that they are in numerical order of creation, as you can see if you add these lines to your script: Global $CheckBox13 = GUICtrlCreateCheckbox("456456", 8, 336, 97, 17) GUICtrlCreateTabItem("TAB 2") Global $InputCaseID2 = GUICtrlCreateInput("", 80, 25, 80, 21) Global $lblCaseID = GUICtrlCreateLabel("Case ID", 8, 30, 68, 18) Global $CheckBox14 = GUICtrlCreateCheckbox("AAAAAAA", 8, 48, 110, 17) MsgBox(0, "ControlIDs", "$Checkbox13: " & @TAB & $CheckBox13 & @CRLF & _ "TAB2 goes here" & @CRLF & _ "$InputCaseID2: " & @TAB & $InputCaseID2 & @CRLF & _ "$lblCaseID:" & @TAB & $lblCaseID & @CRLF & _ "$CheckBox14: " & @TAB & $CheckBox14) Global $CheckBox15 = GUICtrlCreateCheckbox("PPPPPPPPP", 8, 72, 110, 17) I would suggest using arrays to hold the returned ControlIDs - that way life is very easy: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> ; Create an array to hold the returned ControlIDs <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Global $aCheckbox[27] ; Why 27? Because arrays start at 0 #Region ### START Koda GUI section ### Form= Global $Form = GUICreate("Checklist", 190, 407, 1233, 178) Global $text = "" Global $aCheckbox GUICtrlCreateTab(1, 1, 190, 365) GUICtrlCreateTabItem("TAB 1") Global $InputCaseID1 = GUICtrlCreateInput($text, 80, 25, 80, 21) Global $lblCaseID = GUICtrlCreateLabel("Case ID", 8, 30, 68, 18) ; Store the ControlIDs as the controls are created <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $aCheckbox[1] = GUICtrlCreateCheckbox("1111111", 8, 48, 110, 17) $aCheckbox[2] = GUICtrlCreateCheckbox("2222222", 8, 72, 110, 17) $aCheckbox[3] = GUICtrlCreateCheckbox("333333333", 8, 96, 110, 17) $aCheckbox[4] = GUICtrlCreateCheckbox("444444444", 8, 120, 110, 17) $aCheckbox[5] = GUICtrlCreateCheckbox("55555555", 8, 144, 110, 17) $aCheckbox[6] = GUICtrlCreateCheckbox("666666666", 8, 168, 110, 17) $aCheckbox[7] = GUICtrlCreateCheckbox("77777777", 8, 192, 150, 17) $aCheckbox[8] = GUICtrlCreateCheckbox("888888888", 8, 216, 150, 17) $aCheckbox[9] = GUICtrlCreateCheckbox("99999999", 8, 240, 110, 17) $aCheckbox[10] = GUICtrlCreateCheckbox("45646", 8, 264, 110, 17) $aCheckbox[11] = GUICtrlCreateCheckbox("4345634", 8, 288, 97, 17) $aCheckbox[12] = GUICtrlCreateCheckbox("4563456", 8, 312, 97, 17) $aCheckbox[13] = GUICtrlCreateCheckbox("456456", 8, 336, 97, 17) GUICtrlCreateTabItem("TAB 2") Global $InputCaseID2 = GUICtrlCreateInput("", 80, 25, 80, 21) Global $lblCaseID = GUICtrlCreateLabel("Case ID", 8, 30, 68, 18) $aCheckbox[14] = GUICtrlCreateCheckbox("AAAAAAA", 8, 48, 110, 17) $aCheckbox[15] = GUICtrlCreateCheckbox("PPPPPPPPP", 8, 72, 110, 17) $aCheckbox[16] = GUICtrlCreateCheckbox("BBBBBBBB", 8, 96, 110, 17) $aCheckbox[17] = GUICtrlCreateCheckbox("CCCCCCCCCCCCC", 8, 120, 110, 17) $aCheckbox[18] = GUICtrlCreateCheckbox("DDDDDDDDDDDDD", 8, 144, 110, 17) $aCheckbox[19] = GUICtrlCreateCheckbox("EEEEEEEEEE", 8, 168, 110, 17) $aCheckbox[20] = GUICtrlCreateCheckbox("FFFFFFFFFFF", 8, 192, 150, 17) $aCheckbox[21] = GUICtrlCreateCheckbox("GGGGGGGGGG", 8, 216, 150, 17) $aCheckbox[22] = GUICtrlCreateCheckbox("HHHHHHHHH", 8, 240, 110, 17) $aCheckbox[23] = GUICtrlCreateCheckbox("IIIIIIIII", 8, 264, 110, 17) $aCheckbox[24] = GUICtrlCreateCheckbox("JJJJJJJ", 8, 288, 97, 17) $aCheckbox[25] = GUICtrlCreateCheckbox("KKKKKKKKKKK", 8, 312, 97, 17) $aCheckbox[26] = GUICtrlCreateCheckbox("LLLLLLLLL", 8, 336, 97, 17) GUICtrlCreateTabItem("") Global $aCheckboxAlwaysOnTop = GUICtrlCreateCheckbox("Always on Top", 8, 380, 97, 17) Global $btnReset = GUICtrlCreateButton("RESET", 104, 365, 75, 41) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $aCheckboxAlwaysOnTop _SetAlwaysOnTop() Case $btnReset ; Now you can loop through them in a single loop <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< For $i = 1 To 26 ;Remove checked CheckBoxes GUICtrlSetState($aCheckbox[$i], $GUI_UNCHECKED) Next GUICtrlSetData($InputCaseID1, "") GUICtrlSetData($InputCaseID2, "") EndSwitch WEnd Func _SetAlwaysOnTop() If GUICtrlRead($aCheckboxAlwaysOnTop) = $GUI_CHECKED Then WinSetOnTop($Form, "", 1) ;On top Else WinSetOnTop($Form, "", 0) ;Not on top EndIf EndFunc ;==>_SetAlwaysOnTop Please ask if you have any questions. 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
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