Results 1 to 2 of 2

Thread: VB6 - How to delete a section from an INI file

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    VB6 - How to delete a section from an INI file

    I suddenly remembered the code bank when I did a post in the General VB Forum. Might be useful to some. Anyways, to delete a section from an INI file, you use the WritePrivateProfileString API. A typical code example would look something like this:

    VB Code:
    1. 'this goes into the declaration section of the
    2. 'code
    3. Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    4.  
    5. Public sub DeleteKey
    6. Dim sSection As String
    7. Dim sKey As String
    8. Dim sFileName as String
    9.  
    10. sSection = "Section1"
    11. sKey = "Key1"
    12. sFileName="C:\MyINIFILE.INI"
    13.  
    14. 'if the key exists, delete it from the section
    15.    If len(trim(sKey)) <>0 Then
    16.       WritePrivateProfilestring sSection, sKey, _
    17.          vbNullString, sFileName
    18.    Else
    19.       'no key specified, then delete section
    20.       WritePrivateProfileString _
    21.          sSection,sKey,vbNullString,sFileName
    22.    End If
    23. End Sub

  2. #2
    Junior Member
    Join Date
    Jan 2008
    Posts
    26

    Re: VB6 - How to delete a section from an INI file

    hello, where do I put this part
    Code:
    #
    Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    #
    ?

    Thanks

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