Jump to content

Array and GUICtrlSetState


Eambo
 Share

Recommended Posts

Howdy folks!

 

I'm attempting to control multiple buttons using an array for tidiness, however I'm not having much luck. I've used messageboxes to pop up the output and it seems to be correct,  but it doesn't seem to be hiding/showing as I would expect. Any thoughts on what I may be doing wrong, or how best to approach this if I'm approaching it very poorly?

 

Ideally what I'm trying to have is:

 

- Set all buttons to empty + combo box empty on start

- Select an environment in the combo box

- Environment buttons populate

- other two environments buttons are hidden

 

Thank you for any guidance you can offer!

 

; Script generated by AutoBuilder 0.9f Prototype

#Region ---Head--
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <ComboConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>

If _Singleton("JETS", 1) = 0 Then
    MsgBox($MB_SYSTEMMODAL, "Warning", "JETS is already running!")
    Exit
EndIf

$hGUI = GUICreate("JETS", 829, 600, -1, -1, $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_MINIMIZEBOX)

$Combo_01 = GUICtrlCreateCombo("", 160, 20, 145, 21, -1)
GUICtrlSetData($Combo_01, "Production|Shadow|QA", "")
$Label_01 = GUICtrlCreateLabel("Select Your Environment:", 20, 25, 140, 30, -1)

$btn_Production_01 = GUICtrlCreateButton("Production_01", 10, 70, 270, 50, -1)
$btn_Production_02 = GUICtrlCreateButton("Production_02", 280, 70, 270, 50, -1)
$btn_Production_03 = GUICtrlCreateButton("Production_03", 550, 70, 270, 50, -1)
$btn_Production_04 = GUICtrlCreateButton("Production_04", 10, 120, 270, 50, -1)
$btn_Production_05 = GUICtrlCreateButton("Production_05", 280, 120, 270, 50, -1)
$btn_Production_06 = GUICtrlCreateButton("Production_06", 550, 120, 270, 50, -1)
$btn_Production_07 = GUICtrlCreateButton("Production_07", 10, 170, 270, 50, -1)
$btn_Production_08 = GUICtrlCreateButton("Production_08", 280, 170, 270, 50, -1)
$btn_Production_09 = GUICtrlCreateButton("Production_09", 550, 170, 270, 50, -1)
$btn_Production_10 = GUICtrlCreateButton("Production_10", 10, 220, 270, 50, -1)
$btn_Production_11 = GUICtrlCreateButton("Production_11", 280, 220, 270, 50, -1)
$btn_Production_12 = GUICtrlCreateButton("Production_12", 550, 220, 270, 50, -1)
$btn_Production_13 = GUICtrlCreateButton("Production_13", 10, 270, 270, 50, -1)
$btn_Production_14 = GUICtrlCreateButton("Production_14", 280, 270, 270, 50, -1)
$btn_Production_15 = GUICtrlCreateButton("Production_15", 550, 270, 270, 50, -1)
$btn_Production_16 = GUICtrlCreateButton("Production_16", 10, 320, 270, 50, -1)
$btn_Production_17 = GUICtrlCreateButton("Production_17", 280, 320, 270, 50, -1)
$btn_Production_18 = GUICtrlCreateButton("Production_18", 550, 320, 270, 50, -1)
$btn_Production_19 = GUICtrlCreateButton("Production_19", 10, 370, 270, 50, -1)
$btn_Production_20 = GUICtrlCreateButton("Production_20", 280, 370, 270, 50, -1)
$btn_Production_21 = GUICtrlCreateButton("Production_21", 550, 370, 270, 50, -1)
$btn_Production_22 = GUICtrlCreateButton("Production_22", 10, 420, 270, 50, -1)
$btn_Production_23 = GUICtrlCreateButton("Production_23", 280, 420, 270, 50, -1)
$btn_Production_24 = GUICtrlCreateButton("Production_24", 550, 420, 270, 50, -1)
$btn_Production_25 = GUICtrlCreateButton("Production_25", 10, 470, 270, 50, -1)
$btn_Production_26 = GUICtrlCreateButton("Production_26", 280, 470, 270, 50, -1)
$btn_Production_27 = GUICtrlCreateButton("Production_27", 550, 470, 270, 50, -1)
$btn_Production_28 = GUICtrlCreateButton("Production_28", 10, 520, 270, 50, -1)
$btn_Production_29 = GUICtrlCreateButton("Production_29", 280, 520, 270, 50, -1)
$btn_Production_30 = GUICtrlCreateButton("Production_30", 550, 520, 270, 50, -1)

Dim $av_btn_Production[30] = ["$btn_Production_01", "$btn_Production_02", "$btn_Production_03", "$btn_Production_04", "$btn_Production_05", "$btn_Production_06", "$btn_Production_07", "$btn_Production_08", "$btn_Production_09", "$btn_Production_10", _
        "$btn_Production_11", "$btn_Production_12", "$btn_Production_13", "$btn_Production_14", "$btn_Production_15", "$btn_Production_16", "$btn_Production_17", "$btn_Production_18", "$btn_Production_19", "$btn_Production_20", _
        "$btn_Production_21", "$btn_Production_22", "$btn_Production_23", "$btn_Production_24", "$btn_Production_25", "$btn_Production_26", "$btn_Production_27", "$btn_Production_28", "$btn_Production_29", "$btn_Production_30"]

