A Class for reading and writing .INI files easily.
I didn't make these.
Instructions
1. Put this code into your project.
2. To read an .INI fileVB Code:
Class INIReadWrite <DllImport("kernel32.dll", SetLastError:=True)> _ Private Shared Function GetPrivateProfileString(ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As Integer End Function <DllImport("kernel32.dll", SetLastError:=True)> _ Private Shared Function WritePrivateProfileString(ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Boolean End Function Public Shared Function ReadINI(ByVal File As String, ByVal Section As String, ByVal Key As String) As String Dim sb As New StringBuilder(500) GetPrivateProfileString(Section, Key, "", sb, sb.Capacity, File) Return sb.ToString End Function Public Shared Sub WriteINI(ByVal File As String, ByVal Section As String, ByVal Key As String, ByVal Value As String) WritePrivateProfileString(Section, Key, Value, File) End Sub End Class
3. To write to an .INI fileCode:ReadINI(File, Section, Key)
Code:WriteINI(File, Section, Key, Value)


)
Reply With Quote