To Read and Write
#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
#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
#End Region
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
Form1_Load
CheckBox1.CheckState = INIRead(INIPath:="database/configuration/settings.ini", SectionName:="server", KeyName:="welcome", DefaultValue:="0" & ",")
TextBox1.Text = INIRead(INIPath:="database/configuration/settings.ini", SectionName:="server", KeyName:="welcome" & ",")
Button1
INIWrite("database/configuration/settings.ini", "server", "welcome", CheckBox1.CheckState & "," & TextBox1.Text)
So, I have Checkbox1 - Textbox1 and Button1
Checkbox is to enable or disable an option with 0 or 1 and it will add a ","
Textbox1 is to add a message after the ","
Button1 is to Save it, When it saves it it appears this:
Example:
[server]
welcome=1,Test
And its like that that works, so when i save it and close and open the program to load it to test it, it appears 1,Test cant be set to string or something ( error Continue or Cancel )
I need help that when i open the program it gets the result of the INI (Textbox1 last message that was saved)
and the Textbox to get it too so it will display it.
Any help?