VFP Tutorial - If ... Then ... EndIf

Allows a choice between two actions 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. If you switch between using VB, Access and FoxPro then you will continually be making the mistake of writing it as two words.

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

More tips from Alvechurch Data

More tips from Alvechurch Data

If ... Else in VBA and VFP

Visual Basic and FoxPro If and Else.

Read More

If ... Else in C# and VFP

Using If and Else in C# and Visual FoxPro.

Read More