$btn_Shadow_01 = GUICtrlCreateButton("Shadow_01", 10, 70, 270, 50, -1)
$btn_Shadow_02 = GUICtrlCreateButton("Shadow_02", 280, 70, 270, 50, -1)
$btn_Shadow_03 = GUICtrlCreateButton("Shadow_03", 550, 70, 270, 50, -1)
$btn_Shadow_04 = GUICtrlCreateButton("Shadow_04", 10, 120, 270, 50, -1)
$btn_Shadow_05 = GUICtrlCreateButton("Shadow_05", 280, 120, 270, 50, -1)
$btn_Shadow_06 = GUICtrlCreateButton("Shadow_06", 550, 120, 270, 50, -1)
$btn_Shadow_07 = GUICtrlCreateButton("Shadow_07", 10, 170, 270, 50, -1)
$btn_Shadow_08 = GUICtrlCreateButton("Shadow_08", 280, 170, 270, 50, -1)
$btn_Shadow_09 = GUICtrlCreateButton("Shadow_09", 550, 170, 270, 50, -1)
$btn_Shadow_10 = GUICtrlCreateButton("Shadow_10", 10, 220, 270, 50, -1)
$btn_Shadow_11 = GUICtrlCreateButton("Shadow_11", 280, 220, 270, 50, -1)
$btn_Shadow_12 = GUICtrlCreateButton("Shadow_12", 550, 220, 270, 50, -1)
$btn_Shadow_13 = GUICtrlCreateButton("Shadow_13", 10, 270, 270, 50, -1)
$btn_Shadow_14 = GUICtrlCreateButton("Shadow_14", 280, 270, 270, 50, -1)
$btn_Shadow_15 = GUICtrlCreateButton("Shadow_15", 550, 270, 270, 50, -1)
$btn_Shadow_16 = GUICtrlCreateButton("Shadow_16", 10, 320, 270, 50, -1)
$btn_Shadow_17 = GUICtrlCreateButton("Shadow_17", 280, 320, 270, 50, -1)
$btn_Shadow_18 = GUICtrlCreateButton("Shadow_18", 550, 320, 270, 50, -1)
$btn_Shadow_19 = GUICtrlCreateButton("Shadow_19", 10, 370, 270, 50, -1)
$btn_Shadow_20 = GUICtrlCreateButton("Shadow_20", 280, 370, 270, 50, -1)
$btn_Shadow_21 = GUICtrlCreateButton("Shadow_21", 550, 370, 270, 50, -1)
$btn_Shadow_22 = GUICtrlCreateButton("Shadow_22", 10, 420, 270, 50, -1)
$btn_Shadow_23 = GUICtrlCreateButton("Shadow_23", 280, 420, 270, 50, -1)
$btn_Shadow_24 = GUICtrlCreateButton("Shadow_24", 550, 420, 270, 50, -1)
$btn_Shadow_25 = GUICtrlCreateButton("Shadow_25", 10, 470, 270, 50, -1)
$btn_Shadow_26 = GUICtrlCreateButton("Shadow_26", 280, 470, 270, 50, -1)
$btn_Shadow_27 = GUICtrlCreateButton("Shadow_27", 550, 470, 270, 50, -1)
$btn_Shadow_28 = GUICtrlCreateButton("Shadow_28", 10, 520, 270, 50, -1)
$btn_Shadow_29 = GUICtrlCreateButton("Shadow_29", 280, 520, 270, 50, -1)
$btn_Shadow_30 = GUICtrlCreateButton("Shadow_00", 550, 520, 270, 50, -1)

Dim $av_btn_Shadow[30] = ["$btn_Shadow_01", "$btn_Shadow_02", "$btn_Shadow_03", "$btn_Shadow_04", "$btn_Shadow_05", "$btn_Shadow_06", "$btn_Shadow_07", "$btn_Shadow_08", "$btn_Shadow_09", "$btn_Shadow_10", _
        "$btn_Shadow_11", "$btn_Shadow_12", "$btn_Shadow_13", "$btn_Shadow_14", "$btn_Shadow_15", "$btn_Shadow_16", "$btn_Shadow_17", "$btn_Shadow_18", "$btn_Shadow_19", "$btn_Shadow_20", _
        "$btn_Shadow_21", "$btn_Shadow_22", "$btn_Shadow_23", "$btn_Shadow_24", "$btn_Shadow_25", "$btn_Shadow_26", "$btn_Shadow_27", "$btn_Shadow_28", "$btn_Shadow_29", "$btn_Shadow_30"]

$btn_QA_01 = GUICtrlCreateButton("QA_01", 10, 70, 270, 50, -1)
$btn_QA_02 = GUICtrlCreateButton("QA_02", 280, 70, 270, 50, -1)
$btn_QA_03 = GUICtrlCreateButton("QA_03", 550, 70, 270, 50, -1)
$btn_QA_04 = GUICtrlCreateButton("QA_04", 10, 120, 270, 50, -1)
$btn_QA_05 = GUICtrlCreateButton("QA_05", 280, 120, 270, 50, -1)
$btn_QA_06 = GUICtrlCreateButton("QA_06", 550, 120, 270, 50, -1)
$btn_QA_07 = GUICtrlCreateButton("QA_07", 10, 170, 270, 50, -1)
$btn_QA_08 = GUICtrlCreateButton("QA_08", 280, 170, 270, 50, -1)
$btn_QA_09 = GUICtrlCreateButton("QA_09", 550, 170, 270, 50, -1)
$btn_QA_10 = GUICtrlCreateButton("QA_10", 10, 220, 270, 50, -1)
$btn_QA_11 = GUICtrlCreateButton("QA_11", 280, 220, 270, 50, -1)
$btn_QA_12 = GUICtrlCreateButton("QA_12", 550, 220, 270, 50, -1)
$btn_QA_13 = GUICtrlCreateButton("QA_13", 10, 270, 270, 50, -1)
$btn_QA_14 = GUICtrlCreateButton("QA_14", 280, 270, 270, 50, -1)
$btn_QA_15 = GUICtrlCreateButton("QA_15", 550, 270, 270, 50, -1)
$btn_QA_16 = GUICtrlCreateButton("QA_16", 10, 320, 270, 50, -1)
$btn_QA_17 = GUICtrlCreateButton("QA_17", 280, 320, 270, 50, -1)
$btn_QA_18 = GUICtrlCreateButton("QA_18", 550, 320, 270, 50, -1)
$btn_QA_19 = GUICtrlCreateButton("QA_19", 10, 370, 270, 50, -1)
$btn_QA_20 = GUICtrlCreateButton("QA_20", 280, 370, 270, 50, -1)
$btn_QA_21 = GUICtrlCreateButton("QA_21", 550, 370, 270, 50, -1)
$btn_QA_22 = GUICtrlCreateButton("QA_22", 10, 420, 270, 50, -1)
$btn_QA_23 = GUICtrlCreateButton("QA_23", 280, 420, 270, 50, -1)
$btn_QA_24 = GUICtrlCreateButton("QA_24", 550, 420, 270, 50, -1)
$btn_QA_25 = GUICtrlCreateButton("QA_25", 10, 470, 270, 50, -1)
$btn_QA_26 = GUICtrlCreateButton("QA_26", 280, 470, 270, 50, -1)
$btn_QA_27 = GUICtrlCreateButton("QA_27", 550, 470, 270, 50, -1)
$btn_QA_28 = GUICtrlCreateButton("QA_28", 10, 520, 270, 50, -1)
$btn_QA_29 = GUICtrlCreateButton("QA_29", 280, 520, 270, 50, -1)
$btn_QA_30 = GUICtrlCreateButton("QA_30", 550, 520, 270, 50, -1)

