Jump to content

Need little help please :)


sakej
 Share

Go to solution Solved by abberration,

Recommended Posts

Hi all :)

Can anyone pls explain to me why this dosen't work and how to make it works? :)

 

...
$check1 = GUICtrlCreateCheckbox("Dance / Electro Pop",281,135,150,20,-1,-1)
$check2 = GUICtrlCreateCheckbox("Bass House",567,216,103,20,-1,-1)
$check3 = GUICtrlCreateCheckbox("Funky House",445,216,97,20,-1,-1)
$check4 = GUICtrlCreateCheckbox("Mainstage | Big Room",281,162,150,20,-1,-1)
$check5 = GUICtrlCreateCheckbox("Disco Polo Dance",281,188,112,20,-1,-1)
$check6 = GUICtrlCreateCheckbox("Trance",281,216,112,20,-1,-1)
$check7 = GUICtrlCreateCheckbox("Hardstyle",445,135,112,20,-1,-1)
$check8 = GUICtrlCreateCheckbox("Nu Disco",445,162,112,20,-1,-1)
....


Func uncheck()

    Local $to = 15, $check
    Local $aArray[1] = ["$check"]

    For $x = 1 to $to
        _ArrayAdd($aArray, "$check" & $x)
    Next

    _ArrayDisplay($aArray)

    For $i = 1 to UBound($aArray) - 1
        Local $check = $aArray[$i]

        GUICtrlSetState($check, 4)
        ConsoleWrite($check & @CR)
    Next
  EndFunc

The part that does not work is unchecking..

I have 15 checkboxex with variable $check1 , $check2 .. so on so on...

Edited by sakej
Link to comment
Share on other sites

The problem you are encountering is you are using one variable to create 15 checkboxes. This variable does NOT control 15 items - instead, it recycles the variable when creating new checkboxes and leaves the old ones behind with no variable assigned to it (but you can still access them, but it's more difficult). If you keep using the same variable to create all checkboxes, when you go to check or uncheck them, it will only affect the last one created.

I like to use the Assign and Eval operators to dynamically create variables to manage gui items. Here's an example:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 333, 408, 192, 124)
$Button1 = GUICtrlCreateButton("Check", 48, 360, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Uncheck", 168, 360, 75, 25, $WS_GROUP)
For $i = 1 To 15
    Assign("Checkbox" & $i, GUICtrlCreateCheckbox("Checkbox" & $i, 16, 24 + $i * 16, 97, 17))
Next
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _CheckAll()
        Case $Button2
            _UncheckAll()
    EndSwitch
WEnd

Func _CheckAll()
    For $i = 1 To 15
        GUICtrlSetState(Eval("Checkbox" & $i), 1)
    Next
EndFunc

Func _UncheckAll()
    For $i = 1 To 15
        GUICtrlSetState(Eval("Checkbox" & $i), 4)
    Next
EndFunc

Hope this helps! If you have questions, feel free to ask.

Edited by abberration
Link to comment
Share on other sites

Thank you  @abberration 

I've edited OP to include part how checkboxes are created.

I do it that way couse I'm using Autoit Studio, it's conviniet for me when it comes to create / design GUI.

Did mess around a bit wih Assign and Eval but with no luck so far.

Gonna try to incorporate _UncheckAll function from your example and see will it work or not for me.

Link to comment
Share on other sites

  • Solution

I saw where you updated the code. Here's an updated version with your newer code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

$Form1 = GUICreate("Form1", 800, 408, 192, 124)
$check1 = GUICtrlCreateCheckbox("Dance / Electro Pop",281,135,150,20,-1,-1)
$check2 = GUICtrlCreateCheckbox("Bass House",567,216,103,20,-1,-1)
$check3 = GUICtrlCreateCheckbox("Funky House",445,216,97,20,-1,-1)
$check4 = GUICtrlCreateCheckbox("Mainstage | Big Room",281,162,150,20,-1,-1)
$check5 = GUICtrlCreateCheckbox("Disco Polo Dance",281,188,112,20,-1,-1)
$check6 = GUICtrlCreateCheckbox("Trance",281,216,112,20,-1,-1)
$check7 = GUICtrlCreateCheckbox("Hardstyle",445,135,112,20,-1,-1)
$check8 = GUICtrlCreateCheckbox("Nu Disco",445,162,112,20,-1,-1)
GUISetState(@SW_SHOW)

For $j = 1 To 4
    Check()
    Sleep(1000)
    Uncheck()
    Sleep(1000)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func Check()
    For $i = 1 To 15
        GUICtrlSetState(Eval("check" & $i), 1)
    Next
EndFunc

Func Uncheck()
    For $i = 1 To 15
        GUICtrlSetState(Eval("check" & $i), 4)
    Next
EndFunc

Using a similar method with just Eval, this code works. I'm not sure why you are adding the checkboxes to an array after they have been created. But give this a try. It cycles between checking and unchecking all the checkboxes four times.

Link to comment
Share on other sites

OK, I see where I was mistaken now :)

Was using Eval wrong way when tryied do it this way.

And end up with this mess at the time of asking,

 

Thanks a lot, this works.

BTW.

Adding this to array was just a poor attempt to find out a way for this to work, unnecessary and overcomplicated ;/

Now that part is gone thanks to you :)

 

 

