Creates a variant data type
(vlax-make-variant [value] [type])
- value
- type
-
The type of variant. This can be represented by one of the following constants:
vlax-vbEmpty (0) Uninitialized (default value)
vlax-vbNull (1) Contains no valid data
vlax-vbSingle (4) Single-precision floating-point number
vlax-vbDouble (5) Double-precision floating-point number
The integer shown in parentheses indicates the value to which the constant evaluates. It is recommended that you specify the constant in your argument, not the integer value, because the value may change in later releases of AutoCAD.
If you do not specify a type, vlax-make-variant assigns a default data type based on the data type of the value it receives. The following list identifies the default variant data type assigned to each LISP data type:
:vlax-true, :vlax-false vlax-vbBoolean
Create a variant using the defaults for vlax-make-variant:
_$ (setq varnil (vlax-make-variant))
#<variant 0 >
The function creates an uninitialized (vlax-vbEmpty) variant by default. You can accomplish the same thing explicitly with the following call:
_$ (setq varnil (vlax-make-variant nil))
#<variant 0 >
Create an integer variant and set its value to 5:
_$ (setq varint (vlax-make-variant 5 vlax-vbInteger))
#<variant 2 5>
Repeat the previous command, but omit the type argument and see what happens:
_$ (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. This highlights the importance of explicitly stating the type of variant you want when working with numbers.
Omitting the type argument for a string produces predictable results:
_$ (setq varstr (vlax-make-variant "ghost"))
#<variant 8 ghost>
To create a variant containing arrays, you must specify type vlax-vbArray, along with the type of data in the array. For example, to create a variant containing an array of doubles, first set a variable's value to an array of doubles:
_$ (setq 4dubs (vlax-make-safearray vlax-vbDouble '(0 . 3)))
#<safearray...>
Then take the array of doubles and assign it to a variant:
_$ (vlax-make-variant 4dubs)
#<variant 8197 ...>
-
The vlax-make-safearray, vlax-variant-change-type, vlax-variant-type, and vlax-variant-value functions. For more information on using variants, see
Working with Variants in the AutoLISP Developer's Guide.