Jump to content
Macro Express Forums

Ini File Format And Example Questions


daviejr
 Share

Recommended Posts

I have been looking for examples of how one uses INI files to store and retrieve information ...specifically,

(1) how does one create an INI file, and

(2) what format does one use in it (keys, data?) so that it can be read properly?

 

The ME help files are sparse on the subject.

Any code snippets and INI examples would be appreciated.

Link to comment
Share on other sites

Daviejr:

 

An .INI or initialization file (pronounced either 'eye-en-eye' or 'inny') is generally used to store configuration information for Windows or a program that runs on Windows. Once widely used, many programs now use the Windows Registry instead of an .INI file. It is likely that you will find many .INI files in the Windows folder on your computer.

 

An .INI file can be used to read information from an existing .INI file but it is also a convenient way to save and retrieve macro variables. The "Variable Modify String: Save %T1% to INI File" command saves a macro variable to an .INI file and the "Variable Set String %T2% from INI File" reads information from an .INI file and places it into a variable. To understand how to use these commands, you need to understand the structure of an .INI file.

 

An .INI file contains one or more 'Sections'. Each section is given a name and is stored within square brackets, '[' and ']'. Under each section are 'keys' and 'values' separated by an equals sign, ('='). An .INI file may contain many sections but each section name must be unique. Likewise, a section in an .INI file can contain many keys but each key name within a section must be unique. However, keys with the same name can be placed in different sections in an .INI file.

 

The .INI file syntax looks like this:

[sectionName1]
param1=string
param2=string
[sectionName2]
param1=string
param2=string

Here is an example from an actual SYSTEM.INI file found in the Windows folder of a computer:

[drivers]
wave=mmdrv.dll
timer=timer.drv
[386enh]
woafont=dosapp.FON
EGA80WOA.FON=EGA80WOA.FON
EGA40WOA.FON=EGA40WOA.FON
CGA80WOA.FON=CGA80WOA.FON
CGA40WOA.FON=CGA40WOA.FON

This example contains two Sections, "drivers" and "386enh". The "drivers" section contains two Keys, "wave" and "timer". The Key "wave" has a Value of "mmdrv.dll".

 

The "Variable Modify String: Save %T1% to INI File" and "Variable Set String T2% from INI File" commands require that you specify a filename, a Section Name, a Key Name and a string variable (T1 through T99). When you use the "Variable Modify String: Save %T1% to INI File" macro command, the content of the variable is written as the value of the specified Key. When you use the "Variable Set String %T2% from INI File" macro command, the value of the specified Key is read and placed into the specified variable.

Link to comment
Share on other sites

  • 2 weeks later...

You've got it right daviejr. Avoiding the Registry is a very good reason to use INI files. The only downside is working with integers or decimals. They are stored as strings in the file, which means an extra step to convert them when they are read back. However, it is not much of a downside at all!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...