Conditional Statements
Part:
1
2
3
This chapter describes:
- "If" Statements
- "If" Statement Example
- "Select Case" Statements
- "Select Case" Statement Example
"If" Statements
There 4 flavors of "If" statements in VB:
1. Single-statement "If":
If condition Then statement
where "condition" is Boolean value, and "statement" is any VB statement. The specified statement will be executed,
if and only if the specified condition is "True".
2. Multi-statement "If":
If condition Then
statement_block (multiple statements)
End If
The specified multi-statement block will be executed, if and only if the specified condition is "True".
3. "If ... Else" Statement:
If condition Then
statement_block_a
Else
statement_block_b
End If
Two statement blocks are specified. But only one statement block will be executed based on the value of
the specified condition. If the specified condition is "True", the first block will be executed.
If the specified condition is "False", the second block will be executed.
4. "If ... ElseIf" Statement:
If condition_1 Then
statement_block_1
ElseIf condition_2 Then
statement_block_2
...
...
Else
statement_block_n
End If
Many statement blocks are specified. But only one statement block will be executed based on the value of
the condition specified for that block.
(Continued on next part...)
Part:
1
2
3
|