Variant Class
A Variant is a special data type that can contain any type of data. Use the VarType function or the Variant's Type method to determine the data type of a variant.
More information available in parent classes: Object
Notes
The default value of a Variant is 0. When you assign a variant to a String, numeric, or Date variable, REALbasic converts the value of the variant to the variable's data type. For example,
If there is any ambiguity concerning the type conversion of a variant, you should use one of the properties of the Variant class to force the REALbasic compiler to convert the variant to the desired type. In this example, the Product number is supposed to be the string concatenation of the Model number and the Part Number. To do this, use the StringValue property to tell REALbasic to do what you want:
Model=100
Partnumber=546
Product=Model+Partnumber //product=646
Product=Model.StringValue+Partnumber.StringValue //product=100546
Or, you could just type the variables as String and do string concatenation directly.
The Type method returns the type of the variant, provided it is not Nil. For example, the following code generates an NilObjectException error
.
On the other hand, the following example returns 0.
Variants used in an expression convert themselves to the type of the other operand, no matter what kind of data they contain, instead of deferring the type-conversion until runtime. This only affects expressions involving a variant operand and an operand of some other type, not expressions in which both operands are variants.
Consider the following example:
The comparison:
returns False since v is being treated as an Integer. If you instead use:
the comparison returns True.
The comparison
also returns True.
See Also
IsNumeric, VarType functions; DatabaseField, Date, Dictionary classes; Boolean, Color, Double, Integer, Single, String data types; Dim stateme