Chapter 3- Data Types and Operators Boolean Expressions Page 2 3 4

Introduction

The If Statement Page 2 3 4 5 6 7 8 9
Arithmetic Operations Page 2 3 4 5 6 Boolean Operators and Nested If Statements Page 2 3 4 5 6 7
Events and Sequential Processing Page 2 3 4 5 More Examples Page 2 3 4 5 6 7 8 9 10 11 12
Datatypes and Conversions Page 2 3 4 5 6 7 Using Check Box and Option Controls Page 2 3 4 5 6 7 8 9 10
Variable Declarations - Local and Global Page 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Exercises Page 2 3 4 5 6 7 8
Chapter 4- Selection Statements Review Questions
Introduction

Selection Statements

4-1: Introduction

In the previous chapter we have seen the use of operators and variables to form expressions, and the assignment of the value resulting from such an expression to a variable or object property. The code statements we wrote relied on sequential execution. I.e. one statement might assign a value to a variable, and then the next statement in the sequence might use that variable (now with its new value) to calculate something else. The code we wrote could only execute the statements in an event one after another in sequence.

Often such sequential processing of statements is not adequate for the task we want to solve. For example, you have seen from some of the exercises in Chapter 3 that if the user enters invalid data in a textbox (suppose the data is meant to be numeric and the user enters something that cannot be converted to a number) your program will crash with a run-time error.

Instead of just executing the statements it would be nice to be able to first check what the user has entered and then make a choice - either execute the statements or issue a message saying the data is wrong. How we go about making the selection of which statements to execute is the subject of this chapter.

The main concepts in this chapter are

In addition we look at approaches to validating user input, including use of the Validating event and the CausesValidation property. This is part of Exercise 4-9, which is therefore very important that you complete.