contents   index   previous   next



Variant Fundamentals

 

Variants are one of the most interesting, versatile and controversial data types introduced by the COM/OLE standard. A Variant is a self-describing data type. Because of this Variant variables can represent a large variety of data. The same Variant variable could contain a real value or a reference to an object. This flexibility is the basis to the controversies surrounding the use of Variants. Many programmers argue that the weak-typing of Variants encourages bad programming habits and code that is harder to debug. This can be particularly true in languages like Visual Basic, that implement Variants as an intrinsic data type, and will not flag as an error (or even a warning) assignment of values of two completely different types to the same Variant variable. Some languages, like Visual Script, have taken the use of Variants to the extreme; these languages use Variants as their only data type. On the other hand, technologies like ActiveX and COM would not be possible or severely hindered without the implementation of Variants to communicate data between servers and clients.

 

Fortran does not have a native data type comparable to a Variant, but f90VB’s Variants library gives Fortran all the necessary functionality to manipulate Variants as used by Visual Basic and the OLE/COM protocols.

 

In this chapter, we will review the basic concepts about Variants; how they are defined, what gives them their flexibility, and how you can take advantage of f90VB’s Variants library to create Fortran subroutines that can handle Visual Basic’s Variant arguments.

 

The definition of a Variant

7 basic rules for manipulating Variants

Declaring Variants with f90VB

Creating and initializing Variants

Checking the type and obtaining the contents of a Variant

De-referencing chained Variants

Copying Variants

Clearing Variants

Variant arithmetic and logical operations

Performing OLE/COM-conforming conversion of data types