Dim $av_btn_QA[30] = ["$btn_QA_01", "$btn_QA_02", "$btn_QA_03", "$btn_QA_04", "$btn_QA_05", "$btn_QA_06", "$btn_QA_07", "$btn_QA_08", "$btn_QA_09", "$btn_QA_10", _
        "$btn_QA_11", "$btn_QA_12", "$btn_QA_13", "$btn_QA_14", "$btn_QA_15", "$btn_QA_16", "$btn_QA_17", "$btn_QA_18", "$btn_QA_19", "$btn_QA_20", _
        "$btn_QA_21", "$btn_QA_22", "$btn_QA_23", "$btn_QA_24", "$btn_QA_25", "$btn_QA_26", "$btn_QA_27", "$btn_QA_28", "$btn_QA_29", "$btn_QA_30"]



GUISetState()
$i = 1
While $i <= 29
    GUICtrlSetState($av_btn_Production[$i], $GUI_HIDE)
    GUICtrlSetState($av_btn_Shadow[$i], $GUI_HIDE)
    GUICtrlSetState($av_btn_QA[$i], $GUI_HIDE)
    $i = $i + 1
WEnd
#EndRegion ---Head--

#Region --- Form ---



#Region --- Loop ---
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            $Environment = GUICtrlRead($Combo_01)
            If $Environment = "Production" Then
                $i = 0
                While $i <= 29
                    GUICtrlSetState($av_btn_Production[$i], $GUI_SHOW)
                    GUICtrlSetState($av_btn_Shadow[$i], $GUI_HIDE)
                    GUICtrlSetState($av_btn_QA[$i], $GUI_HIDE)
                    $i = $i + 1
                WEnd

            ElseIf $Environment = "Shadow" Then
                $i = 0
                While $i <= 29
                    GUICtrlSetState($av_btn_Shadow[$i], $GUI_SHOW)
                    GUICtrlSetState($av_btn_Production[$i], $GUI_HIDE)
                    GUICtrlSetState($av_btn_QA[$i], $GUI_HIDE)
                    $i = $i + 1
                WEnd

            ElseIf $Environment = "QA" Then
                $i = 0
                While $i <= 29
                    GUICtrlSetState($av_btn_QA[$i], $GUI_SHOW)
                    GUICtrlSetState($av_btn_Shadow[$i], $GUI_HIDE)
                    GUICtrlSetState($av_btn_Production[$i], $GUI_HIDE)
                    $i = $i + 1
                WEnd

            Else

                $i = 1
                While $i <= 29
                    GUICtrlSetState($av_btn_QA[$i], $GUI_HIDE)
                    GUICtrlSetState($av_btn_Shadow[$i], $GUI_HIDE)
                    GUICtrlSetState($av_btn_Production[$i], $GUI_HIDE)
                    $i = $i + 1
                WEnd

            EndIf

    EndSelect
WEnd
#EndRegion --- Loop ---

#Region --- Additional Functions ---
#EndRegion --- Additional Functions ---

Exit

 

Link to comment
Share on other sites

@Eambo
Use an array of controls as showed in the example below:

Spoiler
#Region ---Head--
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <ComboConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>


; Declaring three Global arrays of 30 elements
Global $arrProductionButtons[30]
Global $arrShadowButtons[30]
Global $arrQAButtons[30]

If _Singleton("JETS", 1) = 0 Then
    MsgBox($MB_SYSTEMMODAL, "Warning", "JETS is already running!")
    Exit
EndIf

$hGUI = GUICreate("JETS", 829, 600, -1, -1, $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_MINIMIZEBOX)

$Combo_01 = GUICtrlCreateCombo("", 160, 20, 145, 21, -1)
GUICtrlSetData($Combo_01, "Production|Shadow|QA", "")
$Label_01 = GUICtrlCreateLabel("Select Your Environment:", 20, 25, 140, 30, -1)

