WD: Deleting an Entry Line from an .INI Settings File

Last reviewed: August 5, 1997
Article 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 6.0a WritePrivateProfileString Delete Key
word6 Entry Private Settings File DeleteProfileStr 7.0 word95 word7 ntword
wordnt
Keywords : kbprg kbusage
Version : 6.0 6.0a 6.0c 7.0 7.0a
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 5, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.