Visit our new web pages

We have launched a new extended set of web pages at www.alvechurchdata.co.uk. These old pages will stay on the server because people still have links to them but they will not be updated.

The new version of this page is at www.alvechurchdata.co.uk/hints-and-tips/fox101table.html.

VFP Tutorial - Data Tables


Table files

Unlike Access or SQL Server, FoxPro stores all the tables of its database as separate files. Fields of fixed-length data are held in a file with an extension of .dbf; the variable-length data, graphics and OLE objects have an extension of .fpt and the indexes are .cdx. This separation has good and bad points but is proved reliable over many years.

Designing a table

We will skip the first and most important phase of this process and assume that the structure of the table has already been considered. This project has a single table named CD with the following structure:

Field Type Size Description
CDID I   Unique sequential number to identify each CD
Publisher C 30 Publisher of this CD - eg 'Microsoft'
CDName C 30 Name of this CD - eg 'Visual FoxPro 8'
SerialNo C 40 Manufacturer's serial number
Key C 40 Security Key
CDDate D   Date received

Creating a table

Click on the Data tab of the Project Manager then right-click on Free Tables

Select New File then New Table from the dialog that appears. This dialog allows you to start the Table Wizard which can be useful if your application matches one of the templates provided.

An explorer dialog will appear offering to create a table named 'Table1.dbf'. Change the name to 'CD.dbf' and save it in the same folder as the project manager file. A real life project typically has its files in a directory tree structure but we'll put all the files in the same folder here for simplicity.

The Table Designer will appear. Add the six fields from the list above and click OK when you have finished. Note that no size has been given for the Integer and Date fields, these are fixed.

[Table Designer]

The greyed-out fields on the right of the designer are only available for tables which are part of a database. You can leave the main route through the tutorial and go to this page to learn about Visual FoxPro databases

Viewing the table

When you have closed the Table Designer you should see an entry like this in the status bar at the base of the screen:

[Status bar]

This shows that the table named 'CD' is open, it's open for your exclusive use, and it holds no records.

Type:

Browse

to view the empty table.

Do not worry if the status bar is empty. If there is no table open when you type the command then Fox will display a directory tree and ask you to select a table.

Adding some records

Unlike Access, you cannot just create a new record by typing on a blank line in the grid. You have to select Append New Record from the Table menu. This menu pad appears when a Browse window is open on the desktop.

[Browse a table]

Do this three or four times and add some data to the table so that you will have something to work with when you design a form.


Introduction | Environment | Project | Tables | Forms | Navigation | Executable


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