VFP Tutorial - Navigation

All the basic controls are available on the FoxPro Form Controls toolbar. This is shown docked above the Form Designer but can be dragged or docked anywhere on the desktop.

The FoxPro toolbar looks familiar but there are subtle differences between it and the equivalent toolbars in Access and Visual Basic. To add a control to the form you click once on the toolbar then once on the form. This will add the control to the form at its default size. You can click on the toolbar then click on the form and drag the control to a new size but it's easier to get the control onto the form in one operation and adjust the size later.

Don't try to drag a control from the toolbar to the form. Nothing will happen.

Add a Close button

Click on the button control (fifth button from the left) on the toolbar and drop it on the bottom right of the form. Double-click on the button to open an editor on the code that will run when the button is clicked. Type this line of code into that window:

ThisForm.Release

ThisForm is the FoxPro equivalent of Me in Access and refers to the form which holds this object. As you type the period a list of possible methods will appear. By the time that you have typed 'rel' Fox will have identified that you want the Release method and will pop up a tooltip to identify it. Press Enter to confirm.

[Editing the Click method]

Close and save the code window by pressing CTRL+W or by clicking the Save button on the toolbar. Then press CTRL+E or the exclamation mark on the toolbar to run the form.

[VFP Form with Close button]

Click the button and the form will close and return you to the Form Designer. The caption on the button is not quite right and we will correct this by changing the Caption property of the button. Right-click on the button and select Properties... from the menu.

Control properties

FoxPro is a flexible object-oriented system with a wide range of properties. You can reduce the number displayed so that you only see those which have been changed from their default values. Right-click on the name 'Command1' at the top of the Properties Window and select Non-Default Properties Only from the menu. This will filter the list to just the seven properties shown.

Click on the Caption property and type Close as a new value. Note that you cannot type where the value is shown in the list, you have to type the new value of the property into the textbox above.

[Visual FoxPro Properties Window]

Whilst you are in the Properties Window you can also change the name of the control from its default value of "Command1" to something more informative. You can see amongst the properties that the Click event holds a 'User Procedure'. This code is part of the object and will still be a part of the object if you change the object's name. Visual FoxPro does not suffer from the problem that Access and Basic have where changing the name of a property breaks the link to its methods and leaves you with an orphan.

Navigation buttons

Follow the same technique to add two more buttons to the form and change their Caption properties to read 'Prev' and 'Next'. Double-click on the 'Prev' button and type this code into its Click event:

* Move to the previous record and refresh the form
Skip -1
ThisForm.Refresh

The code in green is a comment. If a line starts with an asterisk then everything on that line becomes a comment and is ignored by the compiler.

Close the edit window, double-click on the 'Next' button and type this very similar code into its Click event:

* Move to the next record and refresh the form
Skip 1
ThisForm.Refresh

Add two more buttons to go to the first and the last record. The FoxPro commands are:

* Move to the first record and refresh the form
Go Top
ThisForm.Refresh

and

* Move to the last record and refresh the form
Go Bottom
ThisForm.Refresh

These four buttons are so similar that we would be thinking about subclassing them all from the same source in a real system.

Run the form

Click the red exclamation mark on the toolbar or select Run Form from the Form menu.

Navigation buttons on a FoxPro form

Improve the navigation

These navigation buttons are too simple to be useful in real life. They need extra code to prevent you trying to move to a position before the first record or after the last record. Go to this page to learn more about FoxPro program code .


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

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

Visual FoxPro Tutorial - The Goto statement

The truth about the FoxPro Goto statement

Read More

Visual FoxPro Tutorial - If ... Else ... EndIf

Using If EndIf to control program flow in Visual FoxPro

Read More

Visual FoxPro Tutorial - Scan ... EndScan loop

Using a scan loop to control program flow in Visual FoxPro

Read More

Visual FoxPro Tutorial - Variables

Using variables in Visual FoxPro

Read More

Visual FoxPro Tutorial - Program control

Syntax for program control structures in Visual FOxPro

Read More