Jump to content

GUICtrlSetState Array


Recommended Posts

I'm making a simple flowchart for work (and for autoit practice.) Select a button, it hides previous options and shows the new tree of options. Each row becomes exponentially larger than the past.

Creating an array for this would make life much easier, but I'm having a heck of a time. Bellow is the basic idea.

#include <GUIConstants.au3>
#include <Array.au3>


GUICreate("My GUI Button",300,300,-1,-1)

;;;;;;;;;;;;;;;;;;;;;
;First Row of Buttons
;;;;;;;;;;;;;;;;;;;;;

$One= GUICtrlCreateButton("1", 5, 25, 100, 30)
$Two= GUICtrlCreateButton("2", 5, 65, 100, 30)
$Three= GUICtrlCreateButton("3", 5, 105, 100, 30)
$StartOver= GUICtrlCreateButton("Start Over", 5, 145, 100, 30)

;;;;;;;;;;;;;;;;;;;;;
;Second Row of Buttons 
;;;;;;;;;;;;;;;;;;;;;

$Four= GUICtrlCreateButton("4", 115, 25, 100, 30)
$Five= GUICtrlCreateButton("5", 115, 65, 100, 30)
$Six= GUICtrlCreateButton("6", 115, 105, 100, 30)


GUISetState ()
While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE 
        ExitLoop
    Case $msg = $One
        GUICtrlSetState($Two,$GUI_HIDE)
        GUICtrlSetState($Three,$GUI_HIDE)
        GUICtrlSetState($Four,$GUI_HIDE)
        GUICtrlSetState($Five,$GUI_HIDE)
        GUICtrlSetState($Six,$GUI_HIDE)
    Case $msg = $Two 
        GUICtrlSetState($One,$GUI_HIDE)
        GUICtrlSetState($Three,$GUI_HIDE)
        GUICtrlSetState($Four,$GUI_HIDE)
        GUICtrlSetState($Five,$GUI_HIDE)
        GUICtrlSetState($Six,$GUI_HIDE)
    Case $msg = $Three
        GUICtrlSetState($One,$GUI_HIDE)
        GUICtrlSetState($Two,$GUI_HIDE)
        GUICtrlSetState($Four,$GUI_HIDE)
        GUICtrlSetState($Five,$GUI_HIDE)
        GUICtrlSetState($Six,$GUI_HIDE)
    Case $msg = $Four
        GUICtrlSetState($One,$GUI_HIDE)
        GUICtrlSetState($Two,$GUI_HIDE)
        GUICtrlSetState($Three,$GUI_HIDE)
        GUICtrlSetState($Five,$GUI_HIDE)
        GUICtrlSetState($Six,$GUI_HIDE)
    Case $msg = $Five
        GUICtrlSetState($One,$GUI_HIDE)
        GUICtrlSetState($Two,$GUI_HIDE)
        GUICtrlSetState($Three,$GUI_HIDE)
        GUICtrlSetState($Four,$GUI_HIDE)
        GUICtrlSetState($Six,$GUI_HIDE)
    Case $msg = $Six
        GUICtrlSetState($One,$GUI_HIDE)
        GUICtrlSetState($Two,$GUI_HIDE)
        GUICtrlSetState($Three,$GUI_HIDE)
        GUICtrlSetState($Four,$GUI_HIDE)
        GUICtrlSetState($Five,$GUI_HIDE)
        
Case $msg = $StartOver
    GUICtrlSetState($One,$GUI_SHOW)
    GUICtrlSetState($Two,$GUI_SHOW)
    GUICtrlSetState($Three,$GUI_SHOW)
    GUICtrlSetState($Four,$GUI_SHOW)
    GUICtrlSetState($Five,$GUI_SHOW)
    GUICtrlSetState($Six,$GUI_SHOW)
    EndSelect
Wend

Below is my attempt at the array. Instead of it calling $Hidebuttons to hide the buttons, it's acting like $Hidebuttons is a button, so it doesnt error out, but doesnt do anything either.

Dim $One,$Two, $Three, $Four, $Five, $Six = 0
Dim $HideButtons
$HideButtons = _ArrayCreate($One,$Two, $Three, $Four, $Five, $Six)
GUICtrlSetState($HideButtons,$GUI_HIDE)

Any suggestions would be welcome =)

Link to comment
Share on other sites

  • Moderators

For $i = 0 To UBound($HideButtons) - 1
    GUICtrlSetState($HideButtons[$i], $GUI_HIDE)
Next

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

#include <GUIConstants.au3>

GUICreate("My GUI Button", 300, 300, -1, -1)

Dim $Buttons[8]
$Buttons[0] = 7
$x = 5
$y = 25
For $i = 1 To 3
    ;;;;;;;;;;;;;;;;;;;;;
    ;First Row of Buttons
    ;;;;;;;;;;;;;;;;;;;;;
    $Buttons[$i] = GUICtrlCreateButton($i, $x, $y, 100, 30)
    ;;;;;;;;;;;;;;;;;;;;;
    ;Second Row of Buttons
    ;;;;;;;;;;;;;;;;;;;;;
    $Buttons[$i + 3] = GUICtrlCreateButton($i + 3, $x + 100, $y, 100, 30)
    $y = $y + 40
Next
$Buttons[7] = GUICtrlCreateButton("Start Over", 5, 145, 100, 30)

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Buttons[7] ; start over
            For $i = 1 To 6
                GUICtrlSetState($Buttons[$i], $GUI_SHOW)
            Next
        Case Else
            For $i = 1 To 6
                If $msg = $Buttons[$i] Then
                    For $x = 1 To $i - 1
                        GUICtrlSetState($Buttons[$x], $GUI_HIDE)
                    Next
                    For $x = $i + 1 To 6
                        GUICtrlSetState($Buttons[$x], $GUI_HIDE)
                    Next
                    ContinueLoop
                EndIf
            Next
    EndSelect
WEnd

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

#include <GUIConstants.au3>

GUICreate("My GUI Button", 300, 300, -1, -1)

Dim $Buttons[8]
$Buttons[0] = 7
$x = 5
$y = 25
For $i = 1 To 3
    ;;;;;;;;;;;;;;;;;;;;;
    ;First Row of Buttons
    ;;;;;;;;;;;;;;;;;;;;;
    $Buttons[$i] = GUICtrlCreateButton($i, $x, $y, 100, 30)
    ;;;;;;;;;;;;;;;;;;;;;
    ;Second Row of Buttons
    ;;;;;;;;;;;;;;;;;;;;;
    $Buttons[$i + 3] = GUICtrlCreateButton($i + 3, $x + 100, $y, 100, 30)
    $y = $y + 40
Next
$Buttons[7] = GUICtrlCreateButton("Start Over", 5, 145, 100, 30)

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Buttons[7] ; start over
            For $i = 1 To 6
                GUICtrlSetState($Buttons[$i], $GUI_SHOW)
            Next
        Case Else
            For $i = 1 To 6
                If $msg = $Buttons[$i] Then
                    For $x = 1 To $i - 1
                        GUICtrlSetState($Buttons[$x], $GUI_HIDE)
                    Next
                    For $x = $i + 1 To 6
                        GUICtrlSetState($Buttons[$x], $GUI_HIDE)
                    Next
                    ContinueLoop
                EndIf
            Next
    EndSelect
WEnd

Wow. What a great reminder of how much there is to learn.

Thank you guys.

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