Microsoft Office Tutorials and References
In Depth Information
in a For-Next loop) may make a very descriptive variable name, the following instruction generates a syntax er-
ror:
Next = 132
Defining data types
VBA makes life easy for programmers because it can automatically handle all the details involved in dealing
with data. Data type refers to how data is stored in memory — as integers, logical values, strings, and so on.
Although VBA can take care of data typing automatically, it does so at a cost — namely, slower execution and
less efficient use of memory. If you want optimal speed for your functions, you need to be familiar with data
types. Generally, it's best to use the data type that uses the smallest number of bytes yet still is able to handle all
of the data that will be assigned to it. When VBA works with data, execution speed is a function of the number
of bytes that VBA has at its disposal. In other words, the fewer bytes used by data, the faster VBA can access
and manipulate the data. Table 25-1 lists VBA's assortment of built-in data types.
Table 25-1: VBA Data Types
Data
Type
Bytes
Used
Range of Values
Byte
1
0 to 255
Boolean 2
True or False
Integer
2
–32,768 to 32,767
Long
4
–2,147,483,648 to 2,147,483,647
–3.40E38 to –1.40E–45 for negative values; 1.40E–45 to 3.40E38
for positive values
Single
4
–1.79E308 to –4.94E-324 for negative values; 4.94E–324 to
1.79E308 for positive values
Double
8
Currency 8
–922,337,203,685,477 to 922,337,203,685,477
Date
8
1/1/0100 to 12/31/9999
Object
4
Any object reference
1 per char-
acter
String
Varies
Variant
Varies
Varies
Declaring variables
 
Search JabSto ::




Custom Search