How do I write to .ini files?


Use the Windows API function WritePrivateProfileString, declared as follows

Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

If you want to write the following to a file called "test.ini"
[First]
Second=Third

Use this call:
Result = WritePrivateProfileString ("First", "Second", "Third", "test.ini")

If you want to read from a .ini file, use the opposite function GetPrivateProfileString, declared as follows

Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long


Mail to Daniel Wiman <daniel@wimania.com>
Online since June 1996, updated 971103
<- The VB home
<- Daniels homepage