HTML from FoxPro


HTML is just text and FoxPro has always been very good at manipulating text . Generating the HTML on your own PC gives you a static document on the web but that's sometimes all that the user needs. There are four easy ways of generating HTML from FoxPro:

  • The Web Page Wizard
  • The GenHTML utility
  • TextMerge
  • StrToFile()
  • The FoxPro Editor

Web Page Wizard

This is more useful than most wizards and creates a table of data on a web page from a VFP table or cursor. The wizard generates an HTML file but can also generate a prg file to to recreate that web page. This generated program uses GenHTML and creates and uses a new entry in the GenHTML table.

GenHTML

The 'Save as HTML' option on the File menu calls the generator program specified by system variable _GENHTML. This is usually GenHTML.Prg but you can write your own utility if oyou want to improve it. GenHTML.Prg can be added to your project and distributed in an executable.

Simple syntax is:

DO GenHTML With lcHTMLFileName, lcTableName

You can extend the power of GenHTML by referring to two FoxPro Foundation Classes and a table of styles:

  • _HTML.vcx
  • _HTMLSty.vcx
  • GenHTML.dbf

These too can be distributed in your application.

TextMerge

TextMerge is a tool that dates from FoxPro version 2.00 where we used it to create reports. TextMerge produces a pure ASCII output to a text file and the only way to get special effects in these reports was to embed printer control codes in the text. The Report Writer made life so much easier that TextMerge was little used.

The output from TextMerge can be a mixture of text literals, the contents of fields or memory variables, or the result of VFP functions and TextMerge is now being used as a powerful tool for generating a web page from FoxPro data.

More details on TextMerge here.

StrToFile

StrToFile is a new function introduced with VFP 5. It takes a string variable and writes it into a text file. You have the option of creating a new file, overwriting an existing file, or adding text to the end of an existing file.

StrToFile returns the number of bytes written so you can check this value to ensure that your file has actually been created. The VFP 7 version of StrToFile (and its partner FileToStr) opens the file in Shared mode to reduce the risk of conflict

USE Customer

*-- Start the string with a heading for the page
lcHTML = '<h1>Customer List</h1>'

*-- Now append 'Company' and the company name for each record
SCAN
   lcHTML = lcHTML + '<br>Company  '
   lcHTML = lcHTML + ALLTRIM (Company)
ENDSCAN

*-- And send it to a file
=StrToFile (lcHTML, 'Customer.htm')

FoxPro Editor

Don't forget that FoxPro has a good text editor built in - much better than Notepad as a basic tool for writing HTML. Think of all these advantages:

  • Multiple levels of Undo.
  • Drag and Drop.
  • Automatic indenting.
  • Intellisense which can be extended so that typing PP gives you the opening and closing paragraph tags and puts the cursor between them:

    <P>
       |
    </P>
  • Global search and replace across all pages using Code References on the Tools menu.
  • Write simple programs to write and manipulate your HTML files.

Hints & tips

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.
Autocomplete in VFP 9

Your Access database will look more impressive if you add custom toolbars...
Custom toolbars

FoxPro has always had functions to read and write files at a low level...
Foxpro low level file functions

More...
More pages of hints and tips for users of Microsoft FoxPro and Access databases.

Site Map