home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

19.4 Variants

In order for automation controllers and servers to cooperate, they have to have some way to agree on the type of data that they're passing. Automation accomplishes this through a data type called a VARIANT . The VARIANT data type is built on a C-language union. It contains a type field that identifies that type of data in the union (things such as strings, numbers, automation objects, etc.) and a field that contains the data.

Usually, Perl handles data-type conversion for you. If you need more control, though, you can create a Variant object and specify the type yourself. Perl provides access to the types listed in Table 19.3 .

Table 19.3: Variant Types

Variant Type



Unsigned character (1 byte)


Signed integer (2 bytes)


Signed integer (4 bytes)


Floating point (4 bytes)


Floating point (8 bytes)


OLE Date (floating-point value measuring days since midnight, Dec. 30, 1899)


OLE String


OLE Currency


OLE Boolean

By default, Perl converts integer data to the VT_I4 type, string data to the VT_BSTR type, and floating-point data to the VT_R8 type. Usually, these conversions are what you'd expect, but let's look at how you might specify your own type:

$vt = new OLE::Variant(OLE::VT_DATE, "May 31, 1997" );
$Message->{TimeSent} = $vt;

This example first creates a Variant object, setting the type to VT_DATE and the date to "May 31, 1997." It then assigns the date to the Message object TimeSent property (something you might do if you were posting a message to a folder, for example).