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 one main data type, called a variant. A variant is a very special data type, though, 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; however, internally it is much more complex, which permits it to hold a wide range of different numeric types.

Variant Data Subtypes

While the only data type recognized by VBScript is the variant, any item of variant data belongs to a particular subtype. Let’s look at the range of subtypes—or the different types of data—that a variant can hold:

Empty

The Empty subtype 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 subtype of var1 is Empty, whereas var2 is only Empty for the brief period of time between the execution of the Dim statement on the first line (which declares a variable; it is discussed later in this chapter in Section 3.2.5) and the assignment statement on the second line. In addition, a variable’s subtype ...

Get VBScript in a Nutshell 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.