Chapter 3. Data Types and Variables
In this chapter, we’ll discuss VBScript’s rather unusual support for a single data type before turning to variables and constants in VBScript.
VBScript Data Types: The Many Faces of the Variant
Unlike Visual Basic and Visual Basic for Applications, VBScript has only a single data type, called a variant. A variant is a very special data type, since it can contain many different types of data and can automatically select the most appropriate data type for the particular context in which it is being used. A simplified view of a variant is that it can hold both string data (characters) and numerical data as well as other data, such as dates, Booleans, and objects. Internally it is much more complex, which permits it to hold a wide range of different numeric types.
Variant Data Types
While the only data type recognized by VBScript is the variant, any item of variant data belongs to a particular type. Let’s look at the range of types — or the different types of data — that a variant can hold:
- Empty
Empty is a type that consists of a single value, also called
Empty
, that is automatically assigned to new variables when you declare them, but before you explicitly assign a value to them. For instance, in the code fragment:Dim var1, var2 var2 = 0
the type of
var1
is Empty, whereasvar2
is only Empty for the brief period of time between the execution of theDim
statement on the first line (which declares a variable; it is discussed later in this chapter in Section ...
Get VBScript in a Nutshell, 2nd Edition 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.