Cravin Posted August 28, 2013 Share Posted August 28, 2013 Howdy, I've been digging around on the forums trying to find a good way to disable checkboxes using a radio button. Thanks to some information posted by BrewManNH, I've been able to successfully find a way to do this, however, I'd like to see if anyone has any thoughts on making the code I currently have less ugly - I've tried a few different things and I'm having a slightly difficult time trying to find a good way to cut down the length. Any help would be greatly appreciated! Specifically, I'd like help with the following items: 1) Converting the While loop near the bottom from If statements to Switch...Case or Select...Case so that I can add additional case statements (for other controls such as buttons, shortcut keys, etc if possible. 2) Using an array for $Checkbox1-10 to enable/disable the checkboxes versus having 10+ lines to do the same expandcollapse popup#include <GUIConstantsEx.au3> Global $Radio1,$Radio2,$Radio3,$Radio4,$Checkbox,$Checkbox1,$CheckBox2,$Checkbox3,$Checkbox4,$Checkbox5,$Checkbox6,$Checkbox7,$Checkbox8,$Checkbox9,$Checkbox10,$Main,$Radio1Status,$Radio2Status,$LastRadio1Status,$LastRadio2Status $Main = GUICreate("TEST", 432, 556, 212, 153) $Group2 = GUICtrlCreateGroup("", 24, 200, 377, 65) GUIStartGroup() $Radio1 = GUICtrlCreateRadio("Radio1", 56, 216, 129, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Radio2 = GUICtrlCreateRadio("Radio2", 248, 216, 105, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUIStartGroup() $Radio3 = GUICtrlCreateRadio("Radio3", 56, 240, 57, 17) $Radio4 = GUICtrlCreateRadio("Radio4", 120, 240, 65, 17) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlCreateGroup("", -99, -99, 1, 1) $Group3 = GUICtrlCreateGroup("", 24, 288, 377, 177) $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 72, 312, 89, 17) $Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 168, 312, 89, 17) $Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 272, 312, 97, 17) $Checkbox4 = GUICtrlCreateCheckbox("Checkbox4", 72, 336, 89, 17) $Checkbox5 = GUICtrlCreateCheckbox("Checkbox5", 168, 336, 89, 17) $Checkbox6 = GUICtrlCreateCheckbox("Checkbox6", 272, 336, 105, 17) $Checkbox7 = GUICtrlCreateCheckbox("Checkbox7", 72, 360, 89, 17) $Checkbox8 = GUICtrlCreateCheckbox("Checkbox8", 168, 360, 89, 17) $Checkbox9 = GUICtrlCreateCheckbox("Checkbox9", 72, 384, 89, 17) $Checkbox10 = GUICtrlCreateCheckbox("Checkbox10", 168, 384, 89, 17) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop $Radio1Status = GUICtrlRead($radio1) $Radio2Status = GUICtrlRead($radio2) If $Radio1Status = $GUI_CHECKED Then If $Radio1Status <> $LastRadio1Status Then $LastRadio1Status = $Radio1Status GUICtrlSetState($Checkbox1, $GUI_DISABLE) GUICtrlSetState($Checkbox2, $GUI_DISABLE) GUICtrlSetState($Checkbox3, $GUI_DISABLE) GUICtrlSetState($Checkbox4, $GUI_DISABLE) GUICtrlSetState($Checkbox5, $GUI_DISABLE) GUICtrlSetState($Checkbox6, $GUI_DISABLE) GUICtrlSetState($Checkbox7, $GUI_DISABLE) GUICtrlSetState($Checkbox8, $GUI_DISABLE) GUICtrlSetState($Checkbox9, $GUI_DISABLE) GUICtrlSetState($Checkbox10, $GUI_DISABLE) GUICtrlSetState($Radio3, $GUI_ENABLE) GUICtrlSetState($Radio4, $GUI_ENABLE) EndIf Else If $Radio1Status <> $LastRadio1Status Then $LastRadio1Status = $Radio1Status EndIf EndIf If $Radio2Status = $GUI_CHECKED Then If $Radio2Status <> $LastRadio2Status Then $LastRadio2Status = $Radio2Status GUICtrlSetState($Checkbox1, $GUI_ENABLE) GUICtrlSetState($Checkbox2, $GUI_ENABLE) GUICtrlSetState($Checkbox3, $GUI_ENABLE) GUICtrlSetState($Checkbox4, $GUI_ENABLE) GUICtrlSetState($Checkbox5, $GUI_ENABLE) GUICtrlSetState($Checkbox6, $GUI_ENABLE) GUICtrlSetState($Checkbox7, $GUI_ENABLE) GUICtrlSetState($Checkbox8, $GUI_ENABLE) GUICtrlSetState($Checkbox9, $GUI_ENABLE) GUICtrlSetState($Checkbox10, $GUI_ENABLE) GUICtrlSetState($Radio3, $GUI_DISABLE) GUICtrlSetState($Radio4, $GUI_DISABLE) GUICtrlSetState($Radio3, $GUI_UNCHECKED) GUICtrlSetState($Radio4, $GUI_UNCHECKED) EndIf Else If $Radio2Status <> $LastRadio2Status Then $LastRadio2Status = $Radio2Status EndIf EndIf WEnd Again, thanks in advance for any thoughts - and if any clarification is needed, please let me know! ~ Cravin Link to comment Share on other sites More sharing options...
TheSaint Posted August 28, 2013 Share Posted August 28, 2013 (edited) It can seem ugly, but it is effective. However, if you are concerned about number of lines, typing, copying etc, then one method is the Assign command inside a loop. i.e. For $a = 1 to 10 $checkbox = Assign("Checkbox" & $a) GuiCtrlSetState($checkbox, $GUI_DISABLE) Next Edited August 28, 2013 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Cravin Posted August 28, 2013 Author Share Posted August 28, 2013 Had to adjust the code a bit but the following worked for solving question #2, much obliged, TheSaint! For $a = 1 to 10 $checkbox = Assign("Checkbox" & $a, "", 2) GuiCtrlSetState($checkbox, $GUI_DISABLE) Next Now, how about for the first question, any thoughts? I need to be able to maintain the functionality of the radio buttons and checkboxes while adding additional "case" events. How can I format the While loop to add this? Link to comment Share on other sites More sharing options...
Solution BrewManNH Posted August 28, 2013 Solution Share Posted August 28, 2013 Try this. expandcollapse popup#include <GUIConstantsEx.au3> Global $Radio1, $Radio2, $Radio3, $Radio4, $Checkbox[11], $Checkbox1, $CheckBox2, $Checkbox3 Global $Checkbox4, $Checkbox5, $Checkbox6, $Checkbox7, $Checkbox8, $Checkbox9, $Checkbox10 Global $Main, $Radio1Status, $Radio2Status, $LastRadio1Status, $LastRadio2Status $Main = GUICreate("TEST", 432, 556, 212, 153) $Group2 = GUICtrlCreateGroup("", 24, 200, 377, 65) GUIStartGroup() $Radio1 = GUICtrlCreateRadio("Radio1", 56, 216, 129, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Radio2 = GUICtrlCreateRadio("Radio2", 248, 216, 105, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUIStartGroup() $Radio3 = GUICtrlCreateRadio("Radio3", 56, 240, 57, 17) $Radio4 = GUICtrlCreateRadio("Radio4", 120, 240, 65, 17) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlCreateGroup("", -99, -99, 1, 1) $Group3 = GUICtrlCreateGroup("", 24, 288, 377, 177) $CheckBox[1] = GUICtrlCreateCheckbox("Checkbox1", 72, 312, 89, 17) $CheckBox[2] = GUICtrlCreateCheckbox("Checkbox2", 168, 312, 89, 17) $CheckBox[3] = GUICtrlCreateCheckbox("Checkbox3", 272, 312, 97, 17) $CheckBox[4] = GUICtrlCreateCheckbox("Checkbox4", 72, 336, 89, 17) $CheckBox[5] = GUICtrlCreateCheckbox("Checkbox5", 168, 336, 89, 17) $CheckBox[6] = GUICtrlCreateCheckbox("Checkbox6", 272, 336, 105, 17) $CheckBox[7] = GUICtrlCreateCheckbox("Checkbox7", 72, 360, 89, 17) $CheckBox[8] = GUICtrlCreateCheckbox("Checkbox8", 168, 360, 89, 17) $CheckBox[9] = GUICtrlCreateCheckbox("Checkbox9", 72, 384, 89, 17) $CheckBox[10] = GUICtrlCreateCheckbox("Checkbox10", 168, 384, 89, 17) GUISetState() While GUIGetMsg() <> $GUI_EVENT_CLOSE $Radio1Status = GUICtrlRead($Radio1) $Radio2Status = GUICtrlRead($Radio2) If $Radio1Status = $GUI_CHECKED Then If $Radio1Status <> $LastRadio1Status Then $LastRadio1Status = $Radio1Status For $I = 1 to 10 GUICtrlSetState($Checkbox[$I], $GUI_DISABLE) Next GUICtrlSetState($Radio3, $GUI_ENABLE) GUICtrlSetState($Radio4, $GUI_ENABLE) EndIf Else If $Radio1Status <> $LastRadio1Status Then $LastRadio1Status = $Radio1Status EndIf EndIf If $Radio2Status = $GUI_CHECKED Then If $Radio2Status <> $LastRadio2Status Then $LastRadio2Status = $Radio2Status For $I = 1 to 10 GUICtrlSetState($Checkbox[$I], $GUI_ENABLE) Next GUICtrlSetState($Radio3, BitOR($GUI_DISABLE, $GUI_UNCHECKED)) GUICtrlSetState($Radio4, BitOR($GUI_DISABLE, $GUI_UNCHECKED)) EndIf Else If $Radio2Status <> $LastRadio2Status Then $LastRadio2Status = $Radio2Status EndIf EndIf WEnd If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Cravin Posted August 28, 2013 Author Share Posted August 28, 2013 That's definitely a more elegant solution, thanks BrewManNH! As always, I owe you. ~ Cravin Link to comment Share on other sites More sharing options...
TheSaint Posted August 28, 2013 Share Posted August 28, 2013 Yes, that's the other (main) way. However, Assign often gets lonely. Sorry about the parameters, I probably should have checked, rather than rely on my memory from older versions. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Cravin Posted August 28, 2013 Author Share Posted August 28, 2013 Not a problem Saint, I appreciate the feedback either way. Got me headed down a better path than the one I was on! 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