; Assigning each control to an element
$arrProductionButtons[0] = GUICtrlCreateButton("Production_01", 10, 70, 270, 50, -1)
$arrProductionButtons[1] = GUICtrlCreateButton("Production_02", 280, 70, 270, 50, -1)
$arrProductionButtons[2] = GUICtrlCreateButton("Production_03", 550, 70, 270, 50, -1)
$arrProductionButtons[3] = GUICtrlCreateButton("Production_04", 10, 120, 270, 50, -1)
$arrProductionButtons[4] = GUICtrlCreateButton("Production_05", 280, 120, 270, 50, -1)
$arrProductionButtons[5] = GUICtrlCreateButton("Production_06", 550, 120, 270, 50, -1)
$arrProductionButtons[6] = GUICtrlCreateButton("Production_07", 10, 170, 270, 50, -1)
$arrProductionButtons[7] = GUICtrlCreateButton("Production_08", 280, 170, 270, 50, -1)
$arrProductionButtons[8] = GUICtrlCreateButton("Production_09", 550, 170, 270, 50, -1)
$arrProductionButtons[9] = GUICtrlCreateButton("Production_10", 10, 220, 270, 50, -1)
$arrProductionButtons[10] = GUICtrlCreateButton("Production_11", 280, 220, 270, 50, -1)
$arrProductionButtons[11] = GUICtrlCreateButton("Production_12", 550, 220, 270, 50, -1)
$arrProductionButtons[12] = GUICtrlCreateButton("Production_13", 10, 270, 270, 50, -1)
$arrProductionButtons[13] = GUICtrlCreateButton("Production_14", 280, 270, 270, 50, -1)
$arrProductionButtons[14] = GUICtrlCreateButton("Production_15", 550, 270, 270, 50, -1)
$arrProductionButtons[15] = GUICtrlCreateButton("Production_16", 10, 320, 270, 50, -1)
$arrProductionButtons[16] = GUICtrlCreateButton("Production_17", 280, 320, 270, 50, -1)
$arrProductionButtons[17] = GUICtrlCreateButton("Production_18", 550, 320, 270, 50, -1)
$arrProductionButtons[18] = GUICtrlCreateButton("Production_19", 10, 370, 270, 50, -1)
$arrProductionButtons[19] = GUICtrlCreateButton("Production_20", 280, 370, 270, 50, -1)
$arrProductionButtons[20] = GUICtrlCreateButton("Production_21", 550, 370, 270, 50, -1)
$arrProductionButtons[21] = GUICtrlCreateButton("Production_22", 10, 420, 270, 50, -1)
$arrProductionButtons[22] = GUICtrlCreateButton("Production_23", 280, 420, 270, 50, -1)
$arrProductionButtons[23] = GUICtrlCreateButton("Production_24", 550, 420, 270, 50, -1)
$arrProductionButtons[24] = GUICtrlCreateButton("Production_25", 10, 470, 270, 50, -1)
$arrProductionButtons[25] = GUICtrlCreateButton("Production_26", 280, 470, 270, 50, -1)
$arrProductionButtons[26] = GUICtrlCreateButton("Production_27", 550, 470, 270, 50, -1)
$arrProductionButtons[27] = GUICtrlCreateButton("Production_28", 10, 520, 270, 50, -1)
$arrProductionButtons[28] = GUICtrlCreateButton("Production_29", 280, 520, 270, 50, -1)
$arrProductionButtons[29] = GUICtrlCreateButton("Production_30", 550, 520, 270, 50, -1)

$arrShadowButtons[0] = GUICtrlCreateButton("Shadow_01", 10, 70, 270, 50, -1)
$arrShadowButtons[1] = GUICtrlCreateButton("Shadow_02", 280, 70, 270, 50, -1)
$arrShadowButtons[2] = GUICtrlCreateButton("Shadow_03", 550, 70, 270, 50, -1)
$arrShadowButtons[3] = GUICtrlCreateButton("Shadow_04", 10, 120, 270, 50, -1)
$arrShadowButtons[4] = GUICtrlCreateButton("Shadow_05", 280, 120, 270, 50, -1)
$arrShadowButtons[5] = GUICtrlCreateButton("Shadow_06", 550, 120, 270, 50, -1)
$arrShadowButtons[6] = GUICtrlCreateButton("Shadow_07", 10, 170, 270, 50, -1)
$arrShadowButtons[7] = GUICtrlCreateButton("Shadow_08", 280, 170, 270, 50, -1)
$arrShadowButtons[8] = GUICtrlCreateButton("Shadow_09", 550, 170, 270, 50, -1)
$arrShadowButtons[9] = GUICtrlCreateButton("Shadow_10", 10, 220, 270, 50, -1)
$arrShadowButtons[10] = GUICtrlCreateButton("Shadow_11", 280, 220, 270, 50, -1)
$arrShadowButtons[11] = GUICtrlCreateButton("Shadow_12", 550, 220, 270, 50, -1)
$arrShadowButtons[12] = GUICtrlCreateButton("Shadow_13", 10, 270, 270, 50, -1)
$arrShadowButtons[13] = GUICtrlCreateButton("Shadow_14", 280, 270, 270, 50, -1)
$arrShadowButtons[14] = GUICtrlCreateButton("Shadow_15", 550, 270, 270, 50, -1)
$arrShadowButtons[15] = GUICtrlCreateButton("Shadow_16", 10, 320, 270, 50, -1)
$arrShadowButtons[16] = GUICtrlCreateButton("Shadow_17", 280, 320, 270, 50, -1)
$arrShadowButtons[17] = GUICtrlCreateButton("Shadow_18", 550, 320, 270, 50, -1)
$arrShadowButtons[18] = GUICtrlCreateButton("Shadow_19", 10, 370, 270, 50, -1)
$arrShadowButtons[19] = GUICtrlCreateButton("Shadow_20", 280, 370, 270, 50, -1)
$arrShadowButtons[20] = GUICtrlCreateButton("Shadow_21", 550, 370, 270, 50, -1)
$arrShadowButtons[21] = GUICtrlCreateButton("Shadow_22", 10, 420, 270, 50, -1)
$arrShadowButtons[22] = GUICtrlCreateButton("Shadow_23", 280, 420, 270, 50, -1)
$arrShadowButtons[23] = GUICtrlCreateButton("Shadow_24", 550, 420, 270, 50, -1)
$arrShadowButtons[24] = GUICtrlCreateButton("Shadow_25", 10, 470, 270, 50, -1)
$arrShadowButtons[25] = GUICtrlCreateButton("Shadow_26", 280, 470, 270, 50, -1)
$arrShadowButtons[26] = GUICtrlCreateButton("Shadow_27", 550, 470, 270, 50, -1)
$arrShadowButtons[27] = GUICtrlCreateButton("Shadow_28", 10, 520, 270, 50, -1)
$arrShadowButtons[28] = GUICtrlCreateButton("Shadow_29", 280, 520, 270, 50, -1)
$arrShadowButtons[29] = GUICtrlCreateButton("Shadow_00", 550, 520, 270, 50, -1)

