Well I'm trying to make a tool for a game for learning purposes and i can't figure it out, I have Checkbox1 and a button The button saves the ini with the checkbox1.CheckState correctly and when i open it the Checkbox1.CheckState is checked so it works, but when i Delete the line from the ini and i open the program it gives an error that says continue or cancel and i want to disappear that error i have working on that error for like 4 hours and still.
i got this:
#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
thats the necessary to read and write ini and it works.
To get current root
Public Function App_Path() As String
Return System.AppDomain.CurrentDomain.BaseDirectory()
i have this for Form1_Load
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CheckBox1.CheckState = INIRead(INIPath:=App_Path() & "database/configuration/settings.ini", SectionName:="config", KeyName:="test")
End Sub
Button1
INIWrite(App_Path() & "database/configuration/settings.ini", "config", "test", CheckBox1.CheckState)
Any Help?
I could have enough like if INIRead and the line is not there then the checkbox1.checkstate is unchecked