WD: Deleting an Entry Line from an .INI Settings File |
Q120028
Microsoft WordBasic includes two statements to read and write information
to a private settings file often referred to as an .INI file:
SetPrivateProfileString and GetPrivateProfileString. Neither of these
commands, however, allow you to remove an entire entry line from a private
settings file or .INI file.
The following WordBasic macro demonstrates the use of the Windows
WritePrivateProfileString function in order to remove an entry from an .INI
file.
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN
RISK. Microsoft provides this macro code "as is" without warranty of any
kind, either express or implied, including but not limited to the implied
warranties of merchantability and/or fitness for a particular purpose.
Declare Function DeleteProfileStr Lib "kernel"(Section$, Key$, \
Value As Long, FName$) As Integer Alias "WritePrivateProfileString"
Sub MAIN
FName$ = "C:\WINWORD\TEXT.INI"
Section$ = "Section"
Key$ = "Entry1"
x = DeleteProfileStr(Section$, Key$, 0, FName$)
End Sub
Declare Function WritePrivateProfileString Lib "kernel32" Alias \
"WritePrivateProfileStringA"(Section$, Key$, Value As Long, FName$) \
As Long
Sub MAIN
FName$ = "C:\TEST.INI"
Section$ = "Section"
Key$ = "Entry1"
x = WritePrivateProfileString(Section$, Key$, 0, FName$)
End Sub
The above WordBasic macro deletes the Entry1= line from the Text.ini file in the C:\Winword directory. Before running the macro, the contents of the Text.ini file appear as follows:
[Section]
Entry1="Text for entry 1"
Entry2="More text"
After running the above macro the contents of the Text.ini file appear as
follows:
[Section]
Entry2="More text"
For more information about the Windows WritePrivateProfileString function,
query on the following words in the Microsoft Knowledge Base:
writeprivateprofilestring and windows and calls
Additional query words: 6.0 WritePrivateProfileString Delete Key word6 Entry Private Settings File DeleteProfileStr 7.0 word95 word7 ntword wordnt
Keywords : kbprg kbusage kbofficeprog
Issue type :
Technology :
|
Last Reviewed: March 28, 2000 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |