This is a code in Visual Basic 9.It provides functions so you can read/write ini files in a simple way.
Create a new Module file and delete everything inside.Then put this in:
Have fun
Create a new Module file and delete everything inside.Then put this in:
Code:
Module INIReader
#Region "API Calls"
Private Declare Unicode Function WritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileStringW" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpString As String, _
ByVal lpFileName As String) As Int32
Private Declare Unicode Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringW" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedString As String, ByVal nSize As Int32, _
ByVal lpFileName As String) As Int32
#End Region
Public Overloads Function INIRead(ByVal INIPath As String, _
ByVal SectionName As String, ByVal KeyName As String, _
ByVal DefaultValue As String) As String
Dim n As Int32
Dim sData As String
sData = Space$(1024)
n = GetPrivateProfileString(SectionName, KeyName, DefaultValue, _
sData, sData.Length, INIPath)
If n > 0 Then
INIRead = sData.Substring(0, n)
Else
INIRead = ""
End If
End Function
Public Sub INIWrite(ByVal INIPath As String, ByVal SectionName As String, _
ByVal KeyName As String, ByVal TheValue As String)
Call WritePrivateProfileString(SectionName, KeyName, TheValue, INIPath)
End Sub
#Region "INIRead Overloads"
Public Overloads Function INIRead(ByVal INIPath As String, _
ByVal SectionName As String, ByVal KeyName As String) As String
Return INIRead(INIPath, SectionName, KeyName, "")
End Function
Public Overloads Function INIRead(ByVal INIPath As String, _
ByVal SectionName As String) As String
Return INIRead(INIPath, SectionName, Nothing, "")
End Function
Public Overloads Function INIRead(ByVal INIPath As String) As String
Return INIRead(INIPath, Nothing, Nothing, "")
End Function
Public Overloads Sub INIDelete(ByVal INIPath As String, ByVal SectionName As String, _
ByVal KeyName As String)
Call WritePrivateProfileString(SectionName, KeyName, Nothing, INIPath)
End Sub
Public Overloads Sub INIDelete(ByVal INIPath As String, ByVal SectionName As String)
Call WritePrivateProfileString(SectionName, Nothing, Nothing, INIPath)
End Sub
#End Region
End Module
Have fun