$arrQAButtons[0] = GUICtrlCreateButton("QA_01", 10, 70, 270, 50, -1)
$arrQAButtons[1] = GUICtrlCreateButton("QA_02", 280, 70, 270, 50, -1)
$arrQAButtons[2] = GUICtrlCreateButton("QA_03", 550, 70, 270, 50, -1)
$arrQAButtons[3] = GUICtrlCreateButton("QA_04", 10, 120, 270, 50, -1)
$arrQAButtons[4] = GUICtrlCreateButton("QA_05", 280, 120, 270, 50, -1)
$arrQAButtons[5] = GUICtrlCreateButton("QA_06", 550, 120, 270, 50, -1)
$arrQAButtons[6] = GUICtrlCreateButton("QA_07", 10, 170, 270, 50, -1)
$arrQAButtons[7] = GUICtrlCreateButton("QA_08", 280, 170, 270, 50, -1)
$arrQAButtons[8] = GUICtrlCreateButton("QA_09", 550, 170, 270, 50, -1)
$arrQAButtons[9] = GUICtrlCreateButton("QA_10", 10, 220, 270, 50, -1)
$arrQAButtons[10] = GUICtrlCreateButton("QA_11", 280, 220, 270, 50, -1)
$arrQAButtons[11] = GUICtrlCreateButton("QA_12", 550, 220, 270, 50, -1)
$arrQAButtons[12] = GUICtrlCreateButton("QA_13", 10, 270, 270, 50, -1)
$arrQAButtons[13] = GUICtrlCreateButton("QA_14", 280, 270, 270, 50, -1)
$arrQAButtons[14] = GUICtrlCreateButton("QA_15", 550, 270, 270, 50, -1)
$arrQAButtons[15] = GUICtrlCreateButton("QA_16", 10, 320, 270, 50, -1)
$arrQAButtons[16] = GUICtrlCreateButton("QA_17", 280, 320, 270, 50, -1)
$arrQAButtons[17] = GUICtrlCreateButton("QA_18", 550, 320, 270, 50, -1)
$arrQAButtons[18] = GUICtrlCreateButton("QA_19", 10, 370, 270, 50, -1)
$arrQAButtons[19] = GUICtrlCreateButton("QA_20", 280, 370, 270, 50, -1)
$arrQAButtons[20] = GUICtrlCreateButton("QA_21", 550, 370, 270, 50, -1)
$arrQAButtons[21] = GUICtrlCreateButton("QA_22", 10, 420, 270, 50, -1)
$arrQAButtons[22] = GUICtrlCreateButton("QA_23", 280, 420, 270, 50, -1)
$arrQAButtons[23] = GUICtrlCreateButton("QA_24", 550, 420, 270, 50, -1)
$arrQAButtons[24] = GUICtrlCreateButton("QA_25", 10, 470, 270, 50, -1)
$arrQAButtons[25] = GUICtrlCreateButton("QA_26", 280, 470, 270, 50, -1)
$arrQAButtons[26] = GUICtrlCreateButton("QA_27", 550, 470, 270, 50, -1)
$arrQAButtons[27] = GUICtrlCreateButton("QA_28", 10, 520, 270, 50, -1)
$arrQAButtons[28] = GUICtrlCreateButton("QA_29", 280, 520, 270, 50, -1)
$arrQAButtons[29] = GUICtrlCreateButton("QA_30", 550, 520, 270, 50, -1)


GUISetState()
For $i = 0 To UBound($arrProductionButtons) - 1 Step 1
    GUICtrlSetState($arrProductionButtons[$i], $GUI_HIDE)
    GUICtrlSetState($arrShadowButtons[$i], $GUI_HIDE)
    GUICtrlSetState($arrQAButtons[$i], $GUI_HIDE)
Next
#EndRegion ---Head--

#Region --- Form ---



#Region --- Loop ---
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            $Environment = GUICtrlRead($Combo_01)
            If $Environment = "Production" Then

                For $i = 0 To UBound($arrProductionButtons) - 1 Step 1
                    GUICtrlSetState($arrProductionButtons[$i], $GUI_SHOW)
                    GUICtrlSetState($arrShadowButtons[$i], $GUI_HIDE)
                    GUICtrlSetState($arrQAButtons[$i], $GUI_HIDE)
                Next

            ElseIf $Environment = "Shadow" Then
                For $i = 0 To UBound($arrProductionButtons) - 1 Step 1
                    GUICtrlSetState($arrProductionButtons[$i], $GUI_HIDE)
                    GUICtrlSetState($arrShadowButtons[$i], $GUI_SHOW)
                    GUICtrlSetState($arrQAButtons[$i], $GUI_HIDE)
                Next

            ElseIf $Environment = "QA" Then
                For $i = 0 To UBound($arrProductionButtons) - 1 Step 1
                    GUICtrlSetState($arrProductionButtons[$i], $GUI_HIDE)
                    GUICtrlSetState($arrShadowButtons[$i], $GUI_HIDE)
                    GUICtrlSetState($arrQAButtons[$i], $GUI_SHOW)
                Next

            Else

                For $i = 0 To UBound($arrProductionButtons) - 1 Step 1
                    GUICtrlSetState($arrProductionButtons[$i], $GUI_HIDE)
                    GUICtrlSetState($arrShadowButtons[$i], $GUI_HIDE)
                    GUICtrlSetState($arrQAButtons[$i], $GUI_HIDE)
                Next

            EndIf

    EndSelect
WEnd
#EndRegion --- Loop ---

#Region --- Additional Functions ---
#EndRegion --- Additional Functions --

:)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Why not just use GuiCtrlSetData?  Example

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <ComboConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>

If _Singleton("JETS", 1) = 0 Then
    MsgBox($MB_SYSTEMMODAL, "Warning", "JETS is already running!")
    Exit
EndIf

Global $y = 70, $aButtons[30][2]

$hGUI = GUICreate("JETS", 829, 600, -1, -1, $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_MINIMIZEBOX)

