3.1. Visual Basic Data Types
Visual Basic and Visual Basic for Applications support the following data types:
Boolean
Indicates the presence of logical data that can contain either of two values, True or False. The keywords True and False are constants that are predefined in VBA, so you can make use of them in your code when you want to assign a value to a Boolean variable, as the following code fragment shows:
var1 = True var2 = False
Many of the properties of ActiveX controls have possible values of True or False. In addition, within programs, Boolean variables often serve as flags to control program flow, as the following example, which toggles (or reverses) the value of myBool within the If...Else...End If construct, shows:
If myBool = False Then myVar = 4 myBool = True Else myVar = 5 myBool = False End If
Storage required
Two bytes
Range
True or False
Default value
False
Byte
The smallest numeric subtype available in VBA. Because only one byte holds a number ranging from to 255 (or 00 to FF in hexadecimal), there is no room for the sign, and so only positive numbers can be held in a Byte data type. Attempting to assign a negative number or a number greater than 255 to byte data results in a runtime error.
Storage required
One byte
Range
0 to 255
Default value
0
Currency
Provides a special numeric format for storing monetary values.
Storage required
Eight bytes
Range
–922,337,203,685,477.5808 to 922,337,203,685,477.5807
Default value
0
Date
Contains a specially formatted ...
Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.