Dynamically generating data pages with VFP (II.)

Source: Internet
Author: User
Tags expression functions generator html tags variables microsoft frontpage

Easy to build Web pages in Visual FoxPro

I remember at the beginning of this article on the bombast: easy, rapid generation of web pages. As if to now a little with the visual FoxPro "Do not stand," Now let visual FoxPro play!

There are many ways to manipulate strings to text in Visual FoxPro, such as low-level file functions, Strtofile (), SET Textmerge, and so on. I prefer SET Textmerge because it's very graphic and integrates output information with traditional Visual FoxPro code.

SET Textmerge, which has the following applications:

    1. SET textmerge on Open Text merge calculation switch

    2. SET textmerge off text merge calculation switch

    3. The set Textmerge to E:\HTML\TEMP.htm NoShow enters the merged text into the file E:\HTML\TEMP.htm and closes the screen display (turning off the screen display does not run at the speed of the program!!! )

    4. SET Textmerge to close and save files for text merge output

Let's take a look at this command:

Clear
SET TALK off
Cstring= "Chinese! "
SET Textmerge on
\ Great <<cString>>
The Magnificent mountains and rivers
The Hard-working people
*!* the following two lines to perform the effect:
* The Great Chinese! Magnificent mountains and rivers
* The Hard-working people

Here are three signs, let's see what they mean:

\: The text after this tag is merged, resulting in a newline output

\: The text after this tag is merged, and the resulting result continues on one line of output

<< >> (Text merge separator): variables, functions in the secondary symbol are evaluated, and the output is merged.

Clear
SET TALK off
Cstring= "Chinese! "
Set Textmerge off && closes the text merge calculation switch, so the variables and functions in <<>> will not be computed to output
\ Great <<cString>>
The Magnificent mountains and rivers
The Hard-working people
*!* the following two lines to perform the effect:
* Great <<cString>> Magnificent mountains and rivers
* The Hard-working people

<< >> is the system default text merge separator that you can use SET textmerge delimiters to change the text merge separator:

Clear
SET TALK off
Cstring= "Chinese! "
SET textmerge delimiters to "# #", "# #" && new text Merge Separator # # #
SET Textmerge on
\ The Great <<cstring>># #cString # #
The Magnificent mountains and rivers
The Hard-working people
SET textmerge delimiters to && restore system default Text merge separator
\ The Great <<cstring>># #cString # #
*!* the following three lines to perform the effect:
* Great <<cString>> Chinese! Magnificent mountains and rivers
* The Hard-working people
* The Great Chinese! # #cString # #

Well, speaking of which, I think you already know how to build a Web page in Visual FoxPro. Create a new program to copy the HTML that is generated in FrontPage, and add "\" before each line to represent the text merge output. Then add a head to this piece of code and a tail, the process is simple, the result is as follows:

