Jump to content
Sign in to follow this  
loki1982

can a variable be used with a variable in the name?

Recommended Posts

loki1982

ok say I have 4 variables

$test1

$test2

$test3

$num

and depending on the result I want to display one of them. Is it possible to do somthing like

msgbox(0,"", $test & $num) so that it displays one of the test variables depending on what the var %num is?

I really dont want to do an if or select statment

Share this post


Link to post
Share on other sites
gadzail

I think "eval" can do the job..

search in autoit help .

Share this post


Link to post
Share on other sites
spudw2k

Share this post


Link to post
Share on other sites
aslani

I really dont want to do an if or select statment

I think you kinda have to since how do you intend to check each value and return the appropriate result?

Edit:

I completely missed what you're trying to do Hubertus72 got it right.

Edited by aslani

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Share this post


Link to post
Share on other sites
LarryDalooza

Dim $test[3]

$test[0]

$test[1]

$test[2]

$num

MsgBox(0,"",$test[$num])

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites
loki1982

$test1=111
$test2=222
$test3=333
$num=2
msgbox(0,"", Eval ("test" & $num))
This worked great. Then I tried to apply it to my code

$dearraynum1 = 1
Dim $encryptmethod1[62] = ["1","2","3","4","5","6","7","8","9","0","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","B","A","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

MsgBox(0,"",$dearraynum1)
MsgBox(0,"",$encryptmethod1[0])
MsgBox(0,"", Eval ("encryptmethod" & $dearraynum1 & "[0]"))

The first box displayed 1 like it should

second 1 like it should

third is blank

Share this post


Link to post
Share on other sites
loki1982

ok got it to work using

msgbox(0,"",Execute ('$encryptmethod' & $dearraynum1 & ' [0]'))

Still cant seem to reason why my first attempt wouldnt work.

Share this post


Link to post
Share on other sites
LarryDalooza

oh boy... Arrays are the accepted "variable variable" solution... Execute() or Eval() are hacks.

Lar


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites
weaponx

ok got it to work using

msgbox(0,"",Execute ('$encryptmethod' & $dearraynum1 & ' [0]'))

Still cant seem to reason why my first attempt wouldnt work.

I think you totally are missing the point of the array. Look at Larry's post again. Do not use Execute.

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  

×