Académique Documents
Professionnel Documents
Culture Documents
10/22/2013
Native: Types that are understood directly by the Visual Basic compiler without assistance from the
programmer
User-defined: commonly referred to by the initials UDT, meaning User defined Type, these correspond
to Pascal records or C structs
Classes: the basis for object oriented programming in Visual Basic. Classes include forms, add-ins,
and database designers.
Built in Types
The built in types are:
Byte
8 bit, unsigned
Integer
16 bit, signed
Long
32 bit signed
Single
32 bit floating point, range about
Double
64 bit IEEE floating point, range about
Currency
exact representation of decimal numbers of up to four decimal places
String
dynamically allocated UniCode strings, theorectical capacity about
Collection
an associative array of Variants.
Date
8 byte date/time value range January 1, 100 to December 31, 9999
Object
a holder for any type of Object.
characters.
Variant
a holder for any type of value or object.
Type Storage
Byte
1 byte
Range of Values
0 to 255
Long
These data
Type
Storage
store
values.
decimal
Single
Range of Values
compared to
Round()
decimal to a
"Double"
"Single" is
similar to
compared to
types can
the "Long"
"Integer".
rounds off a
certain
number of decimal digits that the programmer wants. The first argument should be a decimal value which you
want to round off. The second argument specifies the number of decimal digits you want, for example:
Dim pi as Double
pi=3.141592653589
pi=Round(pi,2) 'Rounds off 3.141592653589 to only two decimal digits
Print pi 'Prints 3.14
String
A string is an array of characters. As an example:
Dim a As String
a = "This is a string"
Strings can be concatenated (connected together to form a new string) using the "&" operator. For example,
dim b as String
b = "Wiki" & "book" & "s"
Print b 'Prints "Wikibooks"
A normal string variable occupies 10 bytes of RAM, plus the string's size, and can hold up to 2 billion
characters!
Structure
An example definition of a structured type:
Type E2Point
x As Double
y As Double
End Type
Sub Test()
Dim MyPoint As E2Point
Dim MyPoint2 As E2Point
MyPoint.x = 4
MyPoint.y = -5
MyPoint2 = MyPoint 'Make a copy
MyPoint2.x = 3
MyPoint2.y = -6
Debug.Print MyPoint.x, MyPoint.y '4, -5
not overriden with 3 and -6
Debug.Print TypeOf MyPoint Is E2Point 'True
Debug.Print TypeOf MyPoint Is Object 'False
End Sub
The type has to be defined outside of a procedure.
Enumeration
An example definition of an enumerated type:
Enum Colors
Red '=0
Green '=1
Blue '=2
End Enum
Enum Colors2
Red2 = 1
Green2 '=2
Blue2 '=3
End Enum
Sub Test()
Debug.Print Red, Green, Blue
Debug.Print Red2, Green2, Blue2
Dim MyVar As Colors 'Ends up being typed as Long
MyVar = 8 'Does not lead to an error: no restriction on values
End Sub