mMyINI

Ok this function should make it easier for you to work with INI Files to read/write them not total bug free but it does it work.

Option Explicit
‘—————————————————————————————
‘ Module : mMyINI
‘ DateTime : 08/04/2010 12:28 AM
‘ Author : Kreshnik Hasanaj
‘ Mail : kresha7@hotmail.com
‘ Purpose : Read and Write INI Files
‘ Usage : At your own risk
‘ Requirements: None
‘ Distribution: You can freely use this code in your own
‘ applications, but you may not reproduce
‘ or publish this code on any web site,
‘ online service, or distribute as source
‘ on any media without express permission.
‘—————————————————————————————
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
Private 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
Declare Function PathFileExists _
Lib “shlwapi.dll” _
Alias “PathFileExistsA” (ByVal pszPath As String) As Long
Const INIExt = “.ini”

Public Function ReadINI(rAppName As String, _
rKeyName As String, _
INIFileName As String) As String
Dim RetValue&
Dim sBuffer$
sBuffer = Space$(255)

If PathFileExists(App.Path & “\” & INIFileName & “.ini”) <> 0 Then
RetValue = GetPrivateProfileString(rAppName, rKeyName, “”, sBuffer, 255, App.Path & “\” & INIFileName & INIExt)

If Not (RetValue) = 0 Then
sBuffer = Left$(sBuffer, RetValue)
ReadINI = sBuffer
End If

Else
Exit Function
End If

End Function

Public Sub WriteINI(AppName As String, _
KeyName As String, _
StrVal As String, _
INIFileName As String)

If AppName = vbNullString Or KeyName = vbNullString Or StrVal = vbNullString Or INIFileName = vbNullString Then
Exit Sub
End If

WritePrivateProfileString AppName, KeyName, StrVal, App.Path & “\” & INIFileName & INIExt
End Sub

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s