What are VBAs data types

When I talk about data type, I'm referring to the manner in which a program stores data in memory — for example, as integers, real numbers, or strings. Although VBA can take care of these details automatically, it does so at a cost. (There's no free lunch.) Letting VBA handle your data typing results in slower execution and inefficient memory use. For small applications, this usually doesn't present much of a problem. But for large or complex applications,

which may be slow or need to conserve every last byte of memory, you need to be on familiar terms with data types.

VBA's automatically handling all the data details makes life easy for programmers. Not all programming languages provide this luxury. For example, some languages are strictly typed, which means the programmer must explicitly define the data type for every variable used.

VBA has a variety of built-in data types. Table 7-1 lists the most common types of data that VBA can handle.

Table 7-1

VBA's Built-in Data Types

Data Type

Bytes Used

Range of Values

Boolean

2

True or False

Integer

2

-32,768 to 32,767

Long

4

-2,147,483,648 to 2,147,483,647

Single

4

-3.402823E38 to 1.401298E45

Double (negative)

8

-1.79769313486232E308 to -4.94065645841247E-324

Double (positive)

8

4.94065645841247E-324 to 1.79769313486232E308

Currency

8

-922,337,203,685,477.5808 to 922,337,203,685,477.5807

Date

8

1/1/100 to 12/31/9999

String

1 per char

Varies

Object

4

Any defined object

Variant

Varies

Any data type

User defined

Varies

Varies

In general, choose the data type that uses the smallest number of bytes but can still handle all the data the program assigns to it.

0 0

Post a comment