WD: Deleting an Entry Line from an .INI Settings File
ID: Q120028
|
The information in this article applies to:
-
Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
-
Microsoft Word for Windows NT, version 6.0
-
Microsoft Word for Windows 95, versions 7.0, 7.0a
SUMMARY
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.
Word for Windows version 6.x
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
Windows 95 or Windows NT
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
MORE INFORMATION
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
Version : WINDOWS:6.0,6.0a,6.0c,7.0,7.0a; winnt:6.0
Platform : WINDOWS winnt
Issue type :