Sign in to follow this  
Followers 0
LurchMan

reading hidden control

7 posts in this topic

#1 ·  Posted (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 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.

Share this post


Link to post
Share on other sites



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/dropaccepted

GUICtrlRead : 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:

#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

WEnd

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I dont think you want me posting all 566 lines.... :P

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 - 54

Tic_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.

Share this post


Link to post
Share on other sites

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:

Global $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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0