Help! Button Variable issue

Recommended Posts

jgus 0

jgus 0

I have to first mention I am not a programmer by any means so I definitely need some help to get past this issue.

I am writing a script that will look at a certain directory that contains some .exe files and creates a GUI button for each .exe file it finds. It uses the FileFindNextFile command and goes through a loop once for each exe it finds and creates the button with the following code.

This works great in that it creates seperate buttons named according to each exe file. The problem is that I want to be able to click on each button and have it run that specific exe file that it refers to. Notice that each time though the loop $GuiAppsButton value will be replaced. So if I later wait for a click of $GuiAppsButton it would only actually run anything on the last button since it was last assigned the value $GuiAppsButton.

This is very obvious why this is happening but I am just not having much luck thinking of a way around this problem. It's almost like each time through the loop it need to dynamically assign a different variable name so that multiple $GuiAppsButtons will exist to be able to call.

I hope this makes sense to someone. Let me know if you need more info.

Share this post

Link to post

Share on other sites

seandisanti 2

seandisanti 2

I have to first mention I am not a programmer by any means so I definitely need some help to get past this issue.

I am writing a script that will look at a certain directory that contains some .exe files and creates a GUI button for each .exe file it finds. It uses the FileFindNextFile command and goes through a loop once for each exe it finds and creates the button with the following code.

This works great in that it creates seperate buttons named according to each exe file. The problem is that I want to be able to click on each button and have it run that specific exe file that it refers to. Notice that each time though the loop $GuiAppsButton value will be replaced. So if I later wait for a click of $GuiAppsButton it would only actually run anything on the last button since it was last assigned the value $GuiAppsButton.

This is very obvious why this is happening but I am just not having much luck thinking of a way around this problem. It's almost like each time through the loop it need to dynamically assign a different variable name so that multiple $GuiAppsButtons will exist to be able to call.

I hope this makes sense to someone. Let me know if you need more info.

i'll see if i can get something written up for you, sounds like a fun little project.

nice. i was going about it kind of the same way, except using a 2 dimensional array, [$x][0] being the filename, and [$x][1] being the GUICtrlCreateButton(). i didn't get mine finished yet though...

***edit***

yes i decided it would be silly to continue doing mine, i've already explained the only real difference, and i think the OP could figure out how to add the small bit of code necessary to change CS's if they wanted to go that route.

Edit3: Ok, I have to stop, something keep drawing me back to this thread!! Buttons should be spaced right and width should be adjusted accordingly. Still a rough rough idea, I have a better one (idea), but no desire to write it

Edited March 4, 2006 by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post

Link to post

Share on other sites

jgus 0

jgus 0

I had also figured out that you could use the ASSIGN command to create the dynamically incremented variable(ie var0, var1, var2). But I was still stumped on how I was going to get each one to run from a single command. The GuiCtrlRead($msg) is what I needed to flick on that dim light in my head.

Thanks again.

Share this post

Link to post

Share on other sites

jgus 0

jgus 0

OK.......I am now thinking about taking this little project one step further and I am stumped yet once again. I would like to make it so that the label on the button could be changed by the user to something more meaningfull. Like maybe right clicking on it would give the option to change the button text. I was thinking of using an ini file to store this information and the ini file would be created the first time the program is opened. So by default the buttons would just be named according to the exe's and then the user could change them later if they wanted to. I was thinking the ini might look something like this.

[1]

exe=filemon.exe

alias=File Monitor

[2]

exe=diskmon.exe

alias=Disk Monitor

I can easily figure out how to use the ini commands to create the ini file, but when trying to figure out how to get the button to open the exe is my problem. Since the button title may now not equal the exe file name I'm not sure exactly how to match up the button with the exe.

CyberSlug 3

CyberSlug 3

When a context menu is clicked, you need to convert its Gui ID number to a flat index: $msg - $ContextMenuItem[0] + 1

For all I know, the $msg id could be 25. But if the zeroth contextMenuItem ID is 22, then we know the index of the click was 4 (25 - 22 + 1). So we want to update the text of $Button[4]. Just set the button text and upadte the alias value from section "4" of our ini file!