Condividi tramite


TEXT ... ENDTEXT Command

Outputs lines of text, the results of expressions and functions, and the contents of variables.

TEXT [TO VarName [ADDITIVE] [TEXTMERGE] [NOSHOW]]
   TextLines
ENDTEXT

Parameters

  • TextLines
    Specifies the text sent to the current output device. TextLines can consist of text, memory variables, array elements, expressions, functions or any combination of these.

    Expressions, functions, memory variables, and array elements specified with TextLines are evaluated only if SET TEXTMERGE is ON and must be enclosed in the delimiters specified by SET TEXTMERGE DELIMITERS. If SET TEXTMERGE is OFF, the expressions, functions, memory variables, and array elements are output as literals along with their delimiters.

    For example, today's date is output if SET TEXTMERGE is ON and a text line contains <<DATE( )>>. If SET TEXTMERGE is OFF, <<DATE( )>> is output literally.

    If you place comments within TEXT and ENDTEXT or after \ or \\, the comments are also output.

  • TO VarName
    This is memory variable name to use for passing the contents of the TEXTENDTEXT control statement. This variable can already exist. If the variable has not yet been declared, it will automatically be created as a Private variable. The new TO setting will work regardless of SET TEXTMERGE. If SET TEXTMERGE is set to a file and the TO statement is included, then both file and variable get output.

  • ADDITIVE
    This keyword determines if the contents of the TO variable are overwritten or added to existing contents. Note: if the content of the TO variable is not a string, Visual FoxPro always overwrites.

  • TEXTMERGE
    The TEXTMERGE keyword enables evaluation of contents surrounded by delimiters without having to do a SET TEXTMERGE ON.

  • NOSHOW
    The NOSHOW keyword disables display to screen of textmerge.

Remarks

This structured programming command sends text lines placed between TEXT and ENDTEXT to the main Visual FoxPro window, a user-defined window, a printer, a text file, or a low-level file.

TEXT sends the text lines to the current output device. This continues until an ENDTEXT statement is encountered or until the program ends.

By default, output from TEXT ... ENDTEXT is sent to the main Visual FoxPro window or the active window. Issue SET CONSOLE OFF to suppress output to the main Visual FoxPro window or the active window. Use SET PRINTER to send output to a printer or a text file.

Output from TEXT ... ENDTEXT can also be sent to a low-level file created or opened with FCREATE( ) or FOPEN( ). If a file handle returned by FCREATE( ) or FOPEN( ) is stored to the _TEXT system variable, output is directed to the corresponding low-level file.

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

See Also

FOPEN( ) | _PRETEXT | SET TEXTMERGE | SET TEXTMERGE DELIMITERS | _TEXT