Jump to content

Control id #'s for gui controls


Fractured
 Share

Recommended Posts

No, it is not possible as far as I know. They are internally generated and managed by AutoIt for each control. Only way to change them is to destroy the control :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

@Fractured My pleasure :)

I normally totally disregard the actual ID beside storing it inside a well-named variable, you can think of the variable as the name of the control. That is how I worked my way up in the beginning. Just my two cents ;)

Feel free to post about what you are trying to do and maybe some of us can offer suggestions.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Basically, I mapped an excel spreadsheet that holds our process here at work to an array. That way we could do non destructive editing and then be able to re save the excel spreadsheet with the changes when we were done. 

I was trying to use the control id's to make For/Next routines for fast checking to decide if the excel sheet needed to be updated. The problem was the gui I made had control id's that didn't align with the array rows/columns (my bad). 

But I was able to make a work-around....sloppy but it works!! Im still very new to using autoit, so my code isn't always great but it is improving...here is what I have so far.

; #INDEX# =================================================================================================
; Name ..........: Process dB Manager
; Version Date ..: 2018-09-17
; AutoIt Version : 3.3.8.1
; Author(s) .....: Charles Wright
; Dll(s) ........:
; Error handling :
; =========================================================================================================

; #Notes# =================================================================================================
;           column # = gui control name -Vaiable - Control id
;           0   =   Process - $Process - 21                     9   =   Gold Strike - $GoldStrike - 36
;           1   =   Rev - $Rev - 22                             10  =   Notes - $Edit1 - 37
;           2   =   Type - $Type - 23                           11  =   Drawing Control - $DrawingControl - 25
;           3   =   ROHS - $ROHS - 24                           12  =   Copper Reference - $CopperRef - 31
;           4   =   Copper - $Copper - 26                       13  =   Electroless Nickel Reference - $ElectrolessRef - 32
;           5   =   Electroless Nickel - $ElectrolessN - 27     14  =   Electrolytic Nickel Reference - $ElectrolyticRef - 33
;           6   =   Electrolytic Nickel - $ElectrolyticN - 28   15  =   Silver Reference - $SilverRef - 34
;           7   =   Silver - $SilverRef - 29                    16  =   Gold Ref - $GoldRef - 35
;           8   =   Gold - $Gold - 30
; =========================================================================================================

; Includes ================================================================================================
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <Excel.au3>
#include "ExtMsgBox.au3"
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
;==========================================================================================================

; Variables ===============================================================================================
$idMsg = 0

; Create application object
Local $oExcel = _Excel_Open(False)
$iIndex = ""
;==========================================================================================================


; Excel Process ===========================================================================================
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

; Open an existing workbook and return its object identifier.
Local $sWorkbook = @ScriptDir & "\Process.xlsx"
MsgBox($MB_SYSTEMMODAL, "Directory", $sWorkbook)
Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook, False, False)

If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Process Opening", "Error opening '" & $sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Process Opening", $sWorkbook & " has been opened successfully")

; Read the formulas of a cell range on sheet 2 of the specified workbook
Local $aResult = _Excel_RangeRead($oWorkbook, 1, Default, 1)

If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Process Load Report", "Error loading Processes." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Process Load Report", "Processes successfully loaded." & @CRLF & "Please click 'OK'")

;Array Debugging Code - Comment out after testing
;Local $iRows = UBound($aResult, $UBOUND_ROWS) ; Total number of rows. In this example it will be 10.
;Local $iCols = UBound($aResult, $UBOUND_COLUMNS) ; Total number of columns. In this example it will be 20.
;Local $iDimension = UBound($aResult, $UBOUND_DIMENSIONS) ; The dimension of the array e.g. 1/2/3 dimensional.;
;
;MsgBox($MB_SYSTEMMODAL, "", "The array is a " & $iDimension & " dimensional array with " & _
;            $iRows & " row(s) & " & $iCols & " column(s).")
;
$aTempModel = _ArrayUnique($aResult, 0)
$sModel = _ArrayToString($aTempModel, "|", 0)

