Working with Variants
 
 
 

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:

vlax-vbEmpty

Uninitialized (default value)

vlax-vbNull

Contains no valid data

vlax-vbInteger

Integer

vlax-vbLong

Long integer

vlax-vbSingle

Single-precision floating-point number

vlax-vbDouble

Double-precision floating-point number

vlax-vbString

String

vlax-vbObject

Object

vlax-vbBoolean

Boolean

vlax-vbArray

Array

The constants evaluate to integer values. Because the integer values can change, you should always refer to the constant, not the integer value. See the entry for vlax-make-variant in the AutoLISP Reference for the current integer value assigned to each constant.

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. Refer to vlax-make-variant in the AutoLISP Reference for a complete list of default type assignments.

If you do not specify a value or data type, vlax-make-variant allocates an uninitialized (vlax-vbEmpty) variant.