Microsoft Visual Basic 2005 Step by Step (Step by Step (Microsoft))
Chapter 6
Using Decision Structures
After completing this chapter, you will be able to:
Write conditional expressions.
Use an If…Then statement to branch to a set of program statements based on a varying condition.
Use the MaskedTextBox control to receive user input in a specific format.
Short-circuit an If…Then statement.
Use a Select Case statement to select one choice from many options in program code.
Use the Name property to rename objects within a program.
Manage mouse events and write a MouseHover event handler.
In the past few chapters, you used several features of Microsoft Visual Basic 2005 to process user input. You used menus, toolbars, dialog boxes, and other Toolbox controls to display choices for the user, and you processed input by using property settings, variables, operators, formulas, and the Microsoft .NET Framework.
In this chapter, you'll learn how to branch conditionally to a specific area in your program based on input you receive from the user. You'll also learn how to evaluate one or more properties or variables by using conditional expressions, and then execute one or more program statements based on the results. In short, you'll increase your programming vocabulary by creating code blocks called decision structures that control how your program executes, or flows, internally.
Upgrade Notes: Migrating Visual Basic 6 Code to Visual Basic 2005
If you're experienced with Microsoft Visual Basic 6, you'll notice some new features in Visual Basic 2005, including the following:
Visual Basic 2005 includes two logical operators named AndAlso and OrElse. In a conditional statement that contains multiple conditions, such as an If…Then decision structure, it might not be necessary to always evaluate all the conditions. Passing over conditions is sometimes called short-circuiting and can be controlled by using the AndAlso and OrElse operators.