Chapter 1: Getting Started

Welcome to Visual FoxPro, the powerful object-oriented environment for database construction and application development. Visual FoxPro provides all the tools you need to manage data, whether you are organizing tables of information and running queries, creating an integrated relational database system, or programming a fully-developed data management application for end users.

Use the Documentation Map to find out more about Visual FoxPro features.

This chapter discusses:

Starting Visual FoxPro

If Visual FoxPro is not currently on your computer, you need to complete the Setup procedure. Setup instructions are in Chapter 1, Installing Visual FoxPro, in the Installation Guide.

To start Visual FoxPro

When you first start Visual FoxPro, the Project Manager creates a new, empty project so you can add existing items to your project or create new items to include in the project.

Using the Project Manager, you can quickly familiarize yourself with Visual FoxPro. The Project Manager provides an easy, visual way to organize and work with tables, forms, databases, reports, queries, and other files when you are managing tables and databases or creating an application.

The Project Manager organizes your data.

If you have your own set of tables from earlier versions of FoxPro®, you can add them to a project immediately to see how Visual FoxPro works. If you have other data you want to organize (be it in spreadsheets, text files, or tables from other applications), you can import it into Visual FoxPro and add it to a project. For more information, see Chapter 9, Importing and Exporting Data.

You can also create a new project at any time by choosing the New option from the File menu.

To create a new project

  1. From the File menu, choose New.

  2. Select Project and choose New File.

  3. In the Create dialog box, type the name you want to assign to the new project.

  4. Choose Save.

To help you become familiar with Visual FoxPro, you can also use the sample files that are provided. These samples are in folders within the Visual Studio …\Samples\Vfp98 directory.

Testdata.dbc

This database contains a simple set of related tables that you can experiment with while becoming familiar with Visual FoxPro. This database was used to create the examples in this book.

Tastrade.pjx

This project contains a fully developed end-user application that you can use to understand the type of application you can develop with Visual FoxPro. By opening the project and examining how it is structured, you can gain insight into how to assemble an application.

Introducing the Project Manager

The Project Manager is the primary organizational tool for working with data and objects in Visual FoxPro. A project is a collection of files, data, documents, and Visual FoxPro objects that is saved as a file with a .pjx extension.

The Project Manager is your “control center” for working with Visual FoxPro.

You can use the Project Manager to organize and manage files as you create tables and databases, write queries, set up forms and reports, and build applications. For more information about building applications with the Project Manager, see the Programmer’s Guide.

You can begin creating your own project by adding existing Visual FoxPro .dbf files to a new project, or by using the sample files located in the Visual Studio …\Samples\Vfp98\Data directory.

Viewing What is in Your Project

The Project Manager presents an organized, hierarchical view of your data. To focus on a particular type of file or object in your project, choose the appropriate tab.

When you are setting up tables and databases and creating forms, queries, views, and reports, you work primarily with the items shown under the Data and Documents tabs.

Locating Data Files

This tab contains all the data for a project: the databases, free tables, queries, and views.

The Data tab in the Project Manager

Databases are sets of tables, usually related to each other through common fields. To support the tables and relationships, you can also include views, connections, stored procedures, business rules, and triggers in your database. You create a database with the Database Designer, which is introduced in Chapter 3, Collecting Tables into a Database. Database files have a .dbc extension.

Free tables are tables which are not part of a database and are stored in a file with a .dbf extension. Creating tables is discussed in Chapter 2, Creating Tables and Indexes.

Queries are a structured way to request specific information stored in tables. Using the Query Designer, you format a question that extracts records from your tables based on the criteria you enter. Queries are SQL-Select commands saved as text files with a .qpr extension. For more information about queries, see Chapter 4, Retrieving Data.

Views are specialized queries that enable you to access both local and remote data and allows for update of data sources by making changes to the records returned by the query. Views exist only within a database and are not independent files. For more information about views, see Chapter 5, Updating Data with Views.

Locating Form and Report Files

The Documents tab contains all the documents you use when working with data: forms for entering and viewing data, and reports and labels for printing tables and query results.

The Documents tab in the Project Manager

Forms are used to display and edit the contents of tables. Creating forms with the Form Designer is discussed in Chapter 8, Managing Data Through Forms.

