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 (database file); the variable-length data, graphics and OLE objects have an extension of .fpt (foxpro text and the indexes are .cdx (compound index. 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. This simple application will only have a single table and does not need the overhead of a database.

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 was requested for the Integer and Date fields, the size of these data types is fixed by FoxPro.

[Table Designer in Visual FoxPro]

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:

[Visual FoxPro Status bar]

This shows that the table named 'CD' is open, it's open for your exclusive use, it holds three records and the record pointer is on the first record.

Type:

Browse

in the Command Window to view the 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 whenever a Browse window is open on the desktop.

[Visual FoxPro Browse command]

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

More tips from Alvechurch Data

More tips from Alvechurch Data

FoxPro table functions

FoxPro commands and functions to manipulate fields and tables.

Read More

FoxPro file extensions

File formats and extensions used by FoxPro

Read More

FoxPro 101 - Databases

Visual FoxPro Tutorial - Combining tables into a database.

Read More