| Chapter 3- Data Types and Operators | Boolean Expressions Page 2 3 4 |
| 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-4: Data Types in Visual Basic (continued)
Testing Exercise 3-2
Complete the code for Exercise 3-2 as indicated above and run the program. Enter values in the textboxes for Initial Capital and Interest Rate such as 2000 and 0.05 respectively and check that the calculation works when expected values are entered.
One very basic test of a program is to verify that it copes with whatever data the user might enter. In general we do not want a program to fail if the user enters something unusual. Instead we want to provide some kind of message to help the user. This is often a difficult task for the programmer since it requires anticipating a wide range of possible user actions.
With this simple program we should test it to discover under what circumstances it fails, and perhaps we can then think of a simple strategy to avoid most failures. It is not our intention to write a totally robust program. We merely want to understand the difficulties of the task and common simple strategies for coping.
The figure shows another test case for this program, which succeeds. Evidently strings containing commas, digits, a period, and scientific notation are successfully converted to numeric data by the conversion functions (Cdbl or System.Convert.toDouble method).
Here is a table of test cases that you should try out:
Table 3-4: Test Cases for Exercise 3-2.
| Initial Capital | Interest Rate | Succeeds? |
|---|---|---|
| 2000 | 0.05 | Yes |
| 1,045,201 | 5.0e-2 | Yes |
| 2,500.99 | 55.0e-3 | - |
| 2000 | .05 | - |
| 2000 | -0.05 | - |
| $2000 | 0.05 | - |
| 2,050,000.67 | 5% | - |
| ($2000) | 0.05 | - |
| $2.5e4 | 0.05 | - |
| ($2.5e4) | 0.05 | - |
| $2000 | 5% | - |
| (US)$2000 | .05 | - |