Results 1 to 6 of 6

Thread: WriteINI and ReadINI

Threaded View

  1. #1

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    WriteINI and ReadINI

    A Class for reading and writing .INI files easily.
    I didn't make these.
    Instructions
    1. Put this code into your project.
    VB Code:
    1. Class INIReadWrite
    2.  
    3.     <DllImport("kernel32.dll", SetLastError:=True)> _
    4.     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
    5.     End Function
    6.  
    7.     <DllImport("kernel32.dll", SetLastError:=True)> _
    8.     Private Shared Function WritePrivateProfileString(ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Boolean
    9.     End Function
    10.  
    11.     Public Shared Function ReadINI(ByVal File As String, ByVal Section As String, ByVal Key As String) As String
    12.         Dim sb As New StringBuilder(500)
    13.         GetPrivateProfileString(Section, Key, "", sb, sb.Capacity, File)
    14.         Return sb.ToString
    15.     End Function
    16.  
    17.     Public Shared Sub WriteINI(ByVal File As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
    18.         WritePrivateProfileString(Section, Key, Value, File)
    19.     End Sub
    20.  
    21. End Class
    2. To read an .INI file
    Code:
    ReadINI(File, Section, Key)
    3. To write to an .INI file
    Code:
    WriteINI(File, Section, Key, Value)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width