How to Write Programs Using Visual FoxPro

By Jeff Grundy

Visual FoxPro offers beginning and seasoned developers a data-centric programming environment in which they can create robust management applications for entering, searching, sorting and manipulating data from various database engines. Besides FoxPro's powerful front-end programming features, its royalty-free distribution model can save your business a considerable amount of money when creating applications for many users, after you factor in licensing costs for standalone products such as Access or Microsoft SQL. To get started with programming a Visual FoxPro application, use one of the many wizards to connect a front-end application to a supported database.

Launch Visual FoxPro. Click “Tools” on the menu bar, then click “Wizards” and “Application.”

Type a name for the new program in the Application Name field. Select a folder on your computer in which to store the project files for the application, then click the “OK” button.

Click the “Data” tab in the new application window, then click “Select.” Browse to the ODBC client-compliant database you wish to use as the backend for the Visual FoxPro application. For smaller database applications, using a Microsoft Access database as the backend produces good results. For larger applications, SQL or MySQL databases can handle large numbers of entries and data transactions. After you select the database, Visual FoxPro displays a list of tables in the data source. Select the table for which you want to create a form to use in the application, then click “Open.”

Click the “Forms” tab in the new application window. Visual FoxPro generates a basic form based on the database source and table you selected. For instance, if the table has five fields, the form generated by Visual FoxPro will also have five text fields.

Create button controls on the new form as needed. For instance, to create a simple application that lets users cycle through records in the database, drag-and-drop a button control on the form, then change the caption label for the button control to “Next.”

Double-click the new “Next” button you created on the form to open a code editor window for the control. In the editor window, enter the following code:

IF ! EOF() SKIP THISFORM.REFRESH ELSE GO TOP ENDIF

Click “File” on the Visual FoxPro menu bar, then click “Save” to save the changes to the form and your new application.

Click “Project Builder” in the new application window, then select the “Win32/COM” option. Click the “Build” button to compile the program into an executable file, along with any necessary dependency files such as DLL files and the database source file. Visual FoxPro creates a new application in a subfolder of the folder you selected to store the project files for the application.

Open Windows Explorer and browse to the folder in which Visual FoxPro copied the executable and dependency files. Copy and paste the folder to other computers as needed. To run the program, open the folder and double-click the executable file. Users can run the program even on computers that do not have FoxPro installed.

Tips

To create an install or setup utility for your Visual FoxPro program, use either a third-party installer or the installer/setup wizard in Microsoft Visual Studio. Third-party installer programs are available from companies such as Inno, Wise and ComponentSource.

×