;$stlModel = StringTrimLeft($sModel, 12)

;_ArrayDisplay($aModel, "$aModel Array")
;_ArrayDisplay($aResult, "$aResult Array")
;MsgBox($MB_SYSTEMMODAL, "$sModel String", $sModel)
;MsgBox($MB_SYSTEMMODAL, "$stlModel String", $stlModel)
;==========================================================================================================

; Gui =====================================================================================================
$Form1_1 = GUICreate("Process dB Manager", 653, 543, 740, 105)
GUISetBkColor(0xFFFBF0)
$Label1 = GUICtrlCreateLabel("Process:", 136, 16, 57, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Rev:", 296, 16, 32, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("Type", 416, 16, 36, 20, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("ROHS:", 464, 72, 46, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("Copper:", 200, 112, 52, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label6 = GUICtrlCreateLabel("Electroless Nickel:", 136, 144, 115, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label7 = GUICtrlCreateLabel("Electrolytic Nickel:", 136, 176, 113, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label8 = GUICtrlCreateLabel("Silver:", 208, 208, 41, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label9 = GUICtrlCreateLabel("Gold:", 216, 240, 36, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label10 = GUICtrlCreateLabel("Drawing Control:", 152, 72, 101, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label11 = GUICtrlCreateLabel("Copper Ref:", 432, 112, 76, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label12 = GUICtrlCreateLabel("Electroless Ref:", 416, 144, 98, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label13 = GUICtrlCreateLabel("Electrolytic Ref:", 416, 176, 96, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label14 = GUICtrlCreateLabel("Silver Ref:", 440, 208, 65, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label15 = GUICtrlCreateLabel("Gold Ref:", 448, 240, 60, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label16 = GUICtrlCreateLabel("Gold Strike", 440, 272, 70, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label17 = GUICtrlCreateLabel("Notes:", 136, 304, 43, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$List1 = GUICtrlCreateList("", 8, 16, 113, 409)     ; 20
$Process = GUICtrlCreateInput("", 200, 16, 65, 24)  ; 21
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Rev = GUICtrlCreateInput("", 336, 16, 41, 24)      ; 22
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Type = GUICtrlCreateInput("", 464, 16, 73, 24)     ;23
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$ROHS = GUICtrlCreateInput("", 512, 72, 25, 24, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))   ;24
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$DrawingControl = GUICtrlCreateInput("", 264, 72, 185, 24)      ; 25
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Copper = GUICtrlCreateInput("", 264, 112, 121, 24) ;26
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$ElectrolessN = GUICtrlCreateInput("", 264, 144, 121, 24)   ;27
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$ElectrolyticN = GUICtrlCreateInput("", 264, 176, 121, 24)  ;28
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Silver = GUICtrlCreateInput("", 264, 208, 121, 24)     ; 29
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Gold = GUICtrlCreateInput("", 264, 240, 121, 24)       ; 30
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$CopperRef = GUICtrlCreateInput("", 520, 112, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$ElectrolessRef = GUICtrlCreateInput("", 520, 144, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$ElectrolyticRef = GUICtrlCreateInput("", 520, 176, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$SilverRef = GUICtrlCreateInput("", 520, 208, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$GoldRef = GUICtrlCreateInput("", 520, 240, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$GoldStrike = GUICtrlCreateInput("", 520, 272, 25, 24, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Edit1 = GUICtrlCreateEdit("", 184, 304, 457, 121)
GUICtrlSetData(-1, "Edit1")
$SaveRecord = GUICtrlCreateButton("Save Record", 88, 448, 99, 25) ; 38
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$DeleteRecord = GUICtrlCreateButton("Delete Record", 264, 448, 107, 25) ; 39
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$SavedB = GUICtrlCreateButton("Save Database", 464, 448, 107, 25) ; 40
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
;==========================================================================================================

; GUICtrlSet ==============================================================================================
GUISetState(@SW_SHOW)
GUICtrlSetData($List1, "" & $sModel & "")
_ExtMsgBoxSet(1,0,default, default, 10, "Consolas", 1000, 1000)
;==========================================================================================================

; While Loop / Cases ======================================================================================
While 1
    $idMsg = GUIGetMsg()


    Select
        Case $idMsg = $GUI_EVENT_CLOSE
            _Excel_BookClose($oWorkbook, False)
            If @error Then Exit _ExtMsgBox(16,0, "Process Close Report", "Error closing processes." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
            _ExtMsgBox(64,0, "Process Close Report", "Processes successfully closed.")

            WinClose($oWorkbook, "Microsoft Excel")
            If Not @error Then
                _ExtMsgBox(64,0, "Excel", "Excel has been successfully closed.")
            Else
                _ExtMsgBox(16,0, "Excel", "Excel has failed to be closed.")
            EndIf

            ExitLoop
        Case $idMsg = $GUI_EVENT_MINIMIZE
            _ExtMsgBox(64,0, "", "Process Manager minimized", 2)
        Case $idMsg = $GUI_EVENT_MAXIMIZE
            _ExtMsgBox(64,0, "", "Process Manager restored", 2)
        Case $idMsg = $List1
            _Select($List1)
        Case $idMsg = $SaveRecord
            _Update()
    EndSelect
WEnd
;==========================================================================================================

; Functions ===============================================================================================
Func _Select($List1) ;$Combo1 - Selection of Process from Array to display in GUI
    $ChosenProc = GUICtrlRead($List1) ;$Combo1
    $iIndex = _ArraySearch($aResult, $ChosenProc)

    ;MsgBox($MB_SYSTEMMODAL, "$iIndex Array Row", $iIndex) ; $iIndex = The array row # that relates to the chosen process

    GUICtrlSetData($Process, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 0, 0))                ;0 / 21
    GUICtrlSetData($Rev, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 1, 1))                    ;1 / 22
    GUICtrlSetData($Type, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 2, 2))                   ;2 / 23
    GUICtrlSetData($ROHS, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 3, 3))                   ;3 / 24
    GUICtrlSetData($Copper, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 4, 4))                 ;4 / 26
    GUICtrlSetData($ElectrolessN, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 5, 5))           ;5 / 27
    GUICtrlSetData($ElectrolyticN, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 6, 6))          ;6 / 28
    GUICtrlSetData($Silver, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 7, 7))                 ;7 ; 29
    GUICtrlSetData($Gold, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 8, 8))                   ;8 / 30
    GUICtrlSetData($GoldStrike, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 9, 9))             ;9 / 36
    GUICtrlSetData($Edit1, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 10, 10))                ;10 / 37
    GUICtrlSetData($DrawingControl, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 11, 11))       ;11 / 25
    GUICtrlSetData($CopperRef, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 12, 12))            ;12 / 31
    GUICtrlSetData($ElectrolessRef, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 13, 13))       ;13 / 32
    GUICtrlSetData($ElectrolyticRef, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 14, 14))      ;14 / 33
    GUICtrlSetData($SilverRef, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 15, 15))            ;15 / 34
    GUICtrlSetData($GoldRef, _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", 16, 16))              ;16 / 35
EndFunc   ;==>_Select

Func _Update() ; Updates the process in the Excel dB
    ;MsgBox($MB_SYSTEMMODAL, "$iIndex Array Row", $iIndex) ; $iIndex = The array row # that relates to the chosen process
    $sRecordtoUpdate = ""
    $sRecordtoTest = ""
    $StringCount = ""

    ;Read Array Row to Compare
    For $ArryCount = 0 To 16
        $sRecordtoUpdate = $sRecordtoUpdate & "|" & _ArrayToString($aResult, "|", $iIndex, $iIndex, "|", $ArryCount, $ArryCount)
    Next
    $sRecordtoUpdate = StringTrimLeft($sRecordtoUpdate, 1)

    ;Read GUI Controls to Compare
    For $StringCountA = 21 To 24
        $sRecordtoTest = $sRecordtoTest & "|" & GUICtrlRead($StringCountA)
    Next
    For $StringCountB = 26 to 30
        $sRecordtoTest = $sRecordtoTest & "|" & GUICtrlRead($StringCountB)
    Next
    For $StringCountC = 36 to 37
        $sRecordtoTest = $sRecordtoTest & "|" & GUICtrlRead($StringCountC)
    Next
    $sRecordtoTest = $sRecordtoTest & "|" & GUICtrlRead(25)
    For $StringCountC = 31 to 35
        $sRecordtoTest = $sRecordtoTest & "|" & GUICtrlRead($StringCountC)
    Next
    $sRecordtoTest= StringTrimLeft($sRecordtoTest, 1)

    ;Compare the Array Row to the Gui Controls
    $iCmp = StringCompare($sRecordtoUpdate, $sRecordtoTest)
    If $iCmp = 0 Then
        _ExtMsgBox(64,0, "Process Save Error", "Process not Changed")
    Else
        _ExtMsgBox(64,0, "Process Save", "Process will be Updated")
        

    ;_ExtMsgBox(64,0, "Strings", "Record from Array" & @CRLF & $sRecordtoUpdate & @CRLF & $sRecordtoTest & @CRLF & "Record from GUI" &@CRLF & @CRLF & $iCmp)

EndFunc   ;==>_Update

 

 

Link to comment
Share on other sites

ID numbers for controls are assigned by order of creation, and usually cannot be assigned again, to prevent conflicts.

That said, I do know that in some instances at least, if you delete in reverse order from the last control created, you can work-around that limitation. That is certainly so for ListViews, where each list entry (row) gets its own control ID. With a single ListView for instance, you have it created last, to gain best advantage with List items.

In any case, like TheDcoder suggested, you are better off referencing by variable name in most cases, as they are easily reassigned.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

  • Moderators

Hi,

Quote

ID numbers for controls are assigned by order of creation, and usually cannot be assigned again, to prevent conflicts.

This is not strictly true.

When AutoIt creates a control using one of the GUICtrlCreate* functions it adds its details to an internal array and returns the index of that array as its "ControlID" - this value is used internally by AutoIt  to identify the controlwhen you use any of the GUICtrl* functions. To allow as many controls as possible, AutoIt looks for the first available empty index in this array to add the new control - normally this means that the returned ControlIDs increase by 1 for each created control. This allows for some easy manipulation of groups of controls by using their ControlIds as the loop counter - as you can see here:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$iStart = GUICtrlCreateDummy()
ConsoleWrite("Start : " & $iStart & @CRLF) ; Should be 3
For $i = 1 To 5
    $iCID = GUICtrlCreateLabel("", 10, 10 + (50 * $i), 200, 40)
    ; Display the returned ControlID - I have no idea what Autoit does with elements 1 & 2 !!!!!
    GUICtrlSetData(-1, $iCID)
    ; Set colour to red
    GUICtrlSetBkColor(-1, 0xFFCCCC)
Next
$iEnd = GUICtrlCreateDummy()
ConsoleWrite("End: " & $iEnd & @CRLF) ; Should be 9

$cAlter_1 = GUICtrlCreateButton("Change 1", 10, 450, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cAlter_1
            ; Set label CIDs as the loop counter
            For $i = $iStart + 1 To $iEnd - 1
                ; Change label colours
                GUICtrlSetBkColor($i, 0xCCFFCC)
            Next
    EndSwitch

WEnd

But look what happens if you delete a previously created control and then create another group of controls. Change the colour of the first group, then press the Delete, Create and Alter_2 buttons in order:

#include <GUIConstantsEx.au3>

Global $cLabel_6, $cLabel_10

$hGUI = GUICreate("Test", 500, 500)

$cLabel_1 = GUICtrlCreateLabel("", 10, 10, 200, 40)
; Display the returned ControlID - I have no idea what Autoit does with elements 1 & 2 !!!!!
GUICtrlSetData(-1, $cLabel_1)
; Set colour to red
GUICtrlSetBkColor(-1, 0xFFCCCC)
$cLabel_2 = GUICtrlCreateLabel("", 10, 60, 200, 40)
GUICtrlSetData(-1, $cLabel_2)
GUICtrlSetBkColor(-1, 0xFFCCCC)
$cLabel_3 = GUICtrlCreateLabel("", 10, 110, 200, 40)
GUICtrlSetData(-1, $cLabel_3)
GUICtrlSetBkColor(-1, 0xFFCCCC)
$cLabel_4 = GUICtrlCreateLabel("", 10, 160, 200, 40)
GUICtrlSetData(-1, $cLabel_4)
GUICtrlSetBkColor(-1, 0xFFCCCC)
$cLabel_5 = GUICtrlCreateLabel("", 10, 210, 200, 40)
GUICtrlSetData(-1, $cLabel_5)
GUICtrlSetBkColor(-1, 0xFFCCCC)

$cAlter_1 = GUICtrlCreateButton("Change 1", 10, 450, 80, 30)

$cAlter_2 = GUICtrlCreateButton("Change 2", 360, 450, 80, 30)
GUICtrlSetState($cAlter_2, $GUI_DISABLE)

$cDelete = GUICtrlCreateButton("Delete", 110, 450, 80, 30)

$cCreate = GUICtrlCreateButton("Create", 260, 450, 80, 30)
GUICtrlSetState($cCreate, $GUI_DISABLE)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cAlter_1
            ; Set label CIDs as the loop counter
            For $i = $cLabel_1 To $cLabel_5
                ; Change left label colours
                GUICtrlSetBkColor($i, 0xCCFFCC)
            Next
        Case $cAlter_2
            For $i = $cLabel_6 To $cLabel_10
                ; Change right label colours - or does it? <<<<<<<<<<<<<<<<<<<<<<<<<<<
                GUICtrlSetBkColor($i, 0xFFFFCC)
            Next
        Case $cDelete
            ; Delete one of the
            GUICtrlDelete($cLabel_3)
            GUICtrlSetState($cCreate, $GUI_ENABLE)
        Case $cCreate
            $cLabel_6 = GUICtrlCreateLabel("", 260, 10, 200, 40)
            GUICtrlSetData(-1, $cLabel_6)
            GUICtrlSetBkColor(-1, 0xCCCCFF)
            $cLabel_7 = GUICtrlCreateLabel("", 260, 60, 200, 40)
            GUICtrlSetData(-1, $cLabel_7)
            GUICtrlSetBkColor(-1, 0xCCCCFF)
            $cLabel_8 = GUICtrlCreateLabel("", 260, 110, 200, 40)
            GUICtrlSetData(-1, $cLabel_8)
            GUICtrlSetBkColor(-1, 0xCCCCFF)
            $cLabel_9 = GUICtrlCreateLabel("", 260, 160, 200, 40)
            GUICtrlSetData(-1, $cLabel_9)
            GUICtrlSetBkColor(-1, 0xCCCCFF)
            $cLabel_10 = GUICtrlCreateLabel("", 260, 210, 200, 40)
            GUICtrlSetData(-1, $cLabel_10)
            GUICtrlSetBkColor(-1, 0xCCCCFF)
            GUICtrlSetState($cAlter_2, $GUI_ENABLE)
    EndSwitch

WEnd

Not quite what you expected eh? You can see that the first of the new labels has taken the ControlID of the deleted label in the first group and so all the buttons and some of the first group of labels change colour as well - as their ControlIDs are now included in the loop.

The moral of the story? Be very careful when using ControlIDs as loop counters if any controls can be deleted anywhere in the script - and remember that deleting whole GUIs also deletes their controls automatically.

How should you action groups of controls? Store their returned ControlIDs in an array and loop through them - that way you will only ever use the correct values.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • 2 weeks later...
On 9/19/2018 at 2:56 AM, Melba23 said:

This is not strictly true.

Mmmmm ... I must have mis-remembered or maybe misunderstood what you told me years ago then, and which I have been operating on ever since ... unless of course things are different now to what they were then.

I guess the most important thing still stands though. Delete controls in the reverse order of creation, without skipping any, else undesired consequences might occur after subsequent new additions (created controls) ... especially with ListViews.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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