Jump to content

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


Recommended Posts

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

Link to comment
Share on other sites

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

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.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...