| 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
Up until this point we have been assigning values to object properties and writing expressions involving values with something close to abandon! The last example brought a stop to our sloppy approach, and we now have to take a step back to understand more carefully how values and data are used in a Visual Basic program. This task is complicated by the fact that Visual Basic attempts to do certain things for us if we are sloppy in our approach to data. In fact much of what we have already done relies on Visual Basic to "correct" our sloppiness, if you like.
You are aware from Chapter 2 and the earlier parts of this chapter that there are different types of data. You have used string or text data, integer numbers, and boolean (true/false) data. A more complete list is contained in Table 3-2.
Table 3-2: A partial list of primitive data types.
| Data Type Name | Storage size | Range of values |
|---|---|---|
| Boolean | 2 byte | True or False (1 or 0) |
| Byte | 1 byte | integers in the range 0 to 255 |
| Char | 2 bytes | 0 to 65,535 representing the Unicode character set |
| Date | 8 bytes | time/date between 0:00:00 on 1/1/0001 to 23:59:59 on 12/31/9999 |
| Double | 8 bytes | a real number; precision is about 14 digits to the right of the decimal point |
| Integer | 4 bytes | integers in the range -2,147,483,648 to 2,147,483,647 |
| Long | 8 bytes | very big! |
| Short | 2 bytes | integers in the range -32,768 to 32,767 |
| Single | 4 bytes | a real number, i.e. a number with a decimal (fractional) part; precision is limited to about 6 digits to the right of the decimal point. |
| String | depends on platform | up to approximately 2 billion Unicode characters |
Notice that the types Short, Integer and Long are all integers with the difference that the Long data type can represent values much larger than 2,147,483,647, and Short can only represent numbers with magnitude up to just 32,767!
Similarly Single and Double are both real number data types with the difference that Double can represent not only larger values but also more accurate values (i.e. more decimal figures)