$Combo_01 = GUICtrlCreateCombo("", 160, 20, 145, 21, -1)
GUICtrlSetData($Combo_01, "|Production|Shadow|QA", "")
$Label_01 = GUICtrlCreateLabel("Select Your Environment:", 20, 25, 140, 30, -1)

For $i = 0 To UBound($aButtons) - 1 Step 3
    $aButtons[$i][1] = $i + 1
    $aButtons[$i][0] = GUICtrlCreateButton($aButtons[$i][1], 10, $y, 270, 50)
    $aButtons[$i + 1][1] = $i + 2
    $aButtons[$i + 1][0] = GUICtrlCreateButton($aButtons[$i + 1][1], 280, $y, 270, 50)
    $aButtons[$i + 2][1] = $i + 3
    $aButtons[$i + 2][0] = GUICtrlCreateButton($aButtons[$i + 2][1], 550, $y, 270, 50)
    $y += 50
Next

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Combo_01
            For $i = 0 To UBound($aButtons) - 1
                If GUICtrlRead($Combo_01) = "" Then
                    GUICtrlSetData($aButtons[$i][0], $i + 1)
                Else
                    GUICtrlSetData($aButtons[$i][0], GUICtrlRead($Combo_01) & "_" & $i + 1)
                EndIf
            Next
        Case $aButtons[0][0] To $aButtons[UBound($aButtons) - 1][0]
            Switch GUICtrlRead($Combo_01)
                Case "Production"
                    MsgBox(4096, "Production Button Clicked", "Production_" & $aButtons[$msg - $aButtons[0][0]][1] & " clicked.")
                Case "Shadow"
                    MsgBox(4096, "Shadow Button Clicked", "Shadow_" & $aButtons[$msg - $aButtons[0][0]][1] & " clicked.")
                Case "QA"
                    MsgBox(4096, "QA Button Clicked", "QA_" & $aButtons[$msg - $aButtons[0][0]][1] & " clicked.")
                Case Else ;~ No Combo item selected
                    ContinueLoop
            EndSwitch
    EndSwitch
WEnd

 

Link to comment
Share on other sites

33 minutes ago, FrancescoDiMuro said:

Use an array of controls as showed in the example below:

Hi @FrancescoDiMuro :

I would add a check to see if $Environment has changed. Otherwise the message boxes are permanently redrawn, which causes flickering.

#Region ---Head--
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <ComboConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>


; Declaring three Global arrays of 30 elements
Global $arrProductionButtons[30]
Global $arrShadowButtons[30]
Global $arrQAButtons[30]

Global $Environment         = "Production"
Global $EnvironmentSelected = "Production"
Global $bEnvironmentShow    = False

If _Singleton("JETS", 1) = 0 Then
    MsgBox($MB_SYSTEMMODAL, "Warning", "JETS is already running!")
    Exit
EndIf

$hGUI = GUICreate("JETS", 829, 600, -1, -1, $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_MINIMIZEBOX)

$Combo_01 = GUICtrlCreateCombo("", 160, 20, 145, 21, -1)
GUICtrlSetData($Combo_01, "Production|Shadow|QA", "")
$Label_01 = GUICtrlCreateLabel("Select Your Environment:", 20, 25, 140, 30, -1)

; Assigning each control to an element?
$arrProductionButtons[0] = GUICtrlCreateButton("Production_01", 10, 70, 270, 50, -1)
$arrProductionButtons[1] = GUICtrlCreateButton("Production_02", 280, 70, 270, 50, -1)
$arrProductionButtons[2] = GUICtrlCreateButton("Production_03", 550, 70, 270, 50, -1)
$arrProductionButtons[3] = GUICtrlCreateButton("Production_04", 10, 120, 270, 50, -1)
$arrProductionButtons[4] = GUICtrlCreateButton("Production_05", 280, 120, 270, 50, -1)
$arrProductionButtons[5] = GUICtrlCreateButton("Production_06", 550, 120, 270, 50, -1)
$arrProductionButtons[6] = GUICtrlCreateButton("Production_07", 10, 170, 270, 50, -1)
$arrProductionButtons[7] = GUICtrlCreateButton("Production_08", 280, 170, 270, 50, -1)
$arrProductionButtons[8] = GUICtrlCreateButton("Production_09", 550, 170, 270, 50, -1)
$arrProductionButtons[9] = GUICtrlCreateButton("Production_10", 10, 220, 270, 50, -1)
$arrProductionButtons[10] = GUICtrlCreateButton("Production_11", 280, 220, 270, 50, -1)
$arrProductionButtons[11] = GUICtrlCreateButton("Production_12", 550, 220, 270, 50, -1)
$arrProductionButtons[12] = GUICtrlCreateButton("Production_13", 10, 270, 270, 50, -1)
$arrProductionButtons[13] = GUICtrlCreateButton("Production_14", 280, 270, 270, 50, -1)
$arrProductionButtons[14] = GUICtrlCreateButton("Production_15", 550, 270, 270, 50, -1)
$arrProductionButtons[15] = GUICtrlCreateButton("Production_16", 10, 320, 270, 50, -1)
$arrProductionButtons[16] = GUICtrlCreateButton("Production_17", 280, 320, 270, 50, -1)
$arrProductionButtons[17] = GUICtrlCreateButton("Production_18", 550, 320, 270, 50, -1)
$arrProductionButtons[18] = GUICtrlCreateButton("Production_19", 10, 370, 270, 50, -1)
$arrProductionButtons[19] = GUICtrlCreateButton("Production_20", 280, 370, 270, 50, -1)
$arrProductionButtons[20] = GUICtrlCreateButton("Production_21", 550, 370, 270, 50, -1)
$arrProductionButtons[21] = GUICtrlCreateButton("Production_22", 10, 420, 270, 50, -1)
$arrProductionButtons[22] = GUICtrlCreateButton("Production_23", 280, 420, 270, 50, -1)
$arrProductionButtons[23] = GUICtrlCreateButton("Production_24", 550, 420, 270, 50, -1)
$arrProductionButtons[24] = GUICtrlCreateButton("Production_25", 10, 470, 270, 50, -1)
$arrProductionButtons[25] = GUICtrlCreateButton("Production_26", 280, 470, 270, 50, -1)
$arrProductionButtons[26] = GUICtrlCreateButton("Production_27", 550, 470, 270, 50, -1)
$arrProductionButtons[27] = GUICtrlCreateButton("Production_28", 10, 520, 270, 50, -1)
$arrProductionButtons[28] = GUICtrlCreateButton("Production_29", 280, 520, 270, 50, -1)
$arrProductionButtons[29] = GUICtrlCreateButton("Production_30", 550, 520, 270, 50, -1)

