Microsoft Office Tutorials and References
In Depth Information
Selection Statements
A key facet of most applications is the ability to make decisions. This ability allows the appli­
cation to make decisions about input received from the user and any values that might be
calculated.
If…Then…Else Statement
The simplest form of decision making is performed with the If…Then…Else statement. It
examines an expression to see if it is true or not. If the expression is Tr ue , the code performs
one set of actions; otherwise, it performs a different set of actions.
If…Then…Else statements can take two forms, either single-line or multi-line. The syntax of
both forms is shown here.
If condition Then statements Else elsestatements
or
If condition Then
[ statements ]
[ ElseIf elseifcondition [ Then ]
[ elseifstatements ] ]
[ Else
[Else elsestatements ] ]
End If
condition
A required expression that must evaluate to a Tr ue or False Boolean value
statements Optional block of one or more statements that are to be executed when
the condition is Tr ue
elseifcondition A required expression if ElseIf is present that must evaluate to a Tr ue
or False Boolean value
elseifstatements Optional block of one or more statements that are to be executed
when the elseifcondition is Tr ue
elsestatements Optional block of one or more statements that are to be executed if no
previous condition or elseifcondition is Tr ue
End If
A required element in multi-line form and terminates the If…Then block
Using the If…Then…Else statements requires the use of comparison operators to build the
needed condition statements. The comparison operators compare two or more values and
decide if the values are equal to each other or if one is greater than the other; then the oper­
ators return a True or False answer. The six comparison operators are listed in Table 4-11.
Search JabSto ::




Custom Search