Sign in to follow this  
Followers 0
Ropetin Again

Dynamically Create Variable Names?

3 posts in this topic

I'm not sure if this makes sense or not, but I can't think of any other way to do it. Let me me explain what I'm trying to achieve. I have a text file acting as a 'config' file. Each line contains a single word, which I would like to be made into a button on a GUI. The text file is editable so the button names, and number of buttons can be easily changed by a user without editing the script. The file is read into an array with;

_FileReadToArray ( "buttonnames.txt", $aNames )

And I can determine how many buttons I need with;

$aNames[0]

To create the buttons I could do something to the effect of;

For $x = 1 to $aNames[0]
    ;Code to create button here
Next

The problem is, to read when a button is pressed, I need to do a;

$button = GUICtrlCreateButton (....

But it won't let me use (or I don't know how to use) a variable, in this case $x, as an additional part of the variable name, so I can create $button1, $button2, $button3 etc.

Any ideas how I can do this, or any suggestions on a better way of achieving what I'd like to do?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try with an array:

Dim $Buttons[$aNames[0]+1]
For $x= 1 to $aNames[0]
    $Buttons[$x] = GUICtrlCreateButton($aNames[$x]);skipped rest of parameters.
Next
Edited by Paulie

Share this post


Link to post
Share on other sites

An array, genius, thank you!

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