Example 1
The following example demonstrates creating a low-level file called myNamesFile.txt and storing its file handle in the _TEXT system variable. The program exits if the myNamesFile.txt file cannot be created.
Visual FoxPro opens the customer table and outputs the names of the first ten contacts to myNamesFile.txt. Visual FoxPro outputs the text and results of the functions to the text file. The example uses MODIFY FILE to open myNamesFile.txt.
CLEAR
CLOSE DATABASES
SET TALK OFF
SET TEXTMERGE ON
STORE FCREATE('myNamesFile.txt') TO _TEXT
IF _TEXT = -1
WAIT WINDOW 'Cannot create an output file. Press a key to exit.'
CANCEL
ENDIF
CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'Data\testdata')
USE customer
TEXT
CONTACT NAMES
<<DATE( )>> <<TIME( )>>
ENDTEXT
WAIT WINDOW 'Press a key to generate the first ten names.'
SCAN NEXT 10
TEXT
<<contact>>
ENDTEXT
ENDSCAN
CLOSE ALL
MODIFY FILE myNamesFile.txt
ERASE myNamesFile.txt Example 2
The following example shows a custom procedure that uses TEXT...ENDTEXT to store an XML DataSet to a variable. In the example, all spaces, tabs, and carriage returns are eliminated.
PROCEDURE myProcedure
DO CASE
CASE nValue = 1
TEXT TO myVar NOSHOW TEXT PRETEXT 7
<?xml version="1.0" encoding="utf-8"?>
<DataSet xmlns="http://tempuri.org">
<<ALLTRIM(STRCONV(leRetVal.item(0).xml,9))>>
</DataSet>
ENDTEXT
OTHERWISE
ENDCASE
ENDPROC