Sign in to follow this  
Followers 0
jack71

For..Next loop with GUICtrlSetState

7 posts in this topic

So I have a bunch of  GUICtrlSetOnEvents.  On my GUI I have an image that I use as background and for image mapping.  I have 24 labels that I place over the button of the background image.  I want to disable all 24 buttons after one is pressed so no other buttons can be pressed.

I'm trying something like this:

 

Global $imagemap[24] = [ "$button1", "$button2", "button3"......."$button24"]

Func  On_Button1()
 
For $i = 0 to UBound($imagemap) - 1
GUICtrlSetState($imagemap[$i], $GUI_DISABLE)
Next
 
;Do some stuff
 
EndFunc
 
This however doesn't work.  When I do a simple msgbox test in the For..Next loop it returns the correct variables, like $button1 etc but for some reason they're not being disabled.  If I manually put:
GUICtrlSetState($button1, $GUI_DISABLE) it works.
 
What am I doing wrong? :o

Share this post


Link to post
Share on other sites



Take the quotes off the variable names, you're storing strings in the array and not the value the variable holds.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

But the variables are holding Labels ie:

$button1 = GUICtrlCreateLabel("", 296, 152, 51, 49)
 GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
 GUICtrlSetOnEvent(-1, "On_Button1")
 
Which makes the Array value empty or invalid.  Nor does it work for me :)

 

Take the quotes off the variable names, you're storing strings in the array and not the value the variable holds.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Global $imagemap[24] = [ "$button1", "$button2", "$button3"......."$button24"]

Replace with : Global $imagemap[24] = [ $button1, $button2, $button3.......$button24]

Because "$button1" is string, not variance

(my english is not well)

Edited by moimon

Share this post


Link to post
Share on other sites

Did you do what I suggested to you to do, or are you going to argue about it? 

You are NOT storing the handles you are storing the string "$button1", "$button2" and not the contents of those variables. Your variables named $button1 etc. are holding the handles (technically control IDs but why quibble) but you are not using those variables in the snippet you posted in the first post.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Simmmah down nah! ;)

No I'm not arguing with you and yes I stated:

 Nor does it work for me :)

 

Did you do what I suggested to you to do, or are you going to argue about it? 

You are NOT storing the handles you are storing the string "$button1", "$button2" and not the contents of those variables. Your variables named $button1 etc. are holding the handles (technically control IDs but why quibble) but you are not using those variables in the snippet you posted in the first post.

 

With or without quotes my labels still function after the For Next loop that is supposed to disable them.

Share this post


Link to post
Share on other sites

Post your script or a reproducer script that demonstrates the issue, as it stands right now all I have is what you've posted and that's not enough to see what you're doing wrong. 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
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
Sign in to follow this  
Followers 0