faldo Posted March 18, 2009 Share Posted March 18, 2009 I know this might be considered a newbie question but i've just learnet arrays and have some trouble applying the functionality to my ideas. If i have a bunch of checkboxes in a GUI, how can i make it so that $msg catches ANY change in state, without having $msg check every single checkbox for change? I'm sure there is a way to put the following code into an array... the thing i can't figure out is how to make the GUIgetmsg() to react on ANY box being checked. I was about to post in the GUI-support forum but i think this is an array-problem #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $check1,$check2,$check3,$check4,$check5, $msg GUICreate("My GUI Checkbox") ; will create a dialog box that when displayed is centered $check1 = GUICtrlCreateCheckbox("CHECKBOX 1", 10, 10, 120, 20) $check2 = GUICtrlCreateCheckbox("CHECKBOX 2", 20, 30, 120, 20) $check3 = GUICtrlCreateCheckbox("CHECKBOX 3", 50, 60, 120, 20) $check4 = GUICtrlCreateCheckbox("CHECKBOX 4", 12, 90, 120, 20) $check5 = GUICtrlCreateCheckbox("CHECKBOX 5", 17, 120, 120, 20) GUISetState() ; will display an dialog box with 1 checkbox ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $check1 then MsgBox(0, "", "Checkbox1 was checked") If $msg = $check2 then MsgBox(0, "", "Checkbox2 was checked") If $msg = $check3 then MsgBox(0, "", "Checkbox3 was checked") If $msg = $check4 then MsgBox(0, "", "Checkbox4 was checked") If $msg = $check5 then MsgBox(0, "", "Checkbox5 was checked") If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>Example Check out my other scripts: RDP antihammer/blacklist generator | Phemex cryptocurrency exchange API Link to comment Share on other sites More sharing options...
Authenticity Posted March 18, 2009 Share Posted March 18, 2009 Using Opt('GuiOnEventMode', 1) and not using a message loop. You can then use GuiCtrlSetOnEvent for each CheckBox. Inside your function you can differentiate between them using the @GUI_CTRLID macro or do some test like: . . . If BitAND(GUICtrlRead(@GUI_CTRLID), $GUI_CHECKED) Then ... This way you don't need array at all. If.. applicable. ;] Link to comment Share on other sites More sharing options...
Mat Posted March 18, 2009 Share Posted March 18, 2009 Do you want to make it so it reacts when the checkbox is marked or do you want it so when another button is pressed it tells you wich check boxes are ticked...if you want it to react to the checkbox being marked then look at GUIOnEvent...I'm no expert but I'm failure sure that has something...If you want it to know if the box is checked on a seperate event (button etc.) then GUICtrlRead will work.check outhttp://www.autoitscript.com/forum/index.ph...hl=GUI+on+eventMDiesel AutoIt Project Listing Link to comment Share on other sites More sharing options...
faldo Posted March 18, 2009 Author Share Posted March 18, 2009 (edited) I acctually just wanted to clean up the code abit and create one response to all the checkboxes, in the real script there are a lot more checkboxes. Would it be a bad idea to put a tight for-loop to solve the problem? #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $check[10], $msg GUICreate("My GUI Checkbox"); will create a dialog box that when displayed is centered $check[1] = GUICtrlCreateCheckbox("CHECKBOX 1", 10, 10, 120, 20) $check[2] = GUICtrlCreateCheckbox("CHECKBOX 2", 20, 30, 120, 20) $check[3] = GUICtrlCreateCheckbox("CHECKBOX 3", 50, 60, 120, 20) $check[4] = GUICtrlCreateCheckbox("CHECKBOX 4", 12, 90, 120, 20) $check[5] = GUICtrlCreateCheckbox("CHECKBOX 5", 17, 120, 120, 20) GUISetState(); will display an dialog box with 1 checkbox ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() For $i=1 to 5 If $msg = $check[$i] then MsgBox(0, "", "Checkbox "&$i&" was checked/unchecked") Next If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc;==>Example Edited March 18, 2009 by faldo Check out my other scripts: RDP antihammer/blacklist generator | Phemex cryptocurrency exchange API Link to comment Share on other sites More sharing options...
Drew Posted March 18, 2009 Share Posted March 18, 2009 GUIOnEvent > For loop. Link to comment Share on other sites More sharing options...
faldo Posted March 18, 2009 Author Share Posted March 18, 2009 If i understand it corectly, GUIonEvent needs one line per checkbox right? so if i have 200 checkboxes i'll need 200 GUIonEvent or 4 lines of For-loop code? Are you guys sure there isn't a better way to do it? Check out my other scripts: RDP antihammer/blacklist generator | Phemex cryptocurrency exchange API Link to comment Share on other sites More sharing options...
Drew Posted March 18, 2009 Share Posted March 18, 2009 200 checkboxes? Thats alot of options lol. But often times noone needs 200 checkboxes, so thats never really an issue. To my knoweledge.. No thats just about it. But I'll look into it in a sec if noone with a bit more experience steps up to the plate. Link to comment Share on other sites More sharing options...
faldo Posted March 18, 2009 Author Share Posted March 18, 2009 (edited) I'm not using 200 checkboxes, that was just an example while hopeing i could use arrays... however, every event that i need to enter for each checkbox is a few lines of code and i have 20 checkboxes... with the for-loop i can remain at about 10 lines for 20 events, with GuiOnEvent i'll need about 200 lines of code to manage. Hope you understand my point of view Edited March 18, 2009 by faldo Check out my other scripts: RDP antihammer/blacklist generator | Phemex cryptocurrency exchange API Link to comment Share on other sites More sharing options...
Spiff59 Posted March 19, 2009 Share Posted March 19, 2009 (edited) You can spit out, "auto-position", and scan plenty of indexed checkboxes without much code. You could proess the checkboxes in various ways, probably determined by how similar the processing for the chechboxes are to one another. expandcollapse popup#include <GUIConstants.au3> Global $Checkbox[64] Dim $left = 20, $top = 0 GuiCreate("My Pgm", 340, 380) For $i = 0 to 63; Create an array of indexed checkboxes $top += 20 If $top > 320 Then $top = 20 $left += 80 EndIf $Checkbox[$i] = GUICtrlCreateCheckbox("Port " & $i, $left, $top) Next $Scan_Button = GUICtrlCreateButton("SCAN", 20, 350,40,20) GUISetState() ;------------------------------------------------------------------------- While 1 Switch GUIGetMsg() Case $Scan_Button Scan_Checkboxes() Case -3; $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Exit ;------------------------------------------------------------------------- Func Scan_Checkboxes() For $i = 0 to 63; Scan all checkboxes If GUICtrlRead($CheckBox[$i]) = $GUI_CHECKED Then MsgBox(1,"", "Box " & $i & " is checked.") Call("Process_Box" & $i) EndIf Next EndFunc Func Process_Box1() MsgBox(1,"","Im doing what I do when Box 1 is clicked") EndFunc Func Process_Box5() MsgBox(1,"","Im doing what I do when Box 5 is clicked") EndFunc Func Process_Box12() MsgBox(1,"","Im doing what I do when Box 12 is clicked") EndFunc Edit: A separate process function for each checkbox might not be necessary for you... Edited March 19, 2009 by Spiff59 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