Sign in to follow this  
Followers 0
Zomp

reading an ini files and assigning variables automatically

6 posts in this topic

Surely this topic has already been discussed but, I'm sorrry, I was not able to find it.

Suppose I have a .ini file with a section like the following:

CheckDate=0
FlushMemory=1
LogFile=log.txt
InsertMedia=0

and depending on it I need to assign variables $CheckDate, $FlushMemory, $LogFile, $InsertMedia.

How can I do?

Many thanks for your help.

Share this post


Link to post
Share on other sites



Surely this topic has already been discussed but, I'm sorrry, I was not able to find it.

Suppose I have a .ini file with a section like the following:

CheckDate=0
FlushMemory=1
LogFile=log.txt
InsertMedia=0

and depending on it I need to assign variables $CheckDate, $FlushMemory, $LogFile, $InsertMedia.

How can I do?

Many thanks for your help.

Are you saying that you want to read the keys in that section and dynamically create variables based off what's found within, or you want to just do something like:

$CheckDate = IniRead ("C:\Path\To\File.ini", "Section", "CheckDate", "DefaultValueIfLookupFails")

If it's the former, I don't think you can dynamically name variables like that, if it's the latter, look up IniRead in the Helpfile.

Share this post


Link to post
Share on other sites

It's just IniRead. For example if you have an ini file:

[Vars]
Num=1

by using:

$Num = IniRead("path", "Vars", "Num", "")

you get 1.

Share this post


Link to post
Share on other sites

If it's the former, I don't think you can dynamically name variables like that, if it's the latter, look up IniRead in the Helpfile.

The former. Anyhow, you have given me the information I needed. Thanks. :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The former. Anyhow, you have given me the information I needed. Thanks. :)

No problem, why do you need/want to declare your variables on the fly?

Edited by exodius

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

No problem, why do you need/want to declare your variables on the fly?

In my mind it seems just a question of speed and length of coding.

A loop similar to "for each ... next" is simpler that a set of single assigments, mostly if the variables are dozens and dozens.

Edited by Zomp

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