Chapter 6 Using Decision Structures 179
Chapter 6 Quick Reference
To Do This
Write a conditional
expression
Use one of the following comparison operators
between two values: =, <>, >, <, >=, or <=.
Use an If... Then
decision structure
Use the following syntax:
If condition1 Then
statements executed if condition1 True
ElseIf condition2 Then
statements executed if condition2 True
Else
statements executed if none are True
End If
Receive input from the
user in a specific format
Add a MaskedTextBox control to your form, and specify the input
format by configuring the Mask property.
Use a Select Case
decision structure
Use the following syntax:
Select Case variable
Case value1
statements executed if value1 matches
Case value2
statements executed if value2 matches
Case Else
statements executed if none match
End Select
Rename an object in
a program
Select the object that you want to rename, and then modify the
object’s (Name) property by using the Properties window. If you
give the object a three-character prefix that identifies its object
type (btn, lbl, lst, etc .), the object is easier to spot in program code.
Make two comparisons in
a conditional expression
Use a logical operator between comparisons (And, Or, Not, or Xor).
Short-circuit an If... Then
statement
If... Then statements can be short-circuited when the AndAlso and
OrElse operators are used and two or more conditional expressions
are given. Depending on the result of the first condition, Visual Basic
might not evaluate the additional conditions, and the statement is
short-circuited.
Write an event handler In the Code Editor, click an object name in the Class Name list box,
and then click an event name in the Method Name list box. Add
program statements to the event procedure (called an event handler)
that respond to the event you are customizing.