Advertisement
Guest User

Untitled

a guest
Oct 24th, 2011
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. Public Class IniFile
  2.  
  3. Private Declare Ansi Function GetPrivateProfileString Lib "kernel32.dll" Alias "GetPrivateProfileStringA" _
  4. (ByVal lpApplicationName As String, _
  5. ByVal lpKeyName As String, _
  6. ByVal lpDefault As String, _
  7. ByVal lpReturnedString As System.Text.StringBuilder, _
  8. ByVal nSize As Integer, _
  9. ByVal lpFileName As String) _
  10. As Integer
  11.  
  12. Private Declare Ansi Function WritePrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
  13. (ByVal lpApplicationName As String, _
  14. ByVal lpKeyName As String, _
  15. ByVal lpString As String, _
  16. ByVal lpFileName As String) _
  17. As Integer
  18.  
  19. Public Property Path As String
  20.  
  21. ''' <summary>
  22. ''' IniFile Constructor
  23. ''' </summary>
  24. ''' <param name="IniPath">The path to the INI file.</param>
  25. Public Sub New(ByVal IniPath As String)
  26. _Path = IniPath
  27. End Sub
  28.  
  29. ''' <summary>
  30. ''' Read value from INI file
  31. ''' </summary>
  32. ''' <param name="section">The section of the file to look in</param>
  33. ''' <param name="key">The key in the section to look for</param>
  34. Public Function ReadValue(ByVal section As String, ByVal key As String) As String
  35. Dim sb As New System.Text.StringBuilder(255)
  36. Dim i = GetPrivateProfileString(section, key, "", sb, 255, Path)
  37. Return sb.ToString()
  38. End Function
  39.  
  40. ''' <summary>
  41. ''' Write value to INI file
  42. ''' </summary>
  43. ''' <param name="section">The section of the file to write in</param>
  44. ''' <param name="key">The key in the section to write</param>
  45. ''' <param name="value">The value to write for the key</param>
  46. Public Sub WriteValue(ByVal section As String, ByVal key As String, ByVal value As String)
  47. WritePrivateProfileString(section, key, value, Path)
  48. End Sub
  49.  
  50. End Class
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement