|
VFP Tutorial - If ... Then ... EndIf
Switches program execution between two alternate paths depending on the value of a
logical expression:
If _TALLY = 0
Then
Wait Window
'No records found'
Else
Copy To
TmpFile.xls
Type XLS
Wait Window
'Exported to Xls'
Endif
If the expression _TALLY=0
evaluates as true (.T. in FoxPro)
then the statements between If and
Else will be executed.
If the expression evaluates as false
(.F. in FoxPro) then the statements
between Else and
EndIf will be executed.
Notes
_TALLY is a variable maintained by
FoxPro which holds the number of records processed by the last
command.
The condition must evaluate as .T.
or .F. because the logical values in
FoxPro are a separate data type and an integer result will not be
interpreted as a logical value.
The Then is optional but does no
harm. If you are used to working in the VB family of languages
where the word is compulsory then you will probably be in the
habit of adding it automatically.
The keyword EndIf is a single word.
The equivalent statement is two words in Visual Basic and if you
switch between using VB, Access and FoxPro then you will
continually be getting it wrong. VB and Access will both correct
this mistake but FoxPro doesn't.
The Else clause is optional and the
structure can just consist of
If ... EndIf.
The components of the structure must be on separate lines.
There is no ElseIf clause. Use a
Do Case
structure when you want to select between more than two choices.
Back to FoxPro
program control
.
Introduction |
Environment |
Project |
Tables |
Forms |
Navigation |
Executable
|