Appendix I. The Variant Subtypes

The reference material in this appendix is a companion to the detailed explanation in Chapter 3 of data types, in particular the VBScript Variant data type. However, a brief description of these concepts follows.

VBScript is what is known as a weakly typed programming language, which is the opposite of a strongly typed language. A weakly typed language does not allow you to declare variables with specific data types such as String, Date, or Boolean. Instead, in VBScript, all variables are automatically and implicitly assigned a special data type called Variant. The Variant data type is actually many data types in one. VBScript still has the concept of data types such as String, Date, and Boolean, but they are embedded within the "container" of the Variant type. The more specific type inside of the Variant type is called a subtype. A Variant variable can have one of many different subtypes — but only one subtype at a time.

The subtype of a Variant variable can change in one of two ways: implicitly and explicitly.

  • An implicit change in subtype occurs when a new value is assigned to a Variant variable. Before the new value being assigned to the variable is committed, the VBScript engine uses its own logic to examine the new value and automatically decide what the subtype should be. If the new value fits within the bounds of the already assigned subtype, VBScript does not change it. This automatic subtype change process is called implicit type coercion ...

Get VBScript Programmer's Reference, Third 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.