gfunk999 Posted August 21, 2008 Share Posted August 21, 2008 (edited) Hi All, I'm having a tough time clearing all boxes with my code... Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded, I know what this means, but I don't see where I exceeded the range. If I clear doesn't that mean I'm resetting the variable to uncheck state? expandcollapse popup#include <GUIConstants.au3> Local $Checkbox[5] $i = -1 $Form1 = GUICreate("Form1", 290, 278, 193, 115) $Checkbox[0] = GUICtrlCreateCheckbox("Checkbox1", 32, 32, 97, 17) $Checkbox[1] = GUICtrlCreateCheckbox("Checkbox2", 32, 56, 97, 17) $Checkbox[2] = GUICtrlCreateCheckbox("Checkbox3", 32, 80, 97, 17) $Checkbox[3] = GUICtrlCreateCheckbox("Checkbox4", 32, 104, 97, 17) $Checkbox[4] = GUICtrlCreateCheckbox("Checkbox5", 32, 128, 97, 17) $Button1 = GUICtrlCreateButton("Check All", 16, 216, 75, 25, 0) $Button2 = GUICtrlCreateButton("Clear All", 104, 216, 75, 25, 0) $Button3 = GUICtrlCreateButton("Cancel", 192, 216, 75, 25, 0) GUISetState(@SW_SHOW) $nMsg = 0 While $nMsg <> $GUI_EVENT_CLOSE $nMsg = GUIGetMsg() Select Case $nMsg = $Button3 ExitLoop Case $nMsg = $Button2 Do $i = $i + 1 GUICtrlSetState($Checkbox[$i], $GUI_UNCHECKED) Until $i = 4 Case $nMsg = $Button1 Do $i = $i + 1 GUICtrlSetState($Checkbox[$i], $GUI_CHECKED) Until $i = 4 EndSelect WEnd Edited August 21, 2008 by gfunk999 Link to comment Share on other sites More sharing options...
dbzfanatic Posted August 21, 2008 Share Posted August 21, 2008 (edited) Your problem seems to be that $i is staying at 4 every time, thus you're trying to call $Checkbox[5] every time you click another button. Try adding $i = 0 under your Until lines. Edit: Just tried it with the $i = 0, works perfectly. Edited August 21, 2008 by dbzfanatic Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
gfunk999 Posted August 21, 2008 Author Share Posted August 21, 2008 Oh the array builds from 4 lol that worked thank you Your problem seems to be that $i is staying at 4 every time, thus you're trying to call $Checkbox[5] every time you click another button. Try adding $i = 0 under your Until lines. Edit: Just tried it with the $i = 0, works perfectly. Link to comment Share on other sites More sharing options...
dbzfanatic Posted August 21, 2008 Share Posted August 21, 2008 Oh the array builds from 4 lol that worked thank you No problem, also try instead of using the Do ... Until use For $i = 0 To 4 ... Next for the steps. Here's a bit of a cleaned-up version of your code. Using Swtich seems easier than Select, at least IMO. #include <GUIConstants.au3> Local $Checkbox[5] Dim $i $Form1 = GUICreate("Form1", 290, 278, 193, 115) $Checkbox[0] = GUICtrlCreateCheckbox("Checkbox1", 32, 32, 97, 17) $Checkbox[1] = GUICtrlCreateCheckbox("Checkbox2", 32, 56, 97, 17) $Checkbox[2] = GUICtrlCreateCheckbox("Checkbox3", 32, 80, 97, 17) $Checkbox[3] = GUICtrlCreateCheckbox("Checkbox4", 32, 104, 97, 17) $Checkbox[4] = GUICtrlCreateCheckbox("Checkbox5", 32, 128, 97, 17) $Button1 = GUICtrlCreateButton("Check All", 16, 216, 75, 25, 0) $Button2 = GUICtrlCreateButton("Clear All", 104, 216, 75, 25, 0) $Button3 = GUICtrlCreateButton("Cancel", 192, 216, 75, 25, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button3 ExitLoop Case $Button2 For $i = 0 To 4 GUICtrlSetState($Checkbox[$i], $GUI_UNCHECKED) Next $i = 0 Case $Button1 For $i = 0 To 4 GUICtrlSetState($Checkbox[$i], $GUI_CHECKED) Next $i = 0 EndSwitch WEnd Dim $i sets $i to 0 by default and with Switch you don't need to add the $nMsg = to your case statements. Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
gfunk999 Posted August 21, 2008 Author Share Posted August 21, 2008 Very Cool thanks again... Just modified it. No problem, also try instead of using the Do ... Until use For $i = 0 To 4 ... Next for the steps. Here's a bit of a cleaned-up version of your code. Using Swtich seems easier than Select, at least IMO. #include <GUIConstants.au3> Local $Checkbox[5] Dim $i $Form1 = GUICreate("Form1", 290, 278, 193, 115) $Checkbox[0] = GUICtrlCreateCheckbox("Checkbox1", 32, 32, 97, 17) $Checkbox[1] = GUICtrlCreateCheckbox("Checkbox2", 32, 56, 97, 17) $Checkbox[2] = GUICtrlCreateCheckbox("Checkbox3", 32, 80, 97, 17) $Checkbox[3] = GUICtrlCreateCheckbox("Checkbox4", 32, 104, 97, 17) $Checkbox[4] = GUICtrlCreateCheckbox("Checkbox5", 32, 128, 97, 17) $Button1 = GUICtrlCreateButton("Check All", 16, 216, 75, 25, 0) $Button2 = GUICtrlCreateButton("Clear All", 104, 216, 75, 25, 0) $Button3 = GUICtrlCreateButton("Cancel", 192, 216, 75, 25, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button3 ExitLoop Case $Button2 For $i = 0 To 4 GUICtrlSetState($Checkbox[$i], $GUI_UNCHECKED) Next $i = 0 Case $Button1 For $i = 0 To 4 GUICtrlSetState($Checkbox[$i], $GUI_CHECKED) Next $i = 0 EndSwitch WEnd Dim $i sets $i to 0 by default and with Switch you don't need to add the $nMsg = to your case statements. Link to comment Share on other sites More sharing options...
dbzfanatic Posted August 21, 2008 Share Posted August 21, 2008 No problem, glad to help . Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
gfunk999 Posted August 21, 2008 Author Share Posted August 21, 2008 One more question if you don't mind, how would go about executing all selected checkboxes and perform an action once i.e. an OK button is pressed. I'll post my code as soon as I'm done, but I know is dirty. :|Very Cool thanks again... Just modified it. Link to comment Share on other sites More sharing options...
dbzfanatic Posted August 21, 2008 Share Posted August 21, 2008 (edited) There are a few ways to do this. The one I use normally is a bit intensive but it works. Here's an example. Case $btnOk If GuiCtrlRead($CheckBox[0]) = $GUI_CHECKED Then *insert code here* EndIf If GuiCtrlRead($CheckBox[1]) = $GUI_CHECKED Then *insert code here* ... EndIf You could also probably send messages to the GUI but I'm not sure how to do that. Edited August 21, 2008 by dbzfanatic Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
gfunk999 Posted August 21, 2008 Author Share Posted August 21, 2008 Cool, what i'm trying to do is pass the result of read for each checkbox, and based on that I will carry out the code. Kind of tedious, I'm still looking for a better solution. I'll give yours a try, thanks again for the quick reply $cr1 = GUICtrlRead($Checkbox[0]) $cr2 = GUICtrlRead($Checkbox[1]) $cr3 = GUICtrlRead($Checkbox[2]) $cr4 = GUICtrlRead($Checkbox[3]) There are a few ways to do this. The one I use normally is a bit intensive but it works. Here's an example. Case $btnOk If GuiCtrlRead($CheckBox[0]) = $GUI_CHECKED Then *insert code here* ElseIf GuiCtrlRead($CheckBox[1]) = $GUI_CHECKED Then *insert code here* ... End Or you could use seperate If statements for each. You could also probably send messages to the GUI but I'm not sure how to do that. Link to comment Share on other sites More sharing options...
dbzfanatic Posted August 21, 2008 Share Posted August 21, 2008 (edited) I kinda goofed a bit on my first post (not enough coffeee). You do need to use separate If statements for each otherwise it will only carry out the first condition it finds and nothing else. So if boxes 1 and 4 are checked it will execute the code for box 1 but not box 4. I also had an idea that may or may not work. Try something like Case $btnOk For $i = 0 To 4 $cr[$i] = GuiCtrlRead($CheckBox[$i]) Next $i = 0 Call Function($cr) Func Function($value) For $i = 0 To 4 If $value[$i] = 1 Then If $i = 0 Then ;do something here for checkbox one EndIf If $i = 1 Then ;do something here for checkbox two Endif EndIf Next EndFunc Edit: Made code a bit more in-depth. Hopefully this will help. Edited August 21, 2008 by dbzfanatic Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
gfunk999 Posted August 21, 2008 Author Share Posted August 21, 2008 (edited) That work I modified it a bit...but I still think there's a cleaner way of doing it. Thanks again dbzfanatic Case $Button4 For $i = 0 To 4 $cr[$j] = GuiCtrlRead($CheckBox[$i]) If $cr[$j] = 1 Then If $i = 0 Then MsgBox(0, "1", "checkbox1") EndIf If $i = 1 Then MsgBox(0, "2", "checkbox2") EndIf If $i = 2 Then MsgBox(0, "3", "checkbox3") EndIf If $i = 3 Then MsgBox(0, "4", "checkbox4") EndIf If $i = 4 Then MsgBox(0, "5", "checkbox5") EndIf EndIf Next $i = 0 Edited August 21, 2008 by gfunk999 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