FoxPro TextMerge
You can use the
Copy To
command to create a simple text file from a table with various forms of
delimiter between fields. The TextMerge
commands let you create a more complex text file. The contents can be
a mixture of plain text, fields and variables, and FoxPro functions.
The commands are:
Set Textmerge On
Tell Fox to evaluate anything it sees between << and >>. These
delimiters can be changed with the Set Delimiters
To command.
Set Textmerge To
<filename>
Noshow
Direct the output to a file. The file will be created if it does not
already exist. If the file does exist and
Safety is
On then you will be asked whether you want
to overwrite it. The Noshow clause
suppresses output to the screen.
\xyz
Send the characters 'xyz' to the file preceded by a CR LF combination.
There is no need for quotes around the characters. If you put quotes around
the characters then the quotes will be output as well.
\\xyz
Send the characters 'xyz' to the file on the current line.
<<foxpro expression>>
Evaluate the FoxPro expression. The expression can be the name of a
field or memory variable or a FoxPro function. The example below shows
how you can mix <<foxpro expression>> with plain text on the
same line.
Set TextMerge To
Close the output file.
Set Textmerge Off
Stop evaluating expressions within << and >>.
Text Merge Example
This example produces an HTML page holding a simple list of customers:
Use Customer
Set Textmerge On
Set Textmerge To
customer.htm
noshow
\<html>
\<head>
\<title>HTML from FoxPro</title>
\</head>
\<body>
\<h1>Customer List</h1>
\<hr />
Scan
  
\Company name is
<<Upper(Company)>>
  
\<br />
Endscan
\</body>
\</html>
Set Textmerge To
Set Textmerge Off
Use In Customer
This short program will produce a text file named 'customer.htm' which
looks like this in a browser:
This is a very simple page and the mixture of TextMerge and HTML can be
confusing to write because both use the < and > symbols. It is
however a very powerful and flexible technique which lets you build
a page which will display a mixture of text and data.
Visual FoxPro offers other ways of generating HTML. These are described
on the
HTML from FoxPro
page.
Gotcha
There are two things to watch out for when using text merge and a third
when using it to produce HTML:
-
Everything on the line after a \ or \\, including any trailing
spaces, will be output.
-
The carriage return/linefeed comes before the characters are
output.
-
Remember that a \\ produces a new line of output in the text of the
HTML file. It will not produce a new line on the web page. You never
really need to use a \\ when generating HTML because browsers ignore
new lines in the HTML source.
|