Edited by sakej
Link to comment
Share on other sites

You could use an array to dynamically change the number of checkboxes for example:

#include <GUIConstantsEx.au3>
Global $aCheckBox[][2] = [["", "Dance / Electro Pop"],["", "Bass House"],["", "Funky House"],["", "Mainstage | Big Room"],["", "Disco Polo Dance"],["", "Trance"],["", "Hardstyle"],["", "Nu Disco"]]
Global $iHeight = 10 + ((UBound($aCheckBox) - 1) * 25) + 55
Global $iY = 10
Global $Form1 = GUICreate("Form1", 800, $iHeight, 192, 124)

For $i = 0 To UBound($aCheckBox) - 1
    $aCheckBox[$i][0] = GUICtrlCreateCheckbox($aCheckBox[$i][1],10,$iY,150,20,-1,-1)
    $iY += 25
Next
Global $idCheck = GUICtrlCreateButton("Check", 10, $iY, 100, 25)
Global $idUncheck = GUICtrlCreateButton("Uncheck", 115, $iY, 100, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idCheck
            _CheckBox(1)
        Case $idUncheck
            _CheckBox(4)
    EndSwitch
WEnd

Func _CheckBox($iFlag = 1)
    For $i = 0 To UBound($aCheckBox) - 1
        GUICtrlSetState($aCheckBox[$i][0], $iFlag)
    Next
EndFunc

Another method is to use GuiCtrlCreateDummy for example:

#include <GUIConstantsEx.au3>

Global $Form1 = GUICreate("Form1", 800, 408, 192, 124)

Global $iCheckStart = GUICtrlCreateDummy()
    Global $check1 = GUICtrlCreateCheckbox("Dance / Electro Pop",281,135,150,20,-1,-1)
    Global $check2 = GUICtrlCreateCheckbox("Bass House",567,216,103,20,-1,-1)
    Global $check3 = GUICtrlCreateCheckbox("Funky House",445,216,97,20,-1,-1)
    Global $check4 = GUICtrlCreateCheckbox("Mainstage | Big Room",281,162,150,20,-1,-1)
    Global $check5 = GUICtrlCreateCheckbox("Disco Polo Dance",281,188,112,20,-1,-1)
    Global $check6 = GUICtrlCreateCheckbox("Trance",281,216,112,20,-1,-1)
    Global $check7 = GUICtrlCreateCheckbox("Hardstyle",445,135,112,20,-1,-1)
    Global $check8 = GUICtrlCreateCheckbox("Nu Disco",445,162,112,20,-1,-1)
Global $iCheckEnd = GUICtrlCreateDummy()

Global $idCheck = GUICtrlCreateButton("Check", 10, 10, 100, 25)
Global $idUncheck = GUICtrlCreateButton("Uncheck", 115, 10, 100, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idCheck
            _CheckBox(1)
        Case $idUncheck
            _CheckBox(4)
    EndSwitch
WEnd

Func _CheckBox($iFlag = 1)
    For $idCheckBox = $iCheckStart To $iCheckEnd
        GUICtrlSetState($idCheckBox, $iFlag)
    Next
EndFunc

 

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