Variants are used to pass and return values from ActiveX functions that could return different types of data.
Several AutoLISP functions allow you to create and work with variants:
The vlax-make-variant function accepts two arguments: value and type. The value argument is the value to be assigned to the variant. The type argument specifies the type of data to be stored in the variant. For type , specify one of the following constants:
For example, the following function call creates an integer variant and sets its value to 5:
(setq varint (vlax-make-variant 5 vlax-vbInteger)) #<variant 2 5>
The return value indicates the variant's data type (2, which is vbInteger) and the variant's value (5). If you do not specify a data type to vlax-make-variant, the function assigns a default type.
For example, the following function call creates a variant and assigns it a value of 5 but does not specify a data type:
(setq varint (vlax-make-variant 5)) #<variant 3 5>
By default, vlax-make-variant assigned the specified integer value to a Long Integer data type, not Integer, as you might expect. When assigning a numeric value to a variant, you should explicitly state the data type you want. If you do not specify a value or data type, vlax-make-variant allocates an uninitialized vlax-vbEmpty variant.