SinSoul Posted June 2, 2011 Posted June 2, 2011 (edited) Hello everyone. I've just joined the community and also just started using autoit. I'm really new to it, so please don't judge me too heavily. In any case, here's my question: I got multiple Checkboxes situated over Buttons. I have script manipulating checkbox(on button click checkbox will be checked or unchecked, depending on condition). Is there a way to do that with all checkboxes using arrays and for statement? Or any other method? Here's what I came up with(of course not working): Global $BUTTON[5] Global $CHECKBOX[5] $BUTTON[1] = EZSKINBUTTON("button1", 35, 60, 75, 30) $CHECKBOX1 = GUICtrlCreateCheckbox("", 85, 70, 10, 10) $BUTTON[2] = EZSKINBUTTON("button2", 35, 100, 100, 30) $CHECKBOX[2] = GUICtrlCreateCheckbox("", 85, 110, 10, 10) $BUTTON[3] = EZSKINBUTTON("button3", 35, 140, 100, 30) $CHECKBOX[3] = GUICtrlCreateCheckbox("", 85, 150, 10, 10) $BUTTON[4] = EZSKINBUTTON("button4", 35, 180, 100, 30) While 1 EZSKINOVER() $MSG = GUIGetMsg() For $i = 1 to 6 Step +1 If $MSG = $BUTTON[$i] Then If GUICtrlRead($CHECKBOX[$i] = $GUI_CHECKED Then GUICtrlSetState($CHECKBOX[$i], $GUI_UNCHECKED) Else GUICtrlSetState($CHECKBOX[$i], $GUI_CHECKED) EndIf EndIf Next WEnd #endregion Or do I have to declare each set manually? :S Any help would be appreciated. Thank you in advance. Edited June 2, 2011 by SinSoul
SinSoul Posted June 2, 2011 Author Posted June 2, 2011 Please close the topic...I had silly code mistake If GUICtrlRead($CHECKBOX[$i][color="#FF0000"])[/color] = $GUI_CHECKED Then Forgot the close the bracet
czardas Posted June 2, 2011 Posted June 2, 2011 (edited) Please close the topic...I had silly code mistake Too late, I just created an example: #include <GuiConstants.au3> Local $hGUI = GUICreate("Check Boxes", 210, 100) Local $ahCheckBox[4] = ["CH0","CH1","CH2","CH3"], $iLeft = 10, $iTop = 10 For $i = 0 To 3 $ahCheckBox[$i] = GUICtrlCreateCheckbox($ahCheckBox[$i], $iLeft, $iTop, 45, 14) $iLeft += 50 Next Local $hButton = GUICtrlCreateButton("Check/Uncheck", 50, 45, 95) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop ElseIf $msg = $hButton Then _CheckBoxToggle($ahCheckBox) EndIf WEnd Func _CheckBoxToggle($ahCheckBox) For $i = 0 To UBound ($ahCheckBox) -1 If GUICtrlRead($ahCheckBox[$i]) = $GUI_UNCHECKED Then GUICtrlSetState($ahCheckBox[$i], $GUI_CHECKED) Else GUICtrlSetState($ahCheckBox[$i], $GUI_UNCHECKED) EndIf Next EndFunc Edited June 2, 2011 by czardas operator64 ArrayWorkshop
SinSoul Posted June 2, 2011 Author Posted June 2, 2011 Too late, I just created an example: #include <GuiConstants.au3> Local $hGUI = GUICreate("Check Boxes", 210, 100) Local $ahCheckBox[4] = ["CH0","CH1","CH2","CH3"], $iLeft = 10, $iTop = 10 For $i = 0 To 3 $ahCheckBox[$i] = GUICtrlCreateCheckbox($ahCheckBox[$i], $iLeft, $iTop, 45, 14) $iLeft += 50 Next Local $hButton = GUICtrlCreateButton("Check/Uncheck", 50, 45, 95) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop ElseIf $msg = $hButton Then _CheckBoxToggle($ahCheckBox) EndIf WEnd Func _CheckBoxToggle($ahCheckBox) For $i = 0 To UBound ($ahCheckBox) -1 If GUICtrlRead($ahCheckBox[$i]) = $GUI_UNCHECKED Then GUICtrlSetState($ahCheckBox[$i], $GUI_CHECKED) Else GUICtrlSetState($ahCheckBox[$i], $GUI_UNCHECKED) EndIf Next EndFunc Thank you very much! Even though I've found a problem, but still your example probably 100 times more effective.
Casey Posted June 2, 2011 Posted June 2, 2011 Too late, I just created an exampleNow that is slick. I never gave thought to build out controls like that. Thanks for the insight.Casey
czardas Posted June 2, 2011 Posted June 2, 2011 No worries. Also welcome to the forum. operator64 ArrayWorkshop
SinSoul Posted June 2, 2011 Author Posted June 2, 2011 No worries. Also welcome to the forum. Thank you =) btw your code works like a charm. Used it also to generate buttons. I'm getting to love AutoIt xD Also thank you for fast reply===case solved===
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