VFP Tutorial - Program Code
Visual FoxPro uses the same language in programs, functions and methods
as it does in the interactive Command Window.
Prev button
This button will move us to the previous record in the table so we
must make sure that the user cannot try to navigate beyond the first
record. An If statement in the click
method of the Prev button will detect whether we are trying to move
to the record before the first one and this code will prevent the user
seeing an error message.
It uses the BOF()
function to determine whether we are at "Beginning of File":
The Then in the first line is optional.
Anybody who works in Visual Basic as well as in FoxPro will already
be in the habit of adding it because it's compulsory in that family
of languages. The final EndIf is
one word. You will get a syntax error if you use two words in VB
style End If.
The Else clause is optional but the components of the If structure
must always be on separate lines.
Next button
The Next button needs to detect whether we are at "End of File"
to prevent the user moving beyond the last record. It has similar
code using the EOF() function but the
logic has to be more complex because the
EOF()
function does not become true until after the record pointer has moved
beyond the last record.
If Eof() Then
Go Bottom
Else
Enabling buttons
Preventing the user from seeing these error messages improves the
usability of the form. Another improvement would be to set the Enabled
property of the
and
buttons false when we are on the last record. This will grey out the
buttons to make it obvious that the user cannot move any further in that
direction.
ThisForm.cmdNext.Enabled
= .F.
ThisForm.cmdLast.Enabled
= .F.
We will need similar commands to disable the
and
buttons when on the first record.
Note that you have to give the full names of the buttons. They have
no independent existence so you must specify them completely.
True and False values are
represented by .T. and
.F. in FoxPro. They are a separate
logical data type and are not related to integers in any way. FoxPro
uses .Null. to represent a null value
in any data type.
Going further
These two pages give more details about
variables
and
programming.
Introduction |
Environment |
Project |
Tables |
Forms |
Navigation |
Executable
|