The Kupex INI Tools 1.0 ActiveX control allows you to easily read and edit INI files.
INI files (files ending with .ini) were used by a lot of programs in Windows 3.1 (with some using the registry), but since Windows 95 has been available, many more programs use the registry to save their settings instead. Your program should use VB6's GetSetting, SaveSetting and DeleteSetting Statements to store settings, but you may need to read an INI file, system.ini for example. If you need to use INI files, you should use this control. There are also API commands to edit INI files. INI files are in this format:
[section1]
key1=text
key2=text
[section2]
key1=text
key2=text
You can't have two sections with the same name, but you can have keys with the same name but only if they are in different sections.
This control was available from the Kupex website that does not seem to exist anymore. You can download the control from my website instead.
The examples on this page will use INI code in a made up file called C:\Cars.ini, which looks like this:
[Fiesta]
Make=Ford
EngineSize=1.3
Colour=Green
Transmission=Manual
Doors=5
[Granada]
Make=Ford
EngineSize=2.9
Colour=Silver
Transmission=Automatic
Doors=5
Shows the about box:

About Box
SectionName As String, KeyName As String, FileName As String
Use this method to get information by specifying the section, key and filename.
|
MsgBox INITool1.GetFromINI("Fiesta", "Colour", "C:\Cars.ini")
'Returns "Green" |
SectionName As String, FileName As String
Returns the first line of a section. This seems pointless to me.
|
MsgBox INITool1.GetINISection("Fiesta", "C:\Cars.ini")
'Returns "Make=Ford" |
Text As String, SectionName As String, KeyName As String, FileName As String
Edits a key or creates a section and key if they don't exist.
|
INITool1.WriteToINI "Red", "Fiesta", "Colour",
"C:\Cars.ini" 'Edits the 'Colour' key in
the 'Fiesta' section |
Text As String, KeyName As String, FileName As String
Creates text that looks like this in the file:
[Section]
Key
Existing sections are replaced and you can't edit the key. Again, this seems pointless and you could also lose a whole section of data. Also, Text should be KeyName and KeyName should be SectionName.
|
INITool1.WriteToINISection "Colour", "Fiesta", "C:\Cars.ini" |
| From: | Martyn | |
| Date: | Thursday, September 29, 2005 at 09:31:37 | |
| Comments: | why have another control when you can use API?
easy as pie! |
| From: | Bill |
| Date: | Wednesday, June 30, 2004 at 20:58:54 |
| Comments: | Thank you! This is what I needed! |
| From: | Reuben |
| Date: | Thursday, May 13, 2004 at 14:38:36 |
| Comments: | What a beautiful thing! I am an amature VBr so when I entered your examples directly, they did not work. I got this example from
www.winnetmag.com/WindowsScripting/
Article/ArticleID/4729/4729.html - Set FileObject = CreateObject("INITools.INITool") MyINIEntry = FileObject.GetFromINI("Header", "Key", File). It seems to work quite well. Thank you for helping out. Reuben |
| From: | Andrew |
| Date: | Thursday, April 22, 2004 at 13:19:36 |
| Comments: | Thankyou! Been searching for 2 days for a simple, easy to use ActiveX to write INI's |
| From: | Jonno |
| Date: | Thursday, February 5, 2004 at 18:15:59 |
| Comments: | Brilliant, I'm amazed it wasn't in te default VB tools! |
| From: | Dave |
| Date: | Saturday, May 31, 2003 at 21:57:56 |
| Comments: | Fantastic! thank you, precisely what I was looking for!!!!! |