Microsoft KB Archive/234212

= How To Insert a Line into a Text File Using Low-level File Functions =

Article ID: 234212

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft FoxPro 2.6 Standard Edition
 * Microsoft FoxPro 2.6a Standard Edition
 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual FoxPro 3.0b for Macintosh

-



This article was previously published under Q234212



SUMMARY
You can add lines of a text into a text file by creating a function using the code in the MORE INFORMATION section of this article.



MORE INFORMATION
Save the following code to a program (PRG) file. The calling convention is : Syntax:     InsertText(expC1, expN, expC2)

Parameters: expC1  The file into which text is inserted expN  The line number after which text is inserted expC2 The text to be inserted Returns:    Numeric *-- Function InsertLine
 * -- Description: Inserts text into a file at a specified line
 * -- Parameters:
 * -- lsFileName - The file into which text is inserted
 * -- liLineNum - The line number after which text is inserted
 * -- lsText    - The text to be inserted
 * -- Returns:
 * -- -1 = File could not be opened
 * -- -2 = Text insertion failed
 * -- -3 = File could not be closed
 * -- -3 = File could not be closed

Function InsertLine Parameter lsFileName, liLineNum, lsText liFile = Fopen(lsFileName, 12) If liFile = -1 Return -1 Endif

For i = 1 To liLineNum =Fgets(liFile) Endfor
 * -- Loop until we get to the desired line

liRc = Fputs(liFile, lsText) If liRc = 0 Return -2 Endif
 * -- Insert the text

llRc = Fclose(liFile) If !llRc Return -3 Else Return 1 Endif
 * -- Clean up

Additional query words: Add data low-level low level

Keywords: kbhowto kbxbase KB234212

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.