Sign in to follow this  
Followers 0
Shadowram

Alternative to Eval Array

4 posts in this topic

I'm trying to store info in an array, and then use that info in a fuction that has been passed only a string matching the array's name.

Example:

Global $test_ab[10] = ["test_ab", "t", 2500, 0, 0, 0, 0, 110]

Function($variable)

$question = $variable[2]

EndFunc

----------------------------------------------------------------

When $variable = "test_ab" I'm hoping that $question will = "t". The only way I can think to make this work would be:

$question = Eval($variable & "[2]")

But Eval is not designed to work like that. Any ideas to work around this? Thanks ;)

Share this post


Link to post
Share on other sites



Just leafe out the index. If you just use

Global $test_ab[10] = ["test_ab", "t", 2500, 0, 0, 0, 0, 110]

Function("test_ab")
$question = Eval("test_ab")
EndFunc

then $question IS an array containing all elemnts of the $test_ab array and then you can just do it with the index for example $question[2]

Share this post


Link to post
Share on other sites

Just leafe out the index. If you just use

Global $test_ab[10] = ["test_ab", "t", 2500, 0, 0, 0, 0, 110]

Function("test_ab")
$question = Eval("test_ab")
EndFunc

then $question IS an array containing all elemnts of the $test_ab array and then you can just do it with the index for example $question[2]

So easy! Thank you ;)

Share this post


Link to post
Share on other sites

Another way to look at it:

Global $test_ab[10] = ["test_ab", "t", 2500, 0, 0, 0, 0, 110]
Global $sTest = "test_ab"

$aVar = Eval($sTest)
For $n = 0 To 2
    $RET = $aVar[$n]
    ConsoleWrite("$" & $sTest & "[" & $n & "] = " & $RET & @LF)
Next

Keeping in mind that Assign/Eval are the evil spawn of daemons.

;)


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

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