943,152 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1868
  • VB.NET RSS
Mar 12th, 2010
0

Checkbox status read INI

Expand Post »
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:

VB.NET Syntax (Toggle Plain Text)
  1. #Region "API Calls"
  2.  
  3. Private Declare Unicode Function WritePrivateProfileString Lib "kernel32" _
  4. Alias "WritePrivateProfileStringW" (ByVal lpApplicationName As String, _
  5. ByVal lpKeyName As String, ByVal lpString As String, _
  6. ByVal lpFileName As String) As Int32
  7.  
  8. Private Declare Unicode Function GetPrivateProfileString Lib "kernel32" _
  9. Alias "GetPrivateProfileStringW" (ByVal lpApplicationName As String, _
  10. ByVal lpKeyName As String, ByVal lpDefault As String, _
  11. ByVal lpReturnedString As String, ByVal nSize As Int32, _
  12. ByVal lpFileName As String) As Int32
  13. #End Region
  14.  
  15. Public Overloads Function INIRead(ByVal INIPath As String, _
  16. ByVal SectionName As String, ByVal KeyName As String, _
  17. ByVal DefaultValue As String) As String
  18. Dim n As Int32
  19. Dim sData As String
  20. sData = Space$(1024)
  21. n = GetPrivateProfileString(SectionName, KeyName, DefaultValue, _
  22. sData, sData.Length, INIPath)
  23. If n > 0 Then
  24. INIRead = sData.Substring(0, n)
  25. Else
  26. INIRead = ""
  27. End If
  28. End Function
  29.  
  30. #Region "INIRead Overloads"
  31. Public Overloads Function INIRead(ByVal INIPath As String, _
  32. ByVal SectionName As String, ByVal KeyName As String) As String
  33. Return INIRead(INIPath, SectionName, KeyName, "")
  34. End Function
  35.  
  36. Public Overloads Function INIRead(ByVal INIPath As String, _
  37. ByVal SectionName As String) As String
  38. Return INIRead(INIPath, SectionName, Nothing, "")
  39. End Function
  40.  
  41. Public Overloads Function INIRead(ByVal INIPath As String) As String
  42. Return INIRead(INIPath, Nothing, Nothing, "")
  43. End Function
  44. #End Region
  45.  
  46. Public Sub INIWrite(ByVal INIPath As String, ByVal SectionName As String, _
  47. ByVal KeyName As String, ByVal TheValue As String)
  48. Call WritePrivateProfileString(SectionName, KeyName, TheValue, INIPath)
  49.  
  50. End Sub

thats the necessary to read and write ini and it works.

To get current root

VB.NET Syntax (Toggle Plain Text)
  1. Public Function App_Path() As String
  2. Return System.AppDomain.CurrentDomain.BaseDirectory()


i have this for Form1_Load

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. CheckBox1.CheckState = INIRead(INIPath:=App_Path() & "database/configuration/settings.ini", SectionName:="config", KeyName:="test")
  3. End Sub

Button1

VB.NET Syntax (Toggle Plain Text)
  1. 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
Last edited by xfrolox; Mar 12th, 2010 at 6:31 pm.
Similar Threads
Reputation Points: 19
Solved Threads: 0
Junior Poster in Training
xfrolox is offline Offline
91 posts
since Oct 2009
Mar 12th, 2010
0
Re: Checkbox status read INI
Well LOL i solved it ...

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3. CheckBox1.CheckState = INIRead(INIPath:="database/configuration/settings.ini", SectionName:="config", KeyName:="test", DefaultValue:="0")

Now i have the last problem that i will post it in another thread because is not full similar to this one
Last edited by xfrolox; Mar 12th, 2010 at 10:57 pm.
Reputation Points: 19
Solved Threads: 0
Junior Poster in Training
xfrolox is offline Offline
91 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Listview size
Next Thread in VB.NET Forum Timeline: HELP Textbox read INI





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC