Jump to content
Sign in to follow this  
Damein

Capture which button was pressed/associated to variable?

Recommended Posts

Damein

I feel like I'm being stupid but I'm not understanding something...

I have an array of 20 with 20 different button associated with it.

IE:

$Button[1] = GuiCtrlCreateButton("Button 1") ect. ect.
$Button[2] = GuiCtrlCreateButton("Button 2") ect. ect.

And so on.

Now the text of the button (Button 1, Button 2 ect.) can change at anytime someone sets the text to something else.

So what I need to do is detect when someone presses a button, which variable is associated with it.

IE: 

$Button[$i] = GuiCtrlCreateButton("", 20, $Y, 160,30)
GuiCtrlSetOnEvent(-1, "_Action")

And then when that button is pressed it goes to the function _Action and then reads which button was pressed. I can read the text of the button just fine but I can't seem to find out how to read what variable is associated with said button.. I have an ID but that isn't what i want. I wan't just the number.

IE: If button[1] is pressed, I wan't the 1, not the ID or the text, I wan't the 1.

So like if $Button[18] is pressed, I wan't the number 18 pulled not the text of button #18

I'm sure I am just not thinking clearly.. 

But thanks in advance!

 

Oh, and I know I can accomplish this with setting up multiple functions that happen each time a specific button is pressed like so but I would rather not do that, I wan't it all into one function.

Button[$i] = GuiCtrlCreateButton("", 20, $Y, 160,30)
GuiCtrlSetOnEvent(-1, "_Action1")
Button[$i] = GuiCtrlCreateButton("", 20, $Y, 160,30)
GuiCtrlSetOnEvent(-1, "_Action2")

ect. ect. (Not the right coding way, but you get the idea)

Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites
BrewManNH

If you're using OnEvent mode, you can loop through the array's contents to see which of the control IDs match @GUI_CtrlId in your function.


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  

×