Reports are files that tell Visual FoxPro how to format and print the results of queries run on tables. Creating reports with the Report Designer is discussed in Chapter 7, Designing Reports and Labels. Labels are special reports formatted to print on label stock.

The other tabs — Classes, Code, and Other — are primarily used when creating applications for end users. Working with classes, code, and other files is discussed in the Programmer’s Guide in the context of creating an application.

Viewing File Details

The items in the Project Manager are organized in an outline view that you can expand or collapse to look at different levels of detail.

A plus sign (+) appears next to a symbol if there are one or more items of that type in the project. Click the plus sign (+) to display the names of items of that type in the project.

For example, click the plus sign next to the Free Tables symbol to see the names of free tables in the project.

The outline view shows different levels of detail in your project.

To collapse a list once it is expanded, click the minus sign that appears next to the list.

Adding and Removing Files

To use the Project Manager, you must add existing files to it or use it to create new files. For example, if you have a set of existing .dbf tables you want to add to a project, just select Free Tables in the Data tab and use the Add button to add them to the project.

To add a file to a project

  1. Select the type of item you want to add.

  2. Choose Add.

  3. In the Open dialog box, select the name of the file you want to add and choose OK.

To remove a file from a project

  1. Select the element you want to remove.

  2. Choose Remove.

  3. In the confirmation prompt, choose Remove.

If you want to delete the file from your computer, choose Delete.

Creating and Modifying Files

The Project Manager simplifies creating and modifying files. Just select the type of file you want to create or modify and choose the New or Modify button. Visual FoxPro displays the design tool appropriate to the type of file you selected.

To create a file to add to the Project Manager

  1. Select the element you want to create.

  2. Choose New.

With some items, you have the option to use a wizard to help you create the file.

To modify a file

  1. Select an existing file.

  2. Choose Modify.

For example, to modify a table, select the name of the table and choose Modify to display the table in the Table Designer.

Adding a Description to a File

When you create or add a new file, you can add a description to the file. This description is shown at the bottom of the Project Manager when the file is selected.

To add a description to a file

  1. In the Project Manager, select the file.

  2. From the Project menu, choose Edit Description.

  3. In the Description dialog box, type a description for the file.

  4. Choose OK.

Viewing Data in Tables

From the Project Manager, you can browse the contents of the tables in your project.

To browse a table

  1. Select the Data tab.

  2. Select a table and choose Browse.

Viewing tables in a Browse window is discussed in Chapter 2, Creating Tables and Indexes.

Sharing Files Between Projects

You can reuse your work from one project by sharing files with another project. The files are not duplicated, because the project stores only a reference to the file. Files can be associated with different projects simultaneously.

To share files between projects

  1. In Visual FoxPro, open the two projects that will share the file.

  2. In the Project Manager containing the file, select the file.

  3. Drag the file to the container for the other project.

Customizing the Project Manager

You can customize your visual work area by changing your view of the Project Manager or by setting double-click to run files in the Project Manager. For more information about customizing your visual work area, see Chapter 3, Configuring Visual FoxPro, in the Installation Guide.

Changing Your View

Initially, the Project Manager appears as a separate window. You can move the container, resize it, or collapse it so that only the tabs show.

To move the Project Manager

To resize the Project Manager

To collapse the Project Manager

You can easily return the Project Manager to its usual size.

To restore the Project Manager

When the container is collapsed, you can tear off and arrange individual tabs to suit your workspace preferences. When you tear off a tab, it floats independently in the main Visual FoxPro window.

To tear off a tab

  1. Collapse the container.

  2. Select a tab and drag it away from the Project Manager.

When a tab is floating, you can access the options on the Project menu by right-clicking the mouse in the floating tab.

If you want the tab to always remain on top, click the pushpin icon at the top of the tab. The tab will remain on top of other Visual FoxPro windows. You can set more than one tab to be “always on top.” To remove the “always on top” setting on a tab, click the pushpin icon again.

Project Manager tabs

To restore a tab

You can also attach or dock the Project Manager so that it appears as a toolbar on the top of your main Visual FoxPro window.

To dock the Project Manager

When the Project Manager is docked, it becomes part of the toolbar area of the window. You can’t expand the Project Manager window when it’s docked; instead, you click on individual tabs to use them. You can also tear off tabs from a docked Project Manager.

Introducing the Visual FoxPro Designers

The Project Manager gives you quick access to the Visual FoxPro designers. These tools make it easy to create tables, forms, databases, queries, and reports to manage your data.

