Results 1 to 3 of 3

Thread: How do i read and write to a ini files?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    219
    How do i read and write to a ini files?

  2. #2
    New Member
    Join Date
    May 1999
    Posts
    6

    The answer


    Declare these two APIs in a module:

    Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String,
    ByVal nSize As Long, ByVal lpFileName As String) As Long

    Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As String, ByVal lpFileName As String) As Long


    To write to an ini file:

    Dim Res As Long

    Res = WritePrivateProfileString("Section", "Key Name", "Key Value", "C:\MyINI.ini")

    "Res" will be zero if an error occurs.


    To read:

    Dim strString As String
    Dim strStringLen As Integer
    strString = Space(256)
    strStringLen = 255

    GetPrivateProfileString "Section", "Key Name", "", strString, strStringLen, "C:\MyINI.ini"

    If "Section" or "Key Name" is not found then strString will be "" else strString will contain the value of "Key Name"

    Hope this helps.

    Regards:
    VBJ






  3. #3
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    593

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