If and Select Statements

The If...Then block has a single line and multiple line syntax. The condition of an If statement can be a comparison or an expression, but it must evaluate to True or False.

If condition Then Statements...         'single line syntax

If condition Then                              'multiple line syntax

statements...

End If

 

The other variation on the If statement is the If...Then...Else statement. This statement should be used when there are different statement blocks to be executed depending on the condition. There is also the If...Then...ElseIf... variation, these can get quite long and cumbersome, at which time you should consider using the Select statement.

If condition Then

statements...

ElseIf condition Then

statements...

End If

 

The Select Case statement tests the same variable for many different values. This statement tends to be easier to read, understand and follow and should be used in place of a complicated If...Then...ElseIf statement.

Select Case <variable to test>

Case 1

statements...

Case 2

statements...

Case 3

statements...

Case Else

statements...

End Select

See "Language Reference A - Z" chapter for exact syntax and code examples.