This section describes how to use the designers. You can also assemble the items you create with the designers into an application. Creating an application from tables, databases, and forms is discussed in the Programmer’s Guide.

You can also use the designers independently from the Project Manager by using the options of the New command on the File menu. The following table summarizes which designers to use to accomplish different tasks:

To Use this designer
Create tables and set indexes on tables Table Designer
Run queries on local tables Query Designer
Run queries on remote data sources; create updatable queries View Designer
Create a form for viewing and editing the data in your tables Form Designer
Create a report for displaying and printing your data Report Designer
Set up a database; view and create relationships between tables Database Designer
Create a connection for remote views Connection Designer

To use the designers to create new files

Using Toolbars

Each designer has one or more toolbars that give you quick access to the most commonly used features or actions of the tool. For example, the Form Designer has separate toolbars for controls and control layout, and a color palette.

You can place as many toolbars on your screen as you need while working. You can dock toolbars to the top, bottom, or sides of your screen to customize your working environment. Visual FoxPro saves the positions of the toolbars so they remain where you last placed them.

To display toolbars

  1. From the View menu, choose Toolbars.

  2. In the Toolbars dialog box, select the toolbars you want to use.

  3. Choose OK.

To dock a toolbar

Using Wizards

Wizards are interactive programs that help you quickly accomplish common tasks such as creating forms, formatting reports, and setting up queries. For information on individual wizards, see Wizards Overview or press F1 when you are using the wizard.

By answering questions or choosing options on the series of wizard screens, you are telling the wizard to build a file or perform a task based on your responses. For example, if you choose the Report Wizard, you can select the type of report you want to create. The wizard then asks which table you want to use and provides choices for formatting the report.

Starting a Wizard

When you create a new item using the Project Manager or the File menu, you can choose to use a wizard to help you create the item.

To start a Wizard

  1. In the Project Manager, select the type of file you want to create, and choose New.

    You can also choose New from the File menu and select the type of file you want to create.

  2. Select the Wizard option.

You can also access most wizards directly by choosing the Wizards command from the Tools menu.

If you use a Visual FoxPro wizard on data from a table in a database, you can use styles and field mappings stored in the database for forms, tables, labels, queries and reports.

Navigating the Wizard Screens

Once you have the wizard running, just answer the questions on each screen. When you are ready to proceed to the next screen, choose the Next button.

If you make a mistake or change your mind, choose the Back button to see the previous screen so you can make changes. Choose Cancel to exit the wizard without producing any results. If you have a question about using the wizard, press F1 to get Help.

When you reach the last screen, choose the Finish button to exit the wizard.

If you are in a hurry, you can choose the Finish button to proceed to the end of the wizard sequence, skipping the entry of optional information and using defaults supplied by the wizard.

Saving Wizard Results

The last screen of each wizard might ask you to supply a title and, depending upon the type of wizard you are using, give you options to save, browse, modify, or print your results.

Use the Preview option to see the results of the wizard before you are finished with the wizard. You can rerun the wizard if you want to make different choices to change the results. When you are satisfied with the wizard results, choose the Finish button.

Modifying Wizard-Created Items

Once you have created a table, form, query, or report, you can open it in the appropriate design tool and make further changes to it. You cannot reopen a wizard-generated file with a wizard, but you can preview the wizard results and make changes before exiting the wizard.

Using Builders

Builders are tabbed dialog boxes that simplify creating and modifying forms, complex controls, and referential integrity code. Each builder displays a series of tabs so you can set the properties of the selected object. You can use builders for some controls, for forms, for formatting controls, and for creating referential integrity between database tables.

To build a control

To use the Form Builder

Once you have several controls on a form, you can format them all at the same time with the AutoFormat Builder.

To format several controls

  1. In the Form Designer, select controls.

  2. From the Form Designer Toolbar, choose the AutoFormat button.

When a builder is displayed, select the options for each tab and then choose OK to register the changes.

To See
Build a combo box Combo Box Builder
Build a command group Command Group Builder
Build an edit box Edit Box Builder
Build a form Form Builder
Build a grid Grid Builder
Build a list box List Box Builder
Build an option group Option Group Builder
Build a text box Text Box Builder
Format a group of controls AutoFormat Builder
Create referential integrity between database tables Referential Integrity Builder