Jump to content
Sign in to follow this  
Smiley357

Variable question?

Recommended Posts

Smiley357

Is there a way to have a variable inside a variable name?

Example:

$count = 1

$var$count = 500 ;this would mean the same thing as $var1=500

Share this post


Link to post
Share on other sites
TerarinKerowyn

No you cannot do what you are trying to do but you can create a array and use one variable in another

$count = 1
$var[$count] = 500

so $var[0] = 1 and $var[1] = 500 if you had $count = 2 the thing would fail because you never included $var[1] then unless you enum it.


Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah

Share this post


Link to post
Share on other sites
PsaltyDS

No you cannot do what you are trying to do but you can create a array and use one variable in another

$count = 1
$var[$count] = 500

so $var[0] = 1 and $var[1] = 500 if you had $count = 2 the thing would fail because you never included $var[1] then unless you enum it.

Well, it can be done:
$count = 1
Assign("var" & $count, 500)
ConsoleWrite("Debug: $var1 = " & Eval("var1") & @LF)

But, you are right that in the vast majority of cases, arrays are much better.

Assign/Eval are, almost always, evil.

:P


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
Tipulatoid

Well, I need to read from ini-file the several number of sections into arrays. Do the following:

#include <Array.au3>
$IniGeneral = IniReadSection("champ.ini", "General")
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
 EndIf
 
For $g = 1 to $IniGeneral[_ArraySearch ($IniGeneral, "GroupQuan")][1]
    Assign ("IniGroup" & $g, IniReadSection ("champ.ini", "Group" & $g))
Next; that works fine; I get, for example, 2 arrays named $IniGroup1, $IniGroup2

; now I want to see them
For $g = 1 to $IniGeneral[_ArraySearch ($IniGeneral, "GroupQuan")][1]
    _ArrayDisplay (Eval("IniGroup" & "g"))
Next; that doesn't work

example of champ.ini

[General]
ShowLogo=1
TopicNum=1000
PeriodsQuan=20
EstablishConn=0
DeleteConn=1
ConnName=
MultiGame=0
MultiGamePath=
GroupQuan=2
GroupName=Group
[Group1]
GroupEmail=1lalala@unknown.ru
GroupEmailPass=1qwertyuiop
GroupEmailLogin=1tototo
GroupEmailPOP=1poppopop
GroupEmailSMTP=1smtpsmtp
[Group2]
GroupEmail=2lalala@unknown.ru
GroupEmailPass=2qwertyuiop
GroupEmailLogin=2tototo
GroupEmailPOP=2poppopop
GroupEmailSMTP=2smtpsmtp

Can you help with this? (I am newbie) And sorry for bad English

Edited by Tipulatoid

Share this post


Link to post
Share on other sites
Tipulatoid

Please never mind. I solved that

For $g = 1 to $IniGeneral[_ArraySearch ($IniGeneral, "GroupQuan")][1]
    $current = Eval ("IniGroup" & $g)
    _ArrayDisplay ($current)
Next

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.