Visual Basic and Visual FoxPro If ... Else statements

VBA

If, Then, Else, ElseIf, End If

VFP

If, Else, EndIf

Common Syntax Notes

The syntax is almost identical in the two languages. This example is Visual Basic

If a > b Then
  c = "Bigger"
Else
  c = "Smaller"
End If

and this is the same snippet in Visual FoxPro:

If a > b Then
  c = "Bigger"
Else
  c = "Smaller"
EndIf

You can only see one infuriating difference, I have been careful to avoid the other:

  • Visual Basic insists on having a Then after the If whereas it's optional in Visual FoxPro.
  • Visual Basic has End If as two words whereas it's the single word EndIf in Visual FoxPro. What's worse is that VB will automatically correct you if you type EndIf by mistake but, despite having Intellisense, FoxPro won't. I suppose I should add this as a custom feature to my own Intellisense table.

Apart from that, VBA allows multiple clauses to be chained together with ElseIf where FoxPro would use its Do Case structure.

Procedures  |  Language index  |  Case