Jump to content
Sign in to follow this  

More dynamic variables, need help

Recommended Posts


Hello All,


Dim $INIfile = @ScriptDir & "\dnsedit.ini"

Dim $IP, $i, IPcount

$IPcount = IniRead ($INIfile, "IPADDRESS", "IPcount", "" )

For $i = 1 To $IPcount

$IP$i = IniRead ($INIfile, "IPADDRESS", "IP" & $i, "" )

MsgBox(4096, "", $IP$i)


What I'm trying to do here is read a count variable from an ini file, and create dynamic variables with results as such:

$IP1 = IniRead ($INIfile, "IPADDRESS", "IP1", "" )

$IP2 = IniRead ($INIfile, "IPADDRESS", "IP2", "" )


I have tried some of the possible solutions with Eval and Assign that I found in other posts, and can't seem to find any joy. It seems to me that this shouldn't be that hard to do. I have used loops as above in PERL before.

Any help is appreciated :P


Share this post

Link to post
Share on other sites


quite a few things are covered there. if those don't work, you might want to explain what you're trying to do a little better.

I have tried that post but was unable to get the solutions to work;

>What I'm trying to do here is read a count variable from an ini file, and create dynamic variables with >results as such:

>$IP1 = IniRead ($INIfile, "IPADDRESS", "IP1", "" )

>$IP2 = IniRead ($INIfile, "IPADDRESS", "IP2", "" )


I am trying to dynamically create static variables based on a loop count and assign them a value contained in an ini file, also based on the loop count.I know I can do it with case or if statements but that seems so inefficient compared to using a loop.

I'll equate each statement below to what I'm looking for it to evaluate to:

For $i = 1 To $IPcount = For $i = 1 to 2

$IP$i = IniRead ($INIfile, "IPADDRESS", "IP" & $i, "" ) = $IP1 = IniRead ($INIfile, "IPADDRESS", "IP1", "" )

MsgBox(4096, "", $IP1)


$IP$i = IniRead ($INIfile, "IPADDRESS", "IP" & $i, "" ) = $IP2 = IniRead ($INIfile, "IPADDRESS", "IP2", "" )

MsgBox(4096, "", $IP2)

Is this a little clearer?


Share this post

Link to post
Share on other sites

you should be able to just read the ini with the IP and current number just like you posted:

IniRead ($INIfile, "IPADDRESS", "IP" & $i, "" )

as for the dynamic variables, i don't see why you'd need them unless you're using them all later somehow... can't you use an array or a temp variable and handle them like that? if the code you posted is what you're trying to achieve, you can just do:

For $i = 1 To $IPcount
$temp = IniRead ($INIfile, "IPADDRESS", "IP" & $i, "" )
MsgBox(4096, "", $temp)

or even just eliminate the temp variable

For $i = 1 To $IPcount
MsgBox(4096, "", IniRead ($INIfile, "IPADDRESS", "IP" & $i, "" ))

although i'm guessing the real purpose is much more complicated...

Share this post

Link to post
Share on other sites

array seems best IMO.

I can place each pair that does not have a set number and can be added to in its own section in the ini and then build an array out of the section, and I know that will work.

I was hoping to keep some of these items in the sections they are in for logic reasons, and that would work if I could dynamically assign a variable and value based on the count. Although I guess I could build an array from the for loop results since $temp[$i] = IniRead ($INIfile, "IPADDRESS", "IP" & $i, "" ) should work. Edit: it does work as long as the $temp variable is Dim'd as a array using the count from the ini file. The [0] element can also be set to the count and passed on later in the script that way.

Just reading the line from the ini file won't work as I will be using the variable later on, and the count to set the number and position of input controls. So you were right about the more complicated purpose w0uter.

Basically what I am doing is building a GUI app to add populate and zone files from a template and place an entry in the primary.conf file for new domain setup in BIND DNS on Win Server. Since there is no way of knowing before hand how many entries for several sections will be part of th configuration since it will be used on different servers, I will allow as many entries into the ini file as needed. In the instance of the IP addresses , they will all be read from the ini and populated into a combo box.

There is a section for required CNAME entries that is also dynamic and has to read a values like

CN1name = name

CN1value = value

for as many entries as the particular server dns setup requires, and write input controls for each set, dynamically calculating the position of each in the GUI.

So I know there are other ways than a dynamic variable assignment to accomplish it, but I was hoping to find a way to make the variable assignment work since it is also a technique I've used in PERL for years.

I will post the finished script if anyone is interested into the Scripts and Scraps forum.

Any and all input is appreciated.


Edited by billmez

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