136 Part II Programming Fundamentals
TABLE 5-1 Fundamental Data Types in Visual Basic
Data Type Size Range Sample Usage
Short 16-bit –32,768 through 32,767 Dim Birds As Short^
Birds = 12500
UShort 16-bit 0 through 65,535 Dim Days As UShort^
Days = 55000
Integer 32-bit –2,147,483,648 through
2,147,483,647
Dim Insects As Integer
Insects = 37500000
UInteger 32-bit 0 through 4,294,967,295 Dim Joys As UInteger^
Joys = 3000000000
Long 64-bit –9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
Dim WorldPop As Long
WorldPop = 4800000004
ULong 64-bit 0 through
18,446,744,073,709,551,615
Dim Stars As ULong
Stars = _
1800000000000000000
Single 32-bit
floating point
–3 .4028235E38 through
3 .4028235E38
Dim Price As Single
Price = 899.99
Double 64-bit
floating point
–1 .79769313486231E308 through
1 .79769313486231E308
Dim Pi As Double
Pi = 3.1415926535
Decimal 128-bit 0 through +/–79,228,162,514,264,
337,593,543,950,335
(+/–7 .9... E+28) with no
decimal point; 0 through +/–
7 .9228162514264337593543950335
with 28 places to the right of the
decimal. Append “D” if you want
to force Visual Basic to initialize a
Decimal.
Dim Debt As Decimal
Debt = 7600300.5D
Byte 8-bit 0 through 255 (no negative
numbers)
Dim RetKey As Byte
RetKey = 13
SByte 8-bit –128 through 127 Dim NegVal As SByte^
NegVal = – 20
Char 16-bit Any Unicode symbol in the range
0–65,535. Append “c” when
initializing a Char.
Dim UnicodeChar As Char
UnicodeChar = "Ä"c
String Usually 16-bits
per character
0 to approximately 2 billion
16-bit Unicode characters
Dim Dog As String
Dog = "pointer"
Boolean 16-bit True or False. (During conversions,
0 is converted to False, other values
to True .)
Dim Flag as Boolean
Flag = True
Date 64-bit January 1, 0001, through
December 31, 9999
Dim Birthday as Date
Birthday = #3/1/1963#
Object 32-bit Any type can be stored in a variable
of type Object.
Dim MyApp As Object
MyApp = CreateObject _
("Word.Application")