Acorbally:
Here is a relatively simple code snippet that will work in all version of foxpro and on dos.
It includes some testing code which you'd need to strip out.
Unfortunately, in newer versions of FoxPro it would be much simpler.
I'm sure it will require some more error trapping, esp.
regarding the creation of the temporary files.
Also, if you want more granular control of field
positioning - etc., that will require much more code and/or
a different approach.
Hope it helps.
Darrell
[tt]
#DEFINE CRLF CHR(13)+CHR(10)
#DEFINE LineNumPadding SPACE(3)
PRIVATE cOldCentury, cOldSafety, cTempCurs, cTempTbl
PRIVATE cTempFile, nFlHndl, bFail
PRIVATE cNextLine, cText, cLineNum, nLineNumPad
cOldCentury = SET("century"

cOldSafety = SET("safety"

SET CENTURY ON
SET SAFETY OFF
cTempCurs = "_"+SUBSTR(SYS(2015), 4, 10)
* Loop until temp name changes.
* Especially important on fast machines
DO WHILE "_"+SUBSTR(SYS(2015), 4, 10) == cTempCurs
ENDDO
cTempTbl = "_"+SUBSTR(SYS(2015), 4, 10)
cTempFile = SYS(2023)+"\"+SUBSTR(SYS(2015), 4, 10)+".txt"
CREATE TABLE (SYS(2023)+"\"+cTempTbl) (MemFld M)
* This is where your source table/cursor should be selected
* This is just an example on my system
SELECT accountno,invoicenum,compname,phone ;
FROM c:\dev\clients\abs\testtbls\accounts ;
WHERE datesold > CTOD("11/30/2003"

;
ORDER BY invoicenum DESC INTO CURSOR (cTempCurs)
nLineNumPad = LEN(ALLT(STR(RECCOUNT()))) && Line number padding to be used later
* Output table lines to a text file
LIST TO FILE (cTempFile) NOCONSOLE
nFlHndl = FOPEN(cTempFile) && Low level open of output file
bFail = .F. && Set conditional on open failure
IF nFlHndl == -1
bFail = .T.
WAIT "Error opening output file!" WINDOW TIMEOUT 3
ENDIF
IF !bFail
cText = "" &&
* Get header first
DO WHILE UPPER(LEFT(FGETS(nFlHndl),7)) <> "RECORD#" .AND. !FEOF(nFlHndl)
ENDDO
DO WHILE !FEOF(nFlHndl)
* Next line of text
cNextLine = LTRIM(FGETS(nFlHndl))
* Get line number and pad it!
cLineNum = PADL(LEFT(cNextLine,AT(" ",cNextLine)-1),nLineNumPad,LineNumPadding)
* Trim line number from cNextLine
cNextLine = LTRIM(SUBSTR(cNextLine,AT(" ",cNextLine)))
* Concatanate cText with - padded line number, some extra space,
* the next line of text, and a CRLF
cText = cText + cLineNum + LineNumPadding + cNextLine + CRLF
ENDDO
=FCLOSE(nFlHndl)
DELETE FILE (cTempFile)
* cText holds value to be inserted into memo fields
INSERT INTO (cTempTbl) (MemFld) VALUES (cText)
SELECT (cTempTbl)
BROW
USE
DELETE FILE (SYS(2023)+"\"+cTempTbl+".dbf"

ENDIF
SET CENTURY &cOldCentury
SET SAFETY &cOldSafety
[/tt]