Conditional Code Blocks

If..Then..Else

The If..Then..Else is the most classical block for conditionally executing actions. An If evaluates an expression as True or False and according to this allows specifying actions to take. Listing 4.7 shows an example.

Listing 4.7 Demonstrating the If..Then..Else Block

image

If checks if the condition is True; if so, it takes the specified action. Of course you can also specify to evaluate a condition for False (for example, If something = False Then). You can also use an ElseIf to delimit the condition evaluation. If no expression satisfies the condition, the Else statement provides an action that will be executed ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.