Jump to content

Arrays and Checkboxes


Recommended Posts

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 by SinSoul
Link to comment
Share on other sites

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 by czardas
Link to comment
Share on other sites

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.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...