Decision Making with VBA

Relational and Logical Operators ■ If...Then Statement ■ Decisions Based on More Than One Condition

■ The If...Then...Else Statement ■ The If...Then... Elself Statement ■ Nested If...Then... Statements ■ Select Case Statement ■ Using Is with the Case Clause

■ Specifying a Range of Values in a Case Clause ■ Specifying Multiple Expressions in a Case Clause ■ What's Next.

We make thousands of decisions every day. Some decisions are spontaneous. We make them automatically without having to stop and think. Other decisions require that we weigh two or more options or even plan several tasks ahead. Visual Basic for Applications, like other programming languages, offers special statements that allow you to include decision points in your own procedures. But what is decision making? Let's say someone approaches you with the question, "Do you like the color red?" After giving this question some thought, you'll answer "yes" or "no." If you're undecided or simply don't care, you might answer "maybe" or "perhaps." In programming, you must be decisive. Only "yes" or "no" answers are allowed. In programming, all decisions are based on supplied answers. If the answer is positive, the procedure executes a specified block of instructions. If the answer is negative, the procedure executes another block of instructions or simply doesn't do anything. In this chapter, you will learn how to use VBA conditional statements to alter the flow of your program. Conditional statements are often referred to as "control structures," as they give you the ability to control the flow of your VBA procedure by skipping over certain statements and "branching" to another part of the procedure.

0 0

Post a comment