Microsoft Office Tutorials and References
In Depth Information
Understanding data types
LoanPayoffAmount = 243089
ChartHasATitle = False
x = x + 1
MyNum = YourNum * 1.25
TitleText = “4th Quarter Summary”
DateStarted = #4/1/2003#
Understanding data types
VBA makes life easy for programmers because it can automatically handle all the
details involved in dealing with data. The term data type refers to how data is
stored in memory — as integers, real numbers, strings, and so on.
Although VBA can take care of data typing automatically, it does so at a cost —
slower execution and less efficient use of memory. If you want optimal speed for
your code, 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 can handle all 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 14-1 lists VBA’s assortment of
builtin data types.
T ABLE 14-1 VBA’S DATA TYPES
Data Type
Bytes Used
Range of Values
Byte
1 byte
0 to 255
Boolean
2 bytes
TRUE or FALSE
Integer
2 bytes
–32,768 to 32,767
Long
4 bytes
–2,147,483,648 to 2,147,483,647
Single
4 bytes
–3.402823E38 to –1.401298E–45 (for
negative values); 1.401298E–45 to
3.402823E38 (for positive values)
Double
8 bytes
–1.79769313486231E308 to
–4.94065645841247E–324 (negative
values); 4.94065645841247E–324 to
1.79769313486232E308 (positive values)
Currency
8 bytes
–922,337,203,685,477.5808 to
922,337,203,685,477.5807
Continued
Search JabSto ::




Custom Search