The Conditional Statements Explained
If...Else...ElseIf Statement
If/Else Statments are used to conditionally execute code based on condition provided. If the condition provided in the If statement evaluates to true, the code in the block is executed. Otherwise, execution would proceed to the optional ElseIf statements, or the Else statement. ElseIf and Else are not required parts of an If statement.
An example of the If/Else/ElseIf branch statement is:
'The following variable declarations are for the following example only. They are not needed in real life.
Dim x As Integer
Dim y As Integer
If x = y Then
'Whatever will happen if x = y
ElseIf x < y Then
'Whatever will happen if x < y
Else
'Whatever will happen if x isn't = to y and x isn't < to y
End If
Select Case Statement
Either strings or numbers can be used for a Select Case statement.
Select Case statements are usually used to avoid long chains of If/ElseIf/.../ElseIf/Else statements.
An example of a Select Case branch statement using an integer is:
Dim nCPU as Integer
Select Case nCPU
Case 0
'No CPU!
Case 1
'Single CPU
Case 2
'Dual CPU machine
Case 4
'Quad CPU machine
Case 3, 5 To 8
'3, 5, 6, 7, 8 CPU's
Case Else
'Something more than 8
End Select
All text is available under the terms of the GNU Free Documentation License
Source : Wikibooks |