I'm writing an application and made two function to read/write ini files. It's based on the api's mentioned above. Use it if you like..
Remedy
Option Explicit
Private Declare Function WritePrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
Private 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
Public Sub WriteINI(FileName As String, Key As String, SubKey As String, Value As String)
Dim liRetval As Long
liRetval = WritePrivateProfileString(Key, SubKey, Value, FileName)
End Sub
Public Function ReadINI(FileName As String, Key As String, SubKey As String, Optional DefaultValue As String) As String
Dim lsRetval As String
Dim liLength As Long
Dim lsDefVal As String
If IsMissing(DefaultValue) Then
lsDefVal = "(not found)"
Else
lsDefVal = DefaultValue
End If
lsRetval = Space$(255)
liLength = GetPrivateProfileString(Key, SubKey, lsDefVal, lsRetval, 255, FileName)
lsRetval = Left(lsRetval, liLength)
ReadINI = lsRetval
End Function
Example:
Dim liTest As Integer
liTest = Val(ReadINI(App.Path & "\test.ini", "main", "testvalue", "10"

)