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

3-2: Arithmetic Operators (continued)

Exercise 3-1: Calculating the Area of a Circle - Testing the Program

Start debugging your program and perform the following tests:

  1. Enter 1 in the radius textbox. What should the area be?
    Press the Calc. Area button and check if the result is correct?
  2. Enter any positive value in the radius textbox and press the Calc. Area button. Perform a quick mental order of magnitude check - is the result plausible?
  3. Enter the same value as in case ii but negative and press the Calc. Area button. Should this result be allowed?
  4. Enter zero in the radius textbox and press the Calc. Area button.
  5. Press the Clear button and then press the Calc. Area button.

So cases iii and v are problematic indicating that, even in a very simple program such as this, things are perhaps not quite as simple as they might seem.

Case v results in the VB environment displaying information about something called an unhandled exception. Figure 3-3 shows the screen snapshot and the message InvalidCastException was unhandled. There is lots of further information and the environment highlights the offending line of code. For now simply note the line that says Conversion from String "" to type 'Double' is not valid. We'll discuss information in the next few sections that helps make sense of this.

Figure 3-3: A runtime exception

For now all we can do about this error is stop the debugging, so from the Debug menu select Stop Debugging.