Kip Posted October 29, 2008 Share Posted October 29, 2008 (edited) Hi. I want to create variables on the fly. I use Assign() to create normal variables, which works very well: Assign ("MyNewVar","mw") MsgBox(0,"sdsds",Eval("MyNewVar")) But when I'm trying to create arrays that way, it doesnt work. Which actually makes sense since the helpfile doesnt say it's able to create arrays. Assign ("MyNewVar[1]","",2) Assign ("MyNewVar[0]","mw") MsgBox(0,"sdsds",Eval("MyNewVar[0]")) Does someone know how to do this? Edited October 29, 2008 by Kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
LarryDalooza Posted October 29, 2008 Share Posted October 29, 2008 consider...Assign("test",StringSplit("me,you",",")) MsgBox(4096,"",$test[0] & @LF & $test[1] & @LF & $test[2])however Scite will not like it... but it does run... save it and double click. Lar. AutoIt has helped make me wealthy Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 29, 2008 Share Posted October 29, 2008 Hi. I want to create variables on the fly. I use Assign() to create normal variables, which works very well: Assign ("MyNewVar","mw") MsgBox(0,"sdsds",Eval("MyNewVar")) But when I'm trying to create arrays that way, it doesnt work. Which actually makes sense since the helpfile doesnt say it's able to create arrays. Assign ("MyNewVar[1]","",2) Assign ("MyNewVar[0]","mw") MsgBox(0,"sdsds",Eval("MyNewVar[0]")) Does someone know how to do this? This is generally THE WRONG WAY to do things... but it can be done (sort of). You cannot make array references to an Eval() statement, but you can copy to a temp variable for the duration of the operation: #include <Array.au3> Global $avTemp[3] = [1, 2, 3] ; Create vars For $n = 1 To 3 Assign("Test_" & $n, $avTemp, 2) Next $avTemp = "" ; Change data For $n = 1 To 3 $avTemp = Eval("Test_" & $n) For $r = 0 To UBound($avTemp) - 1 $avTemp[$r] = $avTemp[$r] * $n Next Assign("Test_" & $n, $avTemp) Next ; Display results For $n = 1 To 3 $avTemp = Eval("Test_" & $n) _ArrayDisplay($avTemp, "$Test_" & $n) Next After creating them with Assign(), you could also hard-code references to $Test_1 thru $Test_3, but you'll get warning on syntax check that will have to be ignored, and if you know the variable names to hard-code -- what's the point in declaring them with Assign()? And besides, Assign/Eval are EVIL! Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Kip Posted October 29, 2008 Author Share Posted October 29, 2008 you could also hard-code references to $Test_1 thru $Test_3Well, hardcoding it in the script is not an option for me. and if you know the variable names to hard-code -- what's the point in declaring them with Assign()?Avoiding the array in array problem This is generally THE WRONG WAY to do things... but it can be done (sort of).Thanks, Psalty. But that copies the whole array. (And I already knew that)Is there a better way? MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 29, 2008 Share Posted October 29, 2008 Thanks, Psalty. But that copies the whole array. (And I already knew that)Is there a better way?To quote myself: You cannot make array references to an Eval() statement...What, exactly, is your "Avoiding the array in array problem" problem? A better solution than Assign/Eval is surely available. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Kip Posted October 29, 2008 Author Share Posted October 29, 2008 Global $Array[5][7] Global $Bla[2][3] $Bla[1][2] = $Array; Array in array, which slows down the script. If I can believe the helpfile. MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
FaT3oYCG Posted October 29, 2008 Share Posted October 29, 2008 i dont really understand what you are talking about kip but you need to put #include <Array.au3> at the top of your script to use the _ArrayAdd() function. dim $Array_Name[1]; creates a blank array _ArrayAdd($Array_Name, "data"); adds this value to the array For $i = 1 To UBound($Array_Name, 1) - 1; set $i to 1 to the number of items in the $Array_Name the 1 means the first part of the array e.g. $Array_Name[first_part][second_part] and the -1 is because otherwise we go past the end of the table. ; do something Next; loop through until $i is equal to UBound($Array_Name, 1) - 1 some information about arrays and some things you can do with them, i dont know if any of that is what you need but it might help. Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right. Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 29, 2008 Share Posted October 29, 2008 Global $Array[5][7] Global $Bla[2][3] $Bla[1][2] = $Array; Array in array, which slows down the script. If I can believe the helpfile. How about a memory resident SQLite DB instead? Or converted strings saved in scripting dictionary? I still don't see how you got to a requirement for nested arrays AND a requirement for high speed AND are still doing it in AutoIt? It's an interpreted scripting language, man... calculating the negative gravimetric constant of dark energy is not AutoIt's forte. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Kip Posted October 30, 2008 Author Share Posted October 30, 2008 some information about arrays and some things you can do with them, i dont know if any of that is what you need but it might help.You're right. That's not what I need. How about a memory resident SQLite DB instead?Or converted strings saved in scripting dictionary?I can't afford to have external files.I still don't see how you got to a requirement for nested arrays AND a requirement for high speed AND are still doing it in AutoIt? It's an interpreted scripting language, man... calculating the negative gravimetric constant of dark energy is not AutoIt's forte. Nevermind, I guess I'll have to do it your way. MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 30, 2008 Share Posted October 30, 2008 I can't afford to have external files.The cool thing about the SQLite.au3 UDF is that it can create the DB entirely in memory, so the operations are pretty fast too. There is no file required. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Kip Posted October 30, 2008 Author Share Posted October 30, 2008 Cool, but I already have my answer. MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. 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