royalmarine Posted November 17, 2016 Share Posted November 17, 2016 Hi all, Here's my current code of a small project I'm working on. Is there an easier way of doing these checks? Ideally I need to be able to tick any of the boxes, and send a button press to the specific window, depending on which boxes are checked. But with the amount of if, elseIf statements, it's getting long and I think it might be best handled by an array and a for loop if possible? I've tried several attempts at a for loop and an array, but made a mess of it.. So, I've gone back to my default script below. Also, is it possible to put the ControlClick details into a variable? e.g. $t1 = test1.map $t2 = test2.map and then call it in ControlClick as follows ControlClick($t1, "" "[NAME:buttonInit]") expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> $Form1_1 = GUICreate("Contax Dispenser control", 615, 438, 192, 124) $Button1 = GUICtrlCreateButton("Init", 8, 8, 123, 41) $Button2 = GUICtrlCreateButton("Piston in Load Position", 8, 56, 123, 41) $Button3 = GUICtrlCreateButton("Piston in Dispens", 8, 104, 123, 41) $Button4 = GUICtrlCreateButton("Start toggle Piston", 8, 152, 123, 41) $Button5 = GUICtrlCreateButton("Close", 8, 200, 123, 41) $Button6 = GUICtrlCreateButton("Exit", 8, 248, 123, 41) $Checkbox1 = GUICtrlCreateCheckbox("Dispenser 1", 240, 16, 97, 17) $Checkbox2 = GUICtrlCreateCheckbox("Dispenser 2", 240, 48, 97, 17) $Checkbox3 = GUICtrlCreateCheckbox("Dispenser 3", 240, 80, 97, 17) $Checkbox4 = GUICtrlCreateCheckbox("Dispenser 4", 240, 112, 97, 17) $Checkbox5 = GUICtrlCreateCheckbox("Dispenser 5", 240, 144, 97, 17) $Checkbox6 = GUICtrlCreateCheckbox("Dispenser 6", 240, 176, 97, 17) $Checkbox7 = GUICtrlCreateCheckbox("Dispenser 7", 240, 208, 97, 17) $Checkbox8 = GUICtrlCreateCheckbox("Dispenser 8", 240, 240, 97, 17) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then Sleep(2000) ControlClick("test1.map", "", "[NAME:buttonInit]") ElseIf GUICtrlRead($Checkbox1) = $GUI_CHECKED And ($Checkbox2) = $GUI_CHECKED Then Sleep(2000) ControlClick("test1.map", "", "[NAME:buttonInit]") ControlClick("test2.map", "", "[NAME:buttonInit]") ElseIf GUICtrlRead($Checkbox1) = $GUI_CHECKED And ($Checkbox2) = $GUI_CHECKED And ($Checkbox3) = $GUI_CHECKED Then Sleep(2000) ControlClick("test1.map", "", "[NAME:buttonInit]") ControlClick("test2.map", "", "[NAME:buttonInit]") ControlClick("test3.map", "", "[NAME:buttonInit]") ElseIf GUICtrlRead($Checkbox1) = $GUI_CHECKED And ($Checkbox2) = $GUI_CHECKED And ($Checkbox3) = $GUI_CHECKED And ($Checkbox4) = $GUI_CHECKED Then Sleep(2000) ControlClick("test1.map", "", "[NAME:buttonInit]") ControlClick("test2.map", "", "[NAME:buttonInit]") ControlClick("test3.map", "", "[NAME:buttonInit]") ControlClick("test4.map", "", "[NAME:buttonInit]") ElseIf GUICtrlRead($Checkbox1) = $GUI_CHECKED And ($Checkbox2) = $GUI_CHECKED And ($Checkbox3) = $GUI_CHECKED And ($Checkbox4) = $GUI_CHECKED And ($Checkbox5) = $GUI_CHECKED Then Sleep(2000) ControlClick("test1.map", "", "[NAME:buttonInit]") ControlClick("test2.map", "", "[NAME:buttonInit]") ControlClick("test3.map", "", "[NAME:buttonInit]") ControlClick("test4.map", "", "[NAME:buttonInit]") ControlClick("test5.map", "", "[NAME:buttonInit]") ElseIf GUICtrlRead($Checkbox1) = $GUI_CHECKED And ($Checkbox2) = $GUI_CHECKED And ($Checkbox3) = $GUI_CHECKED And ($Checkbox4) = $GUI_CHECKED And ($Checkbox5) = $GUI_CHECKED And ($Checkbox6) = $GUI_CHECKED Then Sleep(2000) ControlClick("test1.map", "", "[NAME:buttonInit]") ControlClick("test2.map", "", "[NAME:buttonInit]") ControlClick("test3.map", "", "[NAME:buttonInit]") ControlClick("test4.map", "", "[NAME:buttonInit]") ControlClick("test5.map", "", "[NAME:buttonInit]") ControlClick("test6.map", "", "[NAME:buttonInit]") ElseIf GUICtrlRead($Checkbox1) = $GUI_CHECKED And ($Checkbox2) = $GUI_CHECKED And ($Checkbox3) = $GUI_CHECKED And ($Checkbox4) = $GUI_CHECKED And ($Checkbox5) = $GUI_CHECKED And ($Checkbox6) = $GUI_CHECKED And ($Checkbox7) = $GUI_CHECKED Then Sleep(2000) ControlClick("test1.map", "", "[NAME:buttonInit]") ControlClick("test2.map", "", "[NAME:buttonInit]") ControlClick("test3.map", "", "[NAME:buttonInit]") ControlClick("test4.map", "", "[NAME:buttonInit]") ControlClick("test5.map", "", "[NAME:buttonInit]") ControlClick("test6.map", "", "[NAME:buttonInit]") ControlClick("test7.map", "", "[NAME:buttonInit]") ElseIf GUICtrlRead($Checkbox1) = $GUI_CHECKED And ($Checkbox2) = $GUI_CHECKED And ($Checkbox3) = $GUI_CHECKED And ($Checkbox4) = $GUI_CHECKED And ($Checkbox5) = $GUI_CHECKED And ($Checkbox6) = $GUI_CHECKED And ($Checkbox7) = $GUI_CHECKED And ($Checkbox8) = $GUI_CHECKED Then Sleep(2000) ControlClick("test1.map", "", "[NAME:buttonInit]") ControlClick("test2.map", "", "[NAME:buttonInit]") ControlClick("test3.map", "", "[NAME:buttonInit]") ControlClick("test4.map", "", "[NAME:buttonInit]") ControlClick("test5.map", "", "[NAME:buttonInit]") ControlClick("test6.map", "", "[NAME:buttonInit]") ControlClick("test7.map", "", "[NAME:buttonInit]") ControlClick("test8.map", "", "[NAME:buttonInit]") Else MsgBox($MB_SYSTEMMODAL, "Warning", "You must select at least one dispenser.", 10) EndIf Case $Button2 Case $Button3 Case $Button4 Case $Button5 Case $Button6 Exit EndSwitch WEnd Link to comment Share on other sites More sharing options...
water Posted November 17, 2016 Share Posted November 17, 2016 (edited) Something like this? expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> Global $iDispensers = 8, $aCheckbox[$iDispensers], $iCountChecked = 0 $Form1_1 = GUICreate("Contax Dispenser control", 615, 438, 192, 124) $Button1 = GUICtrlCreateButton("Init", 8, 8, 123, 41) $Button2 = GUICtrlCreateButton("Piston in Load Position", 8, 56, 123, 41) $Button3 = GUICtrlCreateButton("Piston in Dispens", 8, 104, 123, 41) $Button4 = GUICtrlCreateButton("Start toggle Piston", 8, 152, 123, 41) $Button5 = GUICtrlCreateButton("Close", 8, 200, 123, 41) $Button6 = GUICtrlCreateButton("Exit", 8, 248, 123, 41) For $i = 0 To $iDispensers - 1 $aCheckbox[$i] = GUICtrlCreateCheckbox("Dispenser " & $i + 1, 240, ($i * 32) + 16, 97, 17) Next GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 For $i = 0 To UBound($aCheckbox, 1) - 1 If _IsChecked($aCheckbox[$i]) Then $iCountChecked += 1 Sleep(2000) ControlClick("test" & $i + 1 & ".map", "", "[NAME:buttonInit]") EndIf Next If $iCountChecked = 0 Then MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONWARNING), "Warning", "You must select at least one dispenser.", 10) Case $Button2 Case $Button3 Case $Button4 Case $Button5 Case $Button6 EndSwitch WEnd Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked Edited November 17, 2016 by water royalmarine 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
royalmarine Posted November 17, 2016 Author Share Posted November 17, 2016 Once again, thank you Link to comment Share on other sites More sharing options...
water Posted November 17, 2016 Share Posted November 17, 2016 Glad to be of service My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
royalmarine Posted November 17, 2016 Author Share Posted November 17, 2016 One quick one Water, If I wanted to add another checkbox to check / uncheck all the other checkboxes, would something like this do it? I assume not.. I probably need a new function to call on the GuiCtrlGetState of the current box? $CheckboxAll = GUICtrlCreateCheckbox("Enable all", 240, 272, 97, 17) Case $CheckboxAll For $i = 0 To UBound($aCheckbox, 1) - 1 If _IsChecked($aCheckbox[$i]) Then $iCountChecked += 1 GUICtrlSetState ($aCheckbox, $GUI_CHECKED) EndIf Next Link to comment Share on other sites More sharing options...
water Posted November 17, 2016 Share Posted November 17, 2016 With the following modification you can enable/disable all other checkboxes: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> Global $iDispensers = 8, $aCheckbox[$iDispensers], $iCountChecked = 0 $Form1_1 = GUICreate("Contax Dispenser control", 615, 438, 192, 124) $Button1 = GUICtrlCreateButton("Init", 8, 8, 123, 41) $Button2 = GUICtrlCreateButton("Piston in Load Position", 8, 56, 123, 41) $Button3 = GUICtrlCreateButton("Piston in Dispens", 8, 104, 123, 41) $Button4 = GUICtrlCreateButton("Start toggle Piston", 8, 152, 123, 41) $Button5 = GUICtrlCreateButton("Close", 8, 200, 123, 41) $Button6 = GUICtrlCreateButton("Exit", 8, 248, 123, 41) For $i = 0 To $iDispensers - 1 $aCheckbox[$i] = GUICtrlCreateCheckbox("Dispenser " & $i + 1, 240, ($i * 32) + 16, 97, 17) Next $CheckboxAll = GUICtrlCreateCheckbox("Enable/Disable all", 240, 272, 110, 17) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $CheckboxAll $bCheckAll = _IsChecked($CheckboxAll) For $i = 0 To UBound($aCheckbox, 1) - 1 If $bCheckAll Then GUICtrlSetState($aCheckbox[$i], $GUI_CHECKED) Else GUICtrlSetState($aCheckbox[$i], $GUI_UNCHECKED) EndIf Next Case $Button1 For $i = 0 To UBound($aCheckbox, 1) - 1 If _IsChecked($aCheckbox[$i]) Then $iCountChecked += 1 Sleep(2000) ControlClick("test" & $i + 1 & ".map", "", "[NAME:buttonInit]") EndIf Next If $iCountChecked = 0 Then MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONWARNING), "Warning", "You must select at least one dispenser.", 10) Case $Button2 Case $Button3 Case $Button4 Case $Button5 Case $Button6 EndSwitch WEnd Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
royalmarine Posted November 17, 2016 Author Share Posted November 17, 2016 I was way off.... >.< thanks! Link to comment Share on other sites More sharing options...
water Posted November 17, 2016 Share Posted November 17, 2016 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki 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