SET Textmerge on
SET textmerge delimiters to "# #", "# #"
SET Textmerge to E:\HTML\TEMP.htm noshow
\\\<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
\<meta name= "generator" content= "Microsoft FrontPage 4.0" >
\<meta name= "ProgId" content= "FrontPage.Editor.Document" >
\<title>my-Vfp-html</title>
\<style>
\<!--
\.boe1 {font-family:verdana; font-size:10pt; Margin-left:2}
\.boe3 {font-family:verdana; font-size:10pt; text-decoration:line-through; Margin-left:2}
\.boe2 {font-family:verdana; font-size:10pt; color: #FF0000; Margin-left:2}
\-->
\</style>
\
\<body leftmargin= "topmargin=" >

\<table border= "1" width= "94%" cellspacing= "0" cellpadding= "0" bordercolor= "#000000" >
\<tr>
\&LT;TD width= "100%" >
\<p style= "Margin-bottom: -10" ><font face= "Verdana" size= "2" ><b>description</b>\</font ></p>
\<p style= "MARGIN-LEFT:3; Margin-right:3 "><font face=" Verdana "size=" 3 "><b>you can use \the printwhen-expression to change the fonts Tyles printed based on the values being \printed. In Thiscase, the detail-printed-in-red for those products whose in-stock are below \the level. Also, any products of that have been discontinued are printed in strikeout.\</b></font></td>
\</tr>
\</table>
\<p> </p>
\<p align= "center" >\</p>
\<table border= "0" width= "100%" >
\<tr>
\&LT;TD width= "41%" ><font face= "Verdana" size= "3" ><b>Product</b></font></td>
\&LT;TD width= "17%" ><font face= "Verdana" size= "3" ><b>in stock</b></font></td>
\&LT;TD width= "18%" ><font face= "Verdana" size= "3" ><b>on order</b></font></td>
\&LT;TD width= "24%" ></td>
\</tr>
\</table>
\<table border= "2" width= "100%" bordercolor= "#000000" height= "1" cellspacing= "0" \cellpadding= "0" >
\<tr>
\&LT;TD width= "100%" height= "1" ></td>
\</tr>
\</table>
\<table border= "0" width= "100%" >
\<tr>
\&LT;TD width= "8%" ></td>
\&LT;TD width= "33%" ></td>
\&LT;TD width= "17%" ></td>
\&LT;TD width= "19%" ></td>
\&LT;TD width= "23%" ></td>
\</tr>
\</table>
\</body>
\SET Textmerge off
SET Textmerge to
SET Textmerge DELI

By now, our web page generation program has been completed by 50%. The most important thing is to fill in the page, the technical issues mentioned above--use the text merge separator, the variables, functions will be calculated and then merge the output!

How do you write so many HTML tags? Very simple, I made the "rough" page when I have to display the data where I added a (row) table, now look at the data table has a few data, there are n dots to produce n lines, the code is as follows:

SET Textmerge on
SET textmerge delimiters to "# #", "# #"
SET Textmerge to E:\HTML\TEMP.htm noshow

Select Products
\\\<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
\<meta name= "generator" content= "Microsoft FrontPage 4.0" >
\<meta name= "ProgId" content= "FrontPage.Editor.Document" >
\<title>my-Vfp-html</title>
\<style>
\<!--
\.boe1 {font-family:verdana; font-size:10pt; Margin-left:2}
\.boe3 {font-family:verdana; font-size:10pt; text-decoration:line-through; Margin-left:2}
\.boe2 {font-family:verdana; font-size:10pt; color: #FF0000; Margin-left:2}
\-->
\</style>
\
\<body leftmargin= "topmargin=" >

\<table border= "1" width= "94%" cellspacing= "0" cellpadding= "0" bordercolor= "#000000" >
\<tr>
\&LT;TD width= "100%" >
\<p style= "Margin-bottom: -10" ><font face= "Verdana" size= "2" ><b>description</b></font ></p>
\<p style= "MARGIN-LEFT:3; Margin-right:3 "><font face=" Verdana "size=" 3 "><b>you can use \the printwhen-expression to change the fonts Tyles printed based on the values being \printed. In Thiscase, the detail-printed-in-red for those products whose in-stock are below \the level. Also, any products \that have been discontinued are printed in strikeout.</b>\</font></td>
\</tr>
\</table>
\<p> </p>
\<p align= "center" ></p>
\<table border= "0" width= "100%" >
\<tr>
\&LT;TD width= "41%" ><font face= "Verdana" size= "3" ><b>Product</b></font></td>
\&LT;TD width= "17%" ><font face= "Verdana" size= "3" ><b>in stock</b></font></td>
\&LT;TD width= "18%" ><font face= "Verdana" size= "3" ><b>on order</b></font></td>
\&LT;TD width= "24%" ></td>
\</tr>
\</table>
\<table border= "2" width= "100%" bordercolor= "#000000" height= "1" cellspacing= "0" \cellpadding= "0" >
\<tr>
\&LT;TD width= "100%" height= "1" ></td>
\</tr>
\</table>
\<table border= "0" width= "100%" >
Scan all
Do case
Case products.discontinu=.t.
\<tr>
\&LT;TD width= "8%" ><p class= "Boe3" ># #alltr (product_id) ##</td>
\&LT;TD width= "33%" ><p class= "Boe3" ># #alltr (prod_name) ##</td>
\&LT;TD width= "17%" ><p class= "Boe3" ># #alltr (Transform (in_stock)) ##</td>
\&LT;TD width= "19%" ><p class= "Boe3" ># #alltr (Transform (on_order)) ##</td>
\&LT;TD width= "23%" ></td>
\</tr>
Case PRODUCTS.DISCONTINU=.F.
If In_stock>reorder_at
\<tr>
\&LT;TD width= "8%" ><p class= "Boe1" ># #alltr (product_id) ##</td>
\&LT;TD width= "33%" ><p class= "Boe1" ># #alltr (prod_name) ##</td>
\&LT;TD width= "17%" ><p class= "Boe1" ># #alltr (Transform (in_stock)) ##</td>
\&LT;TD width= "19%" ><p class= "Boe1" ># #alltr (Transform (on_order)) ##</td>
\&LT;TD width= "23%" ></td>
\</tr>
Else
\<tr>
\&LT;TD width= "8%" ><p class= "Boe2" ># #alltr (product_id) ##</td>
\&LT;TD width= "33%" ><p class= "Boe2" ># #alltr (prod_name) ##</td>
\&LT;TD width= "17%" ><p class= "Boe2" ># #alltr (Transform (in_stock)) ##</td>
\&LT;TD width= "19%" ><p class= "Boe2" ># #alltr (Transform (on_order)) ##</td>
\&LT;TD width= "23%" ><p class= "Boe2" >stock below reorder level of # #alltr (transform (reorder_at)) ##</td>
\</tr>
endif
Endcase
ENDscan
\</table>
\</body>
\SET Textmerge off
SET Textmerge to
SET Textmerge DELI

By now, it's done. It seems like the whole process is a hassle, but it's really simple--the simplest program, which is the characteristic of Visual FoxPro, encapsulates the annoying work, but it's not like other development environments--visual FoxPro tend to be encapsulated in a "traditional" fashion (non-OOP), The goal is to give us the greatest flexibility!

How to use the demo program

Use Products
Do BUILDHTML.PRG with "c:\vfphtm.htm" && please copy title.jpg to C packing directory beforehand.
Obrowse=createobject ("Internetexplorer.application")
obrowse.visible=.t.
Obrowse.navigate ("file:///c:\vfphtm.htm")

Apply this technology to other tasks

Apply to XML

These days I'm learning XML (extensible Markup Name language) technology, and I think in the near future he will be a new technology in the database field. I wrote a program that converts the visual FoxPro cursor to a *.xml file, which is implemented by the Cursortoxml () function in Visual FoxPro 7, which is much better than the program I wrote. I would like to cite this example, I hope that everyone's attention to XML, deepen the understanding of the previous article, the most important thing is that XML is a very complex specification, only the built-in functions provided by visual FoxPro 7 may not be covered, learn their own control of XML is of great benefit. Of course, the topic of XML is a lot, complicated, and we'll talk about it later.

The following is the use of the code you downloaded:

Use Products && This function applies to any Visual FoxPro cursor
Do DBF2XML.PRG and "products", "C:\vfpxml.xml"
Obrowse=createobject ("Internetexplorer.application")
obrowse.visible=.t.
Obrowse.navigate ("File:///c:\vfpxml.xml")

Application infinity, imagine in your

I really like the Visual FoxPro of this feature, too simple, too great. It's great at the application level, in addition to the above two examples, we can use it to simply export data, without the annoying low-level file functions, you can export data before the arbitrary processing ...

Now in the form of pure text transmission, display information has become a general trend, the so-called: the general trend, shun the Chang, the reverse of the dead. It is commendable that this trick of Visual FoxPro is in keeping with the times.

Visual FoxPro 7 has been improved on SET Textmerge, but I can't tell you more if it's not explicitly listed in my BATE 1 help. But it can be considered that this function is a major feature of the Visual FoxPro of the new era.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.