LurchMan Posted March 1, 2009 Posted March 1, 2009 (edited) the title kind of gives it away huh? What im trying to achieve here is I have multiple check boxes, and once they are clicked on they become hidden and disabled. I was wondering if it is possible or if anyone knows of an esier way than how im doing it , to read each check box and see if they are checked. My Current Code: Global $Cats1 = False, $Cats2 = False, $Cats3 = False, $Cats4 = False Global $Cats5 = False, $Cats6 = False, $Cats7 = False, $Cats8 = False, $Cats9 = False Global $aCats[9] = [$Q1, $Q2, $Q3, $Q4, $Q5, $Q6, $Q7, $Q8, $Q9] Global $abCats[9] = [$Cats1, $Cats2, $Cats3, $Cats4, $Cats5, $Cats6, $Cats7, $Cats8, $Cats9] For $n = 0 To UBound ($aCats) - 1 $read = BitAND(GUICtrlGetState ($aCats[$n]), $GUI_CHECKED) msgbox (0, "", $read) ;I put this here as a simple debugging If BitAND(GUICtrlRead ($aCats[$n]), $GUI_CHECKED) = True Then $abCats[$n] = True Next If $Cats1 And $Cats2 And $Cats3 And $Cats4 And _ $Cats5 And $Cats6 And $Cats7 And $Cats8 And $Cats9 = True Then $Msg = MsgBox (52, "Cats Game!", "Cats Games! No one wins!" & @LF & _ "Would you like to play again?") If $Msg = 6 Then _PlayAgain () EndIF EndIF When the message box comes up the return is 0 (Failed according to the help file), and I cant see any reason for it to fail like this other than possibly the fact that the control is hidden. All help will be appreciated, and the wall will appreciate it as well cause ill stop banging my head on it.... Edit: It also returns 0 for the ones that havent been clicked yet Edited March 1, 2009 by LurchMan Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.
Moderators Melba23 Posted March 1, 2009 Moderators Posted March 1, 2009 lurchman,2 main problems:1. From that ever helpful Helpfile:GUICtrlGetState: As opposed to GUICtrlRead this function returns ONLY the state of a control enabled/disabled/hidden/show/dropacceptedGUICtrlRead : Checkbox, Radio - state of the button 2. You need to revise how to address elements in an array:Global $abCats[9] = [$Cats1, $Cats2, $Cats3, $Cats4, $Cats5, $Cats6, $Cats7, $Cats8, $Cats9] sets the elements $abCats[0] to $abcats[8] to the variables $Cats1 to $Cats9 respectively.When you want to read those elements, you need to use $abCats[0], $abCats[1], etc. Remember that arrays start at element 0.These amendments to your script are still pretty ugly, but they work:expandcollapse popup#include <GUIConstantsEx.au3> Global $Cats1 = False, $Cats2 = False, $Cats3 = False, $Cats4 = False Global $Cats5 = False, $Cats6 = False, $Cats7 = False, $Cats8 = False, $Cats9 = False Global $aCats[9] Global $abCats[9] = [False, False, False, False, False, False, False, False, False] GUICreate("", 200, 200) For $i = 0 To 8 $aCats[$i] = GUICtrlCreateCheckbox("Cats" & $i, 10, 20 * $i, 50, 20) Next GUISetState() While 1 If GUIGetMsg() = -3 Then Exit For $i = 0 To 8 If BitAND(GUICtrlRead ($aCats[$i]), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($aCats[$i], $GUI_HIDE) EndIf Next For $n = 0 To 8 If BitAND(GUICtrlRead ($aCats[$n]), $GUI_CHECKED) = $GUI_CHECKED Then $abCats[$n] = True EndIf Next If $abCats[0] And $abCats[1]And $abCats[2] And $abCats[3] And $abCats[4] And _ $abCats[5] And $abCats[6] And $abCats[7] And $abCats[8] Then $Msg = MsgBox (52, "Cats Game!", "Cats Games! No one wins!" & @LF & _ "Would you like to play again?") For $i = 0 To 8 GUICtrlSetState($aCats[$i], $GUI_UNCHECKED) GUICtrlSetState($aCats[$i], $GUI_SHOW) $abCats[0] = False Next EndIF WEndM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
LurchMan Posted March 1, 2009 Author Posted March 1, 2009 I was suing GuiCTRLGetState to just try and see if that worked and I forgot to change it before posting. Its already been changed, thank you though. The Array with the boolean values is a problem, true, but not my main problem. Also thank you for pointing this out to me. Earlier in the script it already correctly sets the check box to $GUI_HIDE, and in this part im just trying to read all of the check boxes, but I get a return Code of 0 for failed. It checks to see if all of the boxes have been checked yet or not each time one is clicked. This solution doesn't solv my problem of not being able to read the state of the control.... Thanks for the try. Thank you for your time. Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.
Moderators Melba23 Posted March 1, 2009 Moderators Posted March 1, 2009 lurchman,Sorry, I do not understand. You speak of "my problem of not being able to read the state of the control".The code I posted above succeeds in reading the state of the checkbox controls, whether they are hidden or visible. There must be something else. Post your full code and maybe we can solve this together.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
LurchMan Posted March 1, 2009 Author Posted March 1, 2009 I dont think you want me posting all 566 lines.... I did however attach it but prepare yourself to see some dirty and bad coding lol.... I just started writing it so dont expect too much out of it right now. Theres actually 2 sections that do this for 2 different situations. They are both located inbetween lines 397 - 408 and lines 503 - 514 Set the controls to be hidden: Lines 134 - 303 The controls im trying to read: lines 38 - 54Tic_Tac_Toe.au3 Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.
Moderators Melba23 Posted March 1, 2009 Moderators Posted March 1, 2009 lurchman,The problem lies in the manner in which you fill your arrays. Please excuse me while I put my teaching hat on for a minute!You declare your arrays correctly by stating the name and the number of elements; you also have the correct syntax for filling them:Global $aCats[9] = [$Q1, $Q2, $Q3, $Q4, $Q5, $Q6, $Q7, $Q8, $Q9]Global $abCats[9] = [$Cats1, $Cats2, $Cats3, $Cats4, $Cats5, $Cats6, $Cats7, $Cats8, $Cats9]Where you go wrong is in how you then address the elements in your code. As I mentioned in my first post, you need to use the array name and the element number - i.e. $aCats[0] for the first element of the $aCats array.When you fill your arrays as above, you are setting the elements to the value of variable $Q1, $Q2, etc. As these variables have not been declared (i.e. have no value), your array is actually empty. In fact you could just declare your array as Global $aCats[9] - the end result would be the same.When you create your controls, you are setting the variables $Q1, $Q2, etc to the controlIDs. $Q1 = GUICtrlCreateCheckbox("Q1", 72, 152, 17, 17)....However, you are NOT amending the values in the array, only the value in the variables themselves. To change the array value you need to do one of two things:1. Re-read the value of the variables into the array - but that takes another loop.2. Better to store the ControlID the array elements directly:$aCats[0] = GUICtrlCreateCheckbox("Q1", 72, 152, 17, 17)....This way you get the ControlIDs in the array and then your GUICtrlRead has a valid ControlID to work on!So to reiterate: The elements in arrays must be set directly. Setting the elements to a variable will only use the current value of the variable - if the variable changes, the array element will NOT change, unless you specifically code it.Look at the changes here in how the arrays are declared and the ControlIDs are stored:expandcollapse popupGlobal $X_Wins = 0, $X_Loses = 0 Global $O_Wins = 0, $O_Loses = 0 Global $aCats[9] Global $abCats[9] = [False, False, False, False, False, False, False, False, False] ;~ Main Game $Main = GUICreate("Tic Tac Toe", 594, 609, 203, 117) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") GUICtrlCreateGraphic(192, 112, 17, 417, BitOR($SS_CENTER,$SS_RIGHT,$SS_BLACKRECT,$SS_GRAYRECT,$SS_WHITERECT,$SS_BLACKFRAME,$SS_NOTIFY)) GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0x000000) GUICtrlCreateGraphic(384, 112, 17, 417, BitOR($SS_CENTER,$SS_RIGHT,$SS_BLACKRECT,$SS_GRAYRECT,$SS_WHITERECT,$SS_BLACKFRAME,$SS_NOTIFY)) GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0x000000) GUICtrlCreateGraphic(8, 224, 553, 17) GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0x000000) GUICtrlCreateGraphic(8, 392, 553, 17) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x000000) $aCats[0] = GUICtrlCreateCheckbox("Q1", 72, 152, 17, 17) GUICtrlSetOnEvent(-1, "Q1Click") $aCats[1] = GUICtrlCreateCheckbox("Q1", 285, 150, 17, 17) GUICtrlSetOnEvent(-1, "Q2Click") $aCats[2] = GUICtrlCreateCheckbox("Q1", 469, 157, 17, 17) GUICtrlSetOnEvent(-1, "Q3Click") $aCats[3] = GUICtrlCreateCheckbox("Q1", 80, 314, 17, 17) GUICtrlSetOnEvent(-1, "Q4Click") $aCats[4] = GUICtrlCreateCheckbox("Q1", 288, 305, 17, 17) GUICtrlSetOnEvent(-1, "Q5Click") $aCats[5] = GUICtrlCreateCheckbox("Q1", 483, 308, 17, 17) GUICtrlSetOnEvent(-1, "Q6Click") $aCats[6] = GUICtrlCreateCheckbox("Q1", 93, 472, 17, 17) GUICtrlSetOnEvent(-1, "Q7Click") $aCats[7] = GUICtrlCreateCheckbox("Q1", 297, 473, 17, 17) GUICtrlSetOnEvent(-1, "Q8Click") $aCats[8] = GUICtrlCreateCheckbox("Q1", 483, 475, 17, 17) GUICtrlSetOnEvent(-1, "Q9Click")If you insert this into your code in the correct place, all runs as it should.A good tip: Use _ArrayDisplay to look at the contents of arrays. It halts the script like MsgBox and lets you confirm that you actually have what you think you should have in the array. I did that and saw immediately that the array of ControlIDs was empty. You will need to include Array.au3 to use _ArrayDisplay and make sure you get rid of all the calls before you compile! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
LurchMan Posted March 2, 2009 Author Posted March 2, 2009 Thank you. As you can see im still pretty new when it comes to array and i didn't know about the _ArrayDisplay command...that will come in handy later on! Again thank you! Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.
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