If Then Else

To test several conditions, define several blocks of statements where a statement is executed only when its condition is met. For example:

If <condition1> Then <statement block 1>

Else If <statement block 2>

Else

<statement block 3> End If

If <condition1> returns True, Visual Basic executes the statements following the Then keyword. Visual Basic ignores the statements in <statement block 2> and <statement block 3>, continuing execution with the statements following the End If keywords.

If <condition1> returns False, Visual Basic executes the statements following the Else If keywords, if supplied. Visual Basic ignores the statements in <statement block 1> and <statement block 3>, continuing execution with the statements following the End If keywords.

You may use any number of Else If statements, but only one Else statement, in an If ... Then ... Else statement.

Was this article helpful?

0 0

Post a comment