Data Types and Literals
Part:
1
2
This chapter describes:
- Data Types
- Data Literals
- More on String Literals
Notes and samples in this chapter are based Visual Basic 6.0.
Data Types
Visual Basic supports the following 10 basic data types:
- Byte: Using 1 byte to express integers ranging from 0 to 255.
- Integer: Using 2 bytes to express signed integers ranging from -32768 to 32767.
- Long Integer: Using 4 bytes to express signed integers ranging from -2147483648 to 2147483647.
- Single: Using 4 bytes to express real numbers in floating format ranging from -3.402823e38 to 3.402823e38.
- Double: Using 8 bytes to express real numbers in floating format ranging from -1.79769313486232d308 to
1.79769313486232d308.
- Currency: Using 8 bytes to express real numbers in decimal format ranging from -922337293685477.5808 to
922337293685477.5807.
- String: Using 1 byte per character to express a sequence of characters up to 65535 characters.
- Boolean: Using 2 bytes to express two Boolean values: true and false.
- Date: Using 8 bytes to express dates ranging from Jan. 1, 100 to Dec. 31, 9999.
- Variant: Using a complex storage structure to express any values of the other 8 data types.
Comparing to other programming languages, Currency, Date and Variant are un-usual data types.
We may need to spend more time to look at them.
Data Literals
Data literals are used to enter values in different data types into VB statements.
Here are the syntax rules on data literals.
1. Integer literals are signed integer numbers in decimal format, like -8, 0, and 777.
2. Long Integer literals have the same format as Integer literals but with more digits, like -888888, and 777777.
3. Single literals are signed real numbers with decimal points and exponentials, like 0.00314159e30.
4. Double literals have the same format as Float literals but with more digits and larger exponentials,
like 333.333e200.
5. Currency literals are signed real numbers with decimal points and no exponentials, like 999999.5555.
6. String literals are character strings enclosed in double quotes ("), like "Hello".
7. Boolean literals have two key words: True and False.
8. Date literals are dates in enclosed in hash signs (#), like #31-Dec-1999#.
9. Variant data type has no literals. It uses literals of other data types.
(Continued on next part...)
Part:
1
2
|