INI files

sampoo

Active member
Joined
Jun 12, 2004
Messages
25
Location
Belgium
Programming Experience
3-5
Hi,
I'd like to write code for my software that is able to read a configuration (for multiple languages, so it will be language files) from an INI file. Lot's of application do that, and this way, it is very easy to translate your app in many different languages. An example:

[Executables]
PVA Executable=
vStrip Executable=C:\Program Files\DVD2SVCD\vStrip\vStrip.exe
DVD2AVI Executable=C:\Program Files\DVD2SVCD\DVD2AVI\DVD2AVI.exe
BeSweet Executable=C:\Program Files\DVD2SVCD\BeSweet\BeSweet.exe
MADPlay Executable=C:\Program Files\DVD2SVCD\MADPlay\madplay.exe
MPEG51 Executable=C:\Program Files\DVD2SVCD\MPEG5.1\pub_enc.exe
CCE Executable=
QuEnc Executable=
VFAPI Executable=C:\Program Files\DVD2SVCD\VFAPI\Reader\VFAPIConv-EN.exe

and so on. This fragment came from an INI file of DVD2SVCD (an app to convert DVDs in many different formats). This is done too for languages.

A fictive example: (for a Dutch language file)
[Menus]
LoadFile="Laad Bestand"
Exit="Afsluiten"

[Buttons]
OK="OK"
Cancel="Annuleren"

[...]
...




How can I do this in Visual Basic? Should I write a parser or something similar, and if so, how should I start with it?


Thanks in advance
 
Here's a INIReader and Writer I found a while ago hope it helps
Add it to your project then refer to it, then it will read and modify any Ini you point it to
 

Attachments

  • IniReader.zip
    4.3 KB · Views: 208
The .Net framework already has built in configuration abilities. The System.Configuration namespace would be the namespace to look at. It uses XML as opposed to INI type files; XML has pretty much replaced INI and is the suggested format for future projects.
 
Remember that the application config files can not be edited at run time, which means that the app running can not modify it's own .config file. Have a look at the configuration application block, or do a search on xmlconfig files, there are several libraries out there that imitate the ini files but use xml instead.
 
That's a good point Mykre is making.

I was assuming the files would be static and the app would only need to select the appropriate one for which ever language was needed.

If this is the case, The best thing to do is to create satellite assemblies (compiled dlls). Here's a good tutorial on the MSDN website: Developing World-Ready Applications

Here's an excerpt:
In the satellite assembly deployment model, you create an application with a default assembly (the main assembly) and several satellite assemblies. You should package the resources for the default or neutral assembly with the main assembly and create a separate satellite assembly for each language that your application supports. Because the satellite assemblies are not part of the main assembly, you can easily replace or update resources corresponding to a specific culture without replacing the application's main assembly.
 
Back
Top