TEXT ... ENDTEXT Command Example

The following example demonstrates how you can use SET TEXTMERGE, SET TEXTMERGE DELIMITERS, TEXT ... ENDTEXT, and the _TEXT system variable.

A low-level file called Names.txt is created and its file handle is stored in the _TEXT system variable. The program is exited if Names.txt can't be created. The customer table is opened, and the names of the first 10 contacts are output to Names.txt. Text and the results of functions are output to the text file.

The text file containing the names is then opened with MODIFY FILE.

CLEAR
CLOSE DATABASES
SET TALK OFF
SET TEXTMERGE ON     && Enable embedding of expressions and functions
STORE FCREATE('names.txt') TO _TEXT     && Create low-level file
IF _TEXT = -1  && Can't create low-level file then exit program
   WAIT WINDOW 'Cannot create an output file; press a key to exit'
   CANCEL
ENDIF

CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'Data\testdata')
USE customer  && Opens Customer table

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  && Close the text file and the table
MODIFY FILE names.txt
ERASE names.txt