Sends lines of text specified by TextLines to the current output device or memory variable. Visual FoxPro sends lines of text to the current output device until it encounters an ENDTEXT statement or until the program ends.

The current output device can include the main Visual FoxPro window, a user-defined window, a printer, a text file, or a low-level file.

TEXT [TO VarName [ADDITIVE] [TEXTMERGE] [NOSHOW] [FLAGS nValue] [PRETEXT eExpression]]
      TextLines
ENDTEXT

Parameters

TextLines

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

NoteNote

Visual FoxPro evaluates expressions, functions, memory variables, and array elements specified with TextLines only if you set SET TEXTMERGE to ON and enclose them with the delimiters specified by SET TEXTMERGE DELIMITERS. If SET TEXTMERGE is OFF, Visual FoxPro outputs expressions, functions, memory variables, and array elements as string literals along with their delimiters.

For example, Visual FoxPro evaluates and outputs the current date when you specify the DATE( ) function as TextLines only if SET TEXTMERGE is ON, and TextLines contains the function and the appropriate delimiters, such as <<DATE( )>>. If SET TEXTMERGE is OFF, Visual FoxPro outputs <<DATE( )>> as a string literal.

If you place comments within TEXT...ENDTEXT or after the single backslash character (\) or double backslash characters (\\), Visual FoxPro outputs the comments.

TO VarName

Specifies the memory variable name to use for passing the contents of the TEXT...ENDTEXT. This variable can already exist.

If the variable has not yet been declared, Visual FoxPro automatically creates it as a private variable. The TO clause operates regardless of how SET TEXTMERGE is set. If SET TEXTMERGE is set to a file, and the TO statement is included, Visual FoxPro outputs both the file and variable.

ADDITIVE

Determines whether the contents of the TO variable are overwritten or added to existing contents.

NoteNote

If the contents of TO  VarName is not a string, Visual FoxPro always overwrites the contents in VarName.

TEXTMERGE

Enables evaluation of contents surrounded by delimiters without setting SET TEXTMERGE to ON.

NOSHOW

Disables display of the text merge to the screen.

FLAGS nValue

Specifies a numerical value that determines if output is suppressed to an output file, or if blank lines preceding any text are included in the output.

Value (additive) Description

1

Suppresses output to the file specified with the _TEXT System Variable.

2

When the NOSHOW clause is included, preserves blank lines preceding text that appears within TEXT...ENDTEXT. Setting nValue to 2 will separate current TEXT...ENDTEXT output from previous TEXT...ENDTEXT output with a line feed.

NoteNote

Combining an nValue setting of 2 and PRETEXT of 4 will separate current TEXT…ENDTEXT output from previous TEXT…ENDTEXT output with a line feed while removing empty lines in the TEXT...ENDTEXT output.

PRETEXT eExpression

Specifies a character string to insert before each line of the text merge contents between TEXT...ENDTEXT or a numeric expression.

The following table describes behaviors of the PRETEXT clause depending on the expression specified by eExpression.

eExpression PRETEXT behavior

Character expression

Insert the expression before each line of the text merge contents appearing between the TEXT...ENDTEXT statement. When using PRETEXT with TEXT...ENDTEXT, eExpression is limited to a maximum length of 255 characters.

eExpression overrides the contents of the _PRETEXT system variable. When eExpression contains an expression that needs to be evaluated, for example, a user-defined function (UDF), Visual FoxPro evaluates it only once when the TEXT command first appears.

Numeric expression

Specify additive flag values to determine behavior for the text merge contents appearing between the TEXT...ENDTEXT statement.

For example, a value of 7 specifies that Visual FoxPro eliminate all white space including spaces, tabs, and carriage returns. A value falling outside of the range of 0-15 produces an error.

NoteNote

Specifying a value of zero does not eliminate white space.

When eExpression is a numeric expression, you can use the _PRETEXT system variable to insert additional text after Visual FoxPro eliminates white space.

The following table lists numeric additive flags that you can use in eExpression to specify additional behavior.

Value (Additive) Description

1

Eliminate spaces before each line.

2

Eliminate tabs before each line.

4

Eliminate carriage returns, for example, blank lines, before each line.

8

Eliminate line feeds.

NoteNote

Unlike the _PRETEXT system variable, the PRETEXT clause does not have global scope and applies only to the TEXT...ENDTEXT statement in which it appears.

Characters removed using the PRETEXT clause apply only to text within the TEXT...ENDTEXT statement and not to evaluated text merged from cExpression. In the following example, the spaces in the memory variable, myvar, are not removed when merged with the text in TEXT...ENDTEXT:

 CopyCode imageCopy Code
myvar = "   AAA"
TEXT TO x NOSHOW ADDITIVE TEXTMERGE PRETEXT 7
Start Line
<<myvar>>
      BBB
   CCC
ENDTEXT

Expand imageRemarks

Expand imageExample

Expand imageSee Also