dadamoid Posted November 15, 2007 Share Posted November 15, 2007 I have written a script that creates a GUI with about 50 checkboxes - each one is assigned a variable for processing later. If the user makes a mistake and wants to clear the form.... Is there a way I can easily clear ALL of them without using GUISetState for each one? Thanks Link to comment Share on other sites More sharing options...
Valuater Posted November 15, 2007 Share Posted November 15, 2007 using an array for the checkboxes would help Example... expandcollapse popup#include <GUIConstants.au3> Global $Checkbox[8] ; == GUI generated with Koda == $Miner1 = GUICreate("Conquer Online Auto Miner - Soemaal ~ Elitepvpers.de ©2007 ", 492, 366, 225, 176) GUISetIcon("C:\Program Files\Conquer 2.0\tqzf.ico") GUISetCursor(3) GUISetFont(12, 400, 0, "Times New Roman") GUISetBkColor(0x9DB9EB) $Checkbox[1] = GUICtrlCreateCheckbox("Refine Gem", 24, 64, 153, 33) GUICtrlSetFont(-1, 12, 400, 0, "Times New Roman") GUICtrlSetBkColor(-1, 0x9DB9EB) $Checkbox[2] = GUICtrlCreateCheckbox("Normal Gem", 24, 24, 145, 41) GUICtrlSetFont(-1, 12, 400, 0, "Times New Roman") GUICtrlSetBkColor(-1, 0x9DB9EB) $Checkbox[3] = GUICtrlCreateCheckbox("Super Gem", 24, 96, 169, 33) GUICtrlSetFont(-1, 12, 400, 0, "Times New Roman") GUICtrlSetBkColor(-1, 0x9DB9EB) $Group1 = GUICtrlCreateGroup("Disconnect at", 16, 8, 185, 145) GUICtrlSetFont(-1, 12, 400, 0, "Times New Roman") GUICtrlSetBkColor(-1, 0x9DB9EB) GUICtrlCreateGroup("", -99, -99, 1, 1) $Checkbox[4] = GUICtrlCreateCheckbox("All ores", 264, 24, 145, 33) GUICtrlSetFont(-1, 12, 400, 0, "Times New Roman") GUICtrlSetBkColor(-1, 0x9DB9EB) $Checkbox[5] = GUICtrlCreateCheckbox("Iron/Copper ore", 264, 56, 145, 33) GUICtrlSetFont(-1, 12, 400, 0, "Times New Roman") GUICtrlSetBkColor(-1, 0x9DB9EB) $Checkbox[6] = GUICtrlCreateCheckbox("Iron/Silver ore", 264, 88, 153, 33) GUICtrlSetFont(-1, 12, 400, 0, "Times New Roman") GUICtrlSetBkColor(-1, 0x9DB9EB) $Checkbox[7] = GUICtrlCreateCheckbox("Gold ore", 264, 112, 161, 33) GUICtrlSetFont(-1, 12, 400, 0, "Times New Roman") GUICtrlSetBkColor(-1, 0x9DB9EB) $Group2 = GUICtrlCreateGroup("Ores to Drop", 248, 8, 177, 145) GUICtrlSetFont(-1, 12, 400, 0, "Times New Roman") GUICtrlSetBkColor(-1, 0x9DB9EB) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateLabel("Soemaal's autominer V1.0 Basic oredropper.", 16, 160, 185, 187) GUICtrlSetFont(-1, 12, 400, 0, "Times New Roman") GUICtrlSetBkColor(-1, 0x9DB9EB) $Button = GUICtrlCreateButton("Clear", 300, 230, 100, 50) $Button1 = GUICtrlCreateButton("Done", 300, 300, 100, 50) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button For $x = 1 To UBound($Checkbox) - 1 GUICtrlSetState($Checkbox[$x], $GUI_UNCHECKED) Next Case $msg = $Button1 For $x = 1 To UBound($Checkbox) - 1 If _IsChecked($Checkbox[$x]) Then ; do what you wqant MsgBox(0x0, "Checked", GUICtrlRead($Checkbox[$x], 1) & " was checked", 2) EndIf Next Case Else ;;;;;;; EndSelect WEnd Exit Func _IsChecked($control) Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked 8) Link to comment Share on other sites More sharing options...
dani Posted November 15, 2007 Share Posted November 15, 2007 (edited) I have written a script that creates a GUI with about 50 checkboxes - each one is assigned a variable for processing later. If the user makes a mistake and wants to clear the form.... Is there a way I can easily clear ALL of them without using GUISetState for each one? Thanks I think my example is a bit easier to read with all due respect to Valuater And I'm using DummyControls, which to me are a great way to manage stuff like this. expandcollapse popup#include <GUIConstants.au3> $GUI = GUICreate("There once were 50 checkboxes", 200, 850) $CheckboxesStart = GUICtrlCreateDummy() ; ==> Notice the start For $i = 0 To 49 GUICtrlCreateCheckbox("Checkbox " & $i+1, 0,0+($i*17)) ; ==> Obviously I'm not going to create 50 variables for 50 checkboxes cause this is just for showing how to check every single one. Next ; I read you do, so be sure to create all checkboxes at the same place and surround them by 2 dummy controls. $CheckboxesStop = GUICtrlCreateDummy() ; ==> Notice the end $CheckAll = GUICtrlCreateButton("Check all", 100, 100) $UnCheckAll = GUICtrlCreateButton("Uncheck all", 100, 130) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $CheckAll For $i = $CheckboxesStart to $CheckboxesStop ; ==> Looping through every checkbox GUICtrlSetState($i, $GUI_CHECKED) Next Case $UnCheckAll For $i = $CheckboxesStart to $CheckboxesStop ; ==> Looping through every checkbox GUICtrlSetState($i, $GUI_UNCHECKED) Next Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() ; Daniel ; Ps. If you are going to use an array instead, use For $checkbox In $Checkboxes ; ==> The array is called $Checkboxes, $checkbox is the variable assigned to each value in the array during the loop GUICtrlSetState($checkbox, $GUI_CHECKED) Next Edited November 15, 2007 by D4ni Link to comment Share on other sites More sharing options...
dadamoid Posted November 15, 2007 Author Share Posted November 15, 2007 Thanks Guys. I had already used a loop and array to create the majority of the checkboxes, and managed to clear them too, but the remainder all have unique variable names assigned (coz they need them for processing later) so I was really wondering if there was some Global way of clearing all checkboxes, but I guess there isn't. I'm just lazy so I didn't want to write loads of code just for this simple feature. Never mind. Thanks Anyway. Link to comment Share on other sites More sharing options...
dani Posted November 15, 2007 Share Posted November 15, 2007 Thanks Guys. I had already used a loop and array to create the majority of the checkboxes, and managed to clear them too, but the remainder all have unique variable names assigned (coz they need them for processing later) so I was really wondering if there was some Global way of clearing all checkboxes, but I guess there isn't.I'm just lazy so I didn't want to write loads of code just for this simple feature.Never mind.Thanks Anyway.I wouldn't call a For loop and two DummyControls lots of code 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