erebus Posted October 28, 2004 Share Posted October 28, 2004 Hello all, I wanted to write a function which will draw some GUI groups on a window and put some buttons in each of these groups (anyway my question has nothing to do with the GUI part of AutoIT and that's why I send my post here). However the problem with that function it that from this I also wanted to create some new variables based on a for...next loop. For example: Func WinDraw($left, $top, $wins) For $i = 1 to $wins GUICtrlCreateGroup("pc-" & $i, $left, $top, 120, 120) Global $control & $i = GUICtrlCreateButton($text & $i, $left + 20, $top + 20, 80, 40) Next EndFunc Ok, I know that $control & $i and $text & $i doesn't make any sense but I wanted to find a way to create a new variable name combining a fix name and a for...next based $i number so as to create new variables ending to a new number each time. Is there any way, or could such a feature be added in a future release? Thanks a lot. Link to comment Share on other sites More sharing options...
SlimShady Posted October 28, 2004 Share Posted October 28, 2004 It is added in the beta version. The function is called Assign. Check the help file for more info about the function. Link to comment Share on other sites More sharing options...
erebus Posted October 28, 2004 Author Share Posted October 28, 2004 (edited) That's great! Thanks a lot for your help. Edited October 28, 2004 by erebus Link to comment Share on other sites More sharing options...
erebus Posted October 28, 2004 Author Share Posted October 28, 2004 Ok... after testing a bit I found a serious limitation of the new "Assign" command. There is no way for the script to automatically know the new name after "assigning" a for...next variable to a fix variable name... For example in my code with the Assign command this should be: Local $control, $text GUICtrlCreateGroup("pc-" & $i, $l2, $t2, 120, 120) Assign($control, $i, 2) = GUICtrlCreateButton(Assign($text, $i, 2), $l3, $t3, 80, 40) ...so as to translate this as: $control1 = ...$text1... $control2 = ...$text2... $control3 = ...$text3... ...until the for...next loop finish. What I mean is that I search for a way to declare a variable name + a variable name automatically in the script. Maybe something such as $name($i)... Link to comment Share on other sites More sharing options...
Valik Posted October 28, 2004 Share Posted October 28, 2004 You're using it wrong, which is why. Assign(NAME, DATA, scope). The name field is the name you want the variable to have, this is what is on the left side of the equals sign; however, it is a string, not a variable. The data is the... data. It is what would be on the right side.Example:Assign("control" & $i, GUICtrlCreateButton("WTH were you doing here?", $l3, $t3, 80, 40), 2)I obviously stripped something from the example as I have no clue what the hell you were doing with that line. Link to comment Share on other sites More sharing options...
erebus Posted October 28, 2004 Author Share Posted October 28, 2004 You're using it wrong, which is why.Oh... my bad, I'm sorry :/I obviously stripped something from the example as I have no clue what the hell you were doing with that line.Nothing more than trying to assign a GUICtrlCreateButton to a variable so as to control its state later. The idea is to have a dynamically created variable name so as to eliminate code in the function. Thanks a lot, you are a life saver!Anyway I apologize if my questions seem stupid... :/ Link to comment Share on other sites More sharing options...
CyberSlug Posted October 28, 2004 Share Posted October 28, 2004 You could use an array.... Not sure exactly what you want, but this should show you the syntax. GuiCreate("Example") GuiSetState() WinDraw(10, 10, 5) While GuiGetMsg() <> -3 WEnd Func WinDraw($left, $top, $wins) Global $control[$wins+1];the plus one is so that the largest array element index == $wins For $i = 1 to $wins GUICtrlCreateGroup("pc-" & $i, $left, $top, 320, 320) $control[$i] = GUICtrlCreateButton("text" & $i, $left + 40*$i, $top + 40*$i, 80, 40) Next EndFunc Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
erebus Posted October 29, 2004 Author Share Posted October 29, 2004 Excellent and simple idea, I was so tired yesterday that I couldn't ever have thought of this... Thank you all guys, what is new for me to love in AutoIT now is this great community! You all are really amazing! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now