O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required