Jump to content

Recommended Posts

Posted (edited)

I have the following sample script for where I have 16 buttons and initially 15 of the buttons are disabled.  I then loop through an array and try to re-enabled the buttons.  However, only 13 of the 15 buttons are enabled.  An _arraydisplay($aButtons) shows all 15 elements in there.  I know it must be something easy for experience folks, but i am not seeing where I went wrong.  Can someone help shed light on my sample script?  Thank you.

#include <ScrollBarConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiComboBox.au3>
#include <GuiRichEdit.au3>
#include <GuiButton.au3>
#include <Constants.au3>
#include <GUIEdit.au3>
#include <Array.au3>
#include <File.au3>

_Start()

Func _Start()
    Global $LHToolBar = GUICreate("Toolbar", 823, 56, -1, -1)
    Global $Button1 = GUICtrlCreateButton("", 6, 6, 43, 43, $BS_ICON)
    Global $Button2 = GUICtrlCreateButton("", 55, 6, 43, 43, $BS_ICON)
    Global $Button3 = GUICtrlCreateButton("", 104, 6, 43, 43, $BS_ICON)
    Global $Button4 = GUICtrlCreateButton("", 153, 6, 43, 43, $BS_ICON)
    Global $Button5 = GUICtrlCreateButton("", 202, 6, 43, 43, $BS_ICON)
    Global $Button6 = GUICtrlCreateButton("", 257, 6, 43, 43, $BS_ICON)
    Global $Button7 = GUICtrlCreateButton("", 306, 6, 43, 43, $BS_ICON)
    Global $Button8 = GUICtrlCreateButton("", 355, 6, 43, 43, $BS_ICON)
    Global $Button9 = GUICtrlCreateButton("", 404, 6, 43, 43, $BS_ICON)
    Global $Button10 = GUICtrlCreateButton("", 453, 6, 43, 43, $BS_ICON)
    Global $Button11 = GUICtrlCreateButton("", 508, 6, 43, 43, $BS_ICON)
    Global $Button12 = GUICtrlCreateButton("", 557, 6, 43, 43, $BS_ICON)
    Global $Button13 = GUICtrlCreateButton("", 606, 6, 43, 43, $BS_ICON)
    Global $Button14 = GUICtrlCreateButton("", 655, 6, 43, 43, $BS_ICON)
    Global $Button15 = GUICtrlCreateButton("", 704, 6, 43, 43, $BS_ICON)
    Global $Button16 = GUICtrlCreateButton("", 773, 6, 43, 43, $BS_ICON)
    GUISetState(@SW_SHOW)
    ;Press ESC key to terminates the toolbar
    HotKeySet("{ESC}", "_Stop")

    Global $aButtons[15] = [ _
            "$Button1", _
            "$Button2", _
            "$Button3", _
            "$Button4", _
            "$Button5", _
            "$Button6", _
            "$Button7", _
            "$Button8", _
            "$Button9", _
            "$Button10", _
            "$Button11", _
            "$Button12", _
            "$Button13", _
            "$Button14", _
            "$Button15"]

    ;Let's disable 15 of those buttons.
    For $i = $Button1 To $Button15
        ConsoleWrite($i & @CRLF)
        GUICtrlSetState($i, $GUI_DISABLE)
    Next
    MsgBox(0, "", "Buttons are DISABLED!")

    ;Let's enable those 15 buttons.
    For $i = 0 To UBound($aButtons)
        GUICtrlSetState($i, $GUI_ENABLE)
    Next

;~  For $i = $Button1 To $Button15
;~      GUICtrlSetState($i, $GUI_ENABLE)
;~  Next

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>_Start

Func _Stop()
    Exit
EndFunc   ;==>_Stop

 

Edited by LisHawj
Posted
#include <ScrollBarConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiComboBox.au3>
#include <GuiRichEdit.au3>
#include <GuiButton.au3>
#include <Constants.au3>
#include <GUIEdit.au3>
#include <Array.au3>
#include <File.au3>


Global $aButtons[15]
Global $LHToolBar
_Start()

Func _Start()
    $LHToolBar = GUICreate("Toolbar", 823, 56, -1, -1)
    $Button15 = GUICtrlCreateButton("", 773, 6, 43, 43, $BS_ICON)

    For $i = 0 To UBound($aButtons,1) - 1
        $aButtons[$i] = GUICtrlCreateButton("", 6 + ($i*49), 6, 43, 43, $BS_ICON)
    Next
    
    GUISetState(@SW_SHOW)
    ;Press ESC key to terminates the toolbar
    HotKeySet("{ESC}", "_Stop")

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

    MsgBox(0, "", "Buttons are DISABLED!")

    ;Let's enable those 15 buttons.
    For $i = 0 To UBound($aButtons,1) - 1
        GUICtrlSetState($aButtons[$i], $GUI_ENABLE)
    Next

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>_Start

Func _Stop()
    Exit
EndFunc   ;==>_Stop

 

Posted (edited)
Just now, LisHawj said:

...but i am not seeing where I went wrong.

Hi LisHawj :)
The 1st control you create in a GUI always got an id = 3 (LarsJ, here)
If you check the value of the 1st control you created ($Button1), it will indicate 3, not 1
That difference of 2 explains why you're having 2 buttons not being re-enabled, as :

UBound($aButtons) = $Button13 = 15

Edit: concerning the mysterious control id's 1 and 2
I was lucky enough to find a control returning id = 1, but id# 2 is still a mystery. Maybe one day we'll know about id# 2 too...

Edited by pixelsearch

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted (edited)

Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. 
I wanted to thank you for this websites! Thanks for sharing. Great websites!

<links removed>

Edited by JLogan3o13
Posted

Thank you both for your inputs.  I did not know that the first control created used ID 3 by default and I did see that when I ran _WinAPI_GetDlgCtrlID(Guictrlgethandle()).  I simply didn't understand it and it all went downhill from there.  With your advice I modified my production script as follow and the script is working for me now.  Thank you very much.

For $i = 3 To 17
        GUICtrlSetState($i, $GUI_ENABLE)
    Next

 

Posted

I would suggest using an array as jugador did. That way, you can create controls on the GUI without worrying about where they are created (before/after your buttons)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Posted

@seadoggie01,

Thank you for the advice.  In the production script, the departments want "special" spacing between certain sets of buttons.  I could use a couple different button arrays in the format Jugador has provided, but it was easier to fix Find and Replace 6 lines.  Time permitting, I'll have to revisit the script and write it properly as recommended.  Thank you.

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
  • Recently Browsing   0 members

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