Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove section from an .ini file??

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
GB
ini files seem to be made up of sections, each with a heading [like so]. What I want is a procedure that you can passa heading into that will then delete the enire section.

I'm sure someone already has one, so I'd thought I'd ask before I start doing one myself. Bit lazy, but nevermind.

Thanks

elziko
 
ini files are usually manipulated using Win API calls. I believe the API call you should look up is WritePrivateProfileString. This can be a little confusing but this is the best info I can provide.

Otherwise, (if you want to avoid API's), you could work with the FileSystemObject and just treat the ini file as a normal text file looking for the line you wish to delete.

good luck and I hope this helps. Sorry that I couldn't be a little more detailed but i don't have the code on hand.

bye
Jim
 
Put the following code in a module:

Option Explicit

Public 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


Public Function Write_Ini_String(ByVal sIniPath As String, ByVal sSection As String, ByVal sEntry As String, ByVal sValue As String)

Dim lRetVal As Long

If sEntry = "" Then ' clear the section
lRetVal = WritePrivateProfileString(sSection, vbNullString, vbNullString, sIniPath)
Else
lRetVal = WritePrivateProfileString(sSection, sEntry, sValue, sIniPath)
End If

End Function



And then to write to a section in the ini file, use the line:

Call Write_Ini_String("full_path_and_name_of_ini_file", "Section_Title", "entry", "value")

And to clear a section from the ini file, use the line:

Call Write_Ini_String("full_path_and_name_of_ini_file", "Section_Title", "", "")
Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top