$arrShadowButtons[0] = GUICtrlCreateButton("Shadow_01", 10, 70, 270, 50, -1)
$arrShadowButtons[1] = GUICtrlCreateButton("Shadow_02", 280, 70, 270, 50, -1)
$arrShadowButtons[2] = GUICtrlCreateButton("Shadow_03", 550, 70, 270, 50, -1)
$arrShadowButtons[3] = GUICtrlCreateButton("Shadow_04", 10, 120, 270, 50, -1)
$arrShadowButtons[4] = GUICtrlCreateButton("Shadow_05", 280, 120, 270, 50, -1)
$arrShadowButtons[5] = GUICtrlCreateButton("Shadow_06", 550, 120, 270, 50, -1)
$arrShadowButtons[6] = GUICtrlCreateButton("Shadow_07", 10, 170, 270, 50, -1)
$arrShadowButtons[7] = GUICtrlCreateButton("Shadow_08", 280, 170, 270, 50, -1)
$arrShadowButtons[8] = GUICtrlCreateButton("Shadow_09", 550, 170, 270, 50, -1)
$arrShadowButtons[9] = GUICtrlCreateButton("Shadow_10", 10, 220, 270, 50, -1)
$arrShadowButtons[10] = GUICtrlCreateButton("Shadow_11", 280, 220, 270, 50, -1)
$arrShadowButtons[11] = GUICtrlCreateButton("Shadow_12", 550, 220, 270, 50, -1)
$arrShadowButtons[12] = GUICtrlCreateButton("Shadow_13", 10, 270, 270, 50, -1)
$arrShadowButtons[13] = GUICtrlCreateButton("Shadow_14", 280, 270, 270, 50, -1)
$arrShadowButtons[14] = GUICtrlCreateButton("Shadow_15", 550, 270, 270, 50, -1)
$arrShadowButtons[15] = GUICtrlCreateButton("Shadow_16", 10, 320, 270, 50, -1)
$arrShadowButtons[16] = GUICtrlCreateButton("Shadow_17", 280, 320, 270, 50, -1)
$arrShadowButtons[17] = GUICtrlCreateButton("Shadow_18", 550, 320, 270, 50, -1)
$arrShadowButtons[18] = GUICtrlCreateButton("Shadow_19", 10, 370, 270, 50, -1)
$arrShadowButtons[19] = GUICtrlCreateButton("Shadow_20", 280, 370, 270, 50, -1)
$arrShadowButtons[20] = GUICtrlCreateButton("Shadow_21", 550, 370, 270, 50, -1)
$arrShadowButtons[21] = GUICtrlCreateButton("Shadow_22", 10, 420, 270, 50, -1)
$arrShadowButtons[22] = GUICtrlCreateButton("Shadow_23", 280, 420, 270, 50, -1)
$arrShadowButtons[23] = GUICtrlCreateButton("Shadow_24", 550, 420, 270, 50, -1)
$arrShadowButtons[24] = GUICtrlCreateButton("Shadow_25", 10, 470, 270, 50, -1)
$arrShadowButtons[25] = GUICtrlCreateButton("Shadow_26", 280, 470, 270, 50, -1)
$arrShadowButtons[26] = GUICtrlCreateButton("Shadow_27", 550, 470, 270, 50, -1)
$arrShadowButtons[27] = GUICtrlCreateButton("Shadow_28", 10, 520, 270, 50, -1)
$arrShadowButtons[28] = GUICtrlCreateButton("Shadow_29", 280, 520, 270, 50, -1)
$arrShadowButtons[29] = GUICtrlCreateButton("Shadow_00", 550, 520, 270, 50, -1)

$arrQAButtons[0] = GUICtrlCreateButton("QA_01", 10, 70, 270, 50, -1)
$arrQAButtons[1] = GUICtrlCreateButton("QA_02", 280, 70, 270, 50, -1)
$arrQAButtons[2] = GUICtrlCreateButton("QA_03", 550, 70, 270, 50, -1)
$arrQAButtons[3] = GUICtrlCreateButton("QA_04", 10, 120, 270, 50, -1)
$arrQAButtons[4] = GUICtrlCreateButton("QA_05", 280, 120, 270, 50, -1)
$arrQAButtons[5] = GUICtrlCreateButton("QA_06", 550, 120, 270, 50, -1)
$arrQAButtons[6] = GUICtrlCreateButton("QA_07", 10, 170, 270, 50, -1)
$arrQAButtons[7] = GUICtrlCreateButton("QA_08", 280, 170, 270, 50, -1)
$arrQAButtons[8] = GUICtrlCreateButton("QA_09", 550, 170, 270, 50, -1)
$arrQAButtons[9] = GUICtrlCreateButton("QA_10", 10, 220, 270, 50, -1)
$arrQAButtons[10] = GUICtrlCreateButton("QA_11", 280, 220, 270, 50, -1)
$arrQAButtons[11] = GUICtrlCreateButton("QA_12", 550, 220, 270, 50, -1)
$arrQAButtons[12] = GUICtrlCreateButton("QA_13", 10, 270, 270, 50, -1)
$arrQAButtons[13] = GUICtrlCreateButton("QA_14", 280, 270, 270, 50, -1)
$arrQAButtons[14] = GUICtrlCreateButton("QA_15", 550, 270, 270, 50, -1)
$arrQAButtons[15] = GUICtrlCreateButton("QA_16", 10, 320, 270, 50, -1)
$arrQAButtons[16] = GUICtrlCreateButton("QA_17", 280, 320, 270, 50, -1)
$arrQAButtons[17] = GUICtrlCreateButton("QA_18", 550, 320, 270, 50, -1)
$arrQAButtons[18] = GUICtrlCreateButton("QA_19", 10, 370, 270, 50, -1)
$arrQAButtons[19] = GUICtrlCreateButton("QA_20", 280, 370, 270, 50, -1)
$arrQAButtons[20] = GUICtrlCreateButton("QA_21", 550, 370, 270, 50, -1)
$arrQAButtons[21] = GUICtrlCreateButton("QA_22", 10, 420, 270, 50, -1)
$arrQAButtons[22] = GUICtrlCreateButton("QA_23", 280, 420, 270, 50, -1)
$arrQAButtons[23] = GUICtrlCreateButton("QA_24", 550, 420, 270, 50, -1)
$arrQAButtons[24] = GUICtrlCreateButton("QA_25", 10, 470, 270, 50, -1)
$arrQAButtons[25] = GUICtrlCreateButton("QA_26", 280, 470, 270, 50, -1)
$arrQAButtons[26] = GUICtrlCreateButton("QA_27", 550, 470, 270, 50, -1)
$arrQAButtons[27] = GUICtrlCreateButton("QA_28", 10, 520, 270, 50, -1)
$arrQAButtons[28] = GUICtrlCreateButton("QA_29", 280, 520, 270, 50, -1)
$arrQAButtons[29] = GUICtrlCreateButton("QA_30", 550, 520, 270, 50, -1)


