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

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

VFP and VBA.

The Visual FoxPro and Visual Basic for Applications languages are similar but there are annoying differences between them.

Read More

Text delimiters in VBA and VFP.

Visual Basic for Applications and Visual FoxPro delimiters for strings.

Read More

Text concatenation in VBA and VFP

Visual Basic for Applications and Visual FoxPro operators to concatenate text.

Read More

Text substrings in VBA and VFP

Visual Basic for Applications and Visual FoxPro functions to extract substrings from within a string of text

Read More

Trimming text in VBA and VFP

Visual Basic for Applications and Visual FoxPro functions to trim leading and trailing spaces from string of text

Read More