GUISetState()
For $i = 0 To UBound($arrProductionButtons) - 1 Step 1
    GUICtrlSetState($arrProductionButtons[$i], $GUI_HIDE)
    GUICtrlSetState($arrShadowButtons[$i], $GUI_HIDE)
    GUICtrlSetState($arrQAButtons[$i], $GUI_HIDE)
Next
#EndRegion ---Head--

#Region --- Form ---



#Region --- Loop ---
While 1
    $msg = GUIGetMsg()
    $EnvironmentSelected = GUICtrlRead($Combo_01)
    If $EnvironmentSelected <> $Environment Then
        $bEnvironmentShow = True
        $Environment = $EnvironmentSelected
        ConsoleWrite("< @@DEBUG : New EnvironmentSelected <" & $Environment & ">          " & @CRLF)
    EndIf


    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            ; check if $Environment has changed - otherwise it's flickering
            If $bEnvironmentShow Then
                If $Environment = "Production" Then
                    For $i = 0 To UBound($arrProductionButtons) - 1 Step 1
                        GUICtrlSetState($arrProductionButtons[$i], $GUI_SHOW)
                        GUICtrlSetState($arrShadowButtons[$i], $GUI_HIDE)
                        GUICtrlSetState($arrQAButtons[$i], $GUI_HIDE)
                    Next

                ElseIf $Environment = "Shadow" Then
                    For $i = 0 To UBound($arrProductionButtons) - 1 Step 1
                        GUICtrlSetState($arrProductionButtons[$i], $GUI_HIDE)
                        GUICtrlSetState($arrShadowButtons[$i], $GUI_SHOW)
                        GUICtrlSetState($arrQAButtons[$i], $GUI_HIDE)
                    Next

                ElseIf $Environment = "QA" Then
                    For $i = 0 To UBound($arrProductionButtons) - 1 Step 1
                        GUICtrlSetState($arrProductionButtons[$i], $GUI_HIDE)
                        GUICtrlSetState($arrShadowButtons[$i], $GUI_HIDE)
                        GUICtrlSetState($arrQAButtons[$i], $GUI_SHOW)
                    Next

                Else

                    For $i = 0 To UBound($arrProductionButtons) - 1 Step 1
                        GUICtrlSetState($arrProductionButtons[$i], $GUI_HIDE)
                        GUICtrlSetState($arrShadowButtons[$i], $GUI_HIDE)
                        GUICtrlSetState($arrQAButtons[$i], $GUI_HIDE)
                    Next

                EndIf

                $bEnvironmentShow = False
            EndIf

    EndSelect
WEnd
#EndRegion --- Loop ---

#Region --- Additional Functions ---
#EndRegion --- Additional Functions --

 

EDIT : The solution of @Subz is better :) !

 

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

You could also increase readability of the button creation like this :

Local $av_btn_Production[30], $av_btn_Shadow[30], $av_btn_QA[30], $iInd

$iInd = 0
For $y = 0 To 9
  For $x = 0 To 2
    $av_btn_Production[$iInd] = GUICtrlCreateButton("Production_" & StringFormat("%02i", $iInd + 1), 10 + 270 * $x, 70 + 50 * $y, 270, 50)
    GUICtrlSetState(-1, $GUI_HIDE)
    $iInd += 1
  Next
Next
$iInd = 0
For $y = 0 To 9
  For $x = 0 To 2
    $av_btn_Shadow[$iInd] = GUICtrlCreateButton("Shadow_" & StringFormat("%02i", $iInd + 1), 10 + 270 * $x, 70 + 50 * $y, 270, 50)
    GUICtrlSetState(-1, $GUI_HIDE)
    $iInd += 1
  Next
Next
$iInd = 0
For $y = 0 To 9
  For $x = 0 To 2
    $av_btn_QA[$iInd] = GUICtrlCreateButton("QA_" & StringFormat("%02i", $iInd + 1), 10 + 270 * $x, 70 + 50 * $y, 270, 50)
    GUICtrlSetState(-1, $GUI_HIDE)
    $iInd += 1
  Next
Next

 

Link to comment
Share on other sites

Hi All,

Thanks to everyone for their input, advice, and suggestions - as always the community here is very much appreciated 🙂

Additional thanks to Musashi - The flickering issue you mentioned was something I was going to tackle after this, and you solved it as part of this! 🙂

 

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