Home >Common Problem >What data type is Variant?
What data type is Variant?
Variant is a special data type. This type has no type declaration characters. Its function is to dynamically change the type during runtime and supports all simple data types, such as integers and floats. Point, string, Boolean, date and time, currency and OLE automation objects, etc.
Variant Adaptability
You can replace any data type with the Variant data type, which will be more adaptable. If the content of the Variant variable is a number, it can be represented by a string representing the number or by its actual value, which will be determined by the context, for example:
Dim MyVar As Variant
MyVar = 98052
In the previous example, MyVar contains a value with an actual value of 98052. As expected, arithmetic operators can operate on Variant variables that contain numeric values or string data that can be interpreted as numeric values. If you use the operator to add MyVar to another Variant or numeric variable containing a number, the result is an arithmetic sum.
The Empty value is used to mark Variant variables that have not been initialized (given an initial value). A Variant containing Empty represents 0 in the context of a numeric value, or a zero-length string ("") if used in the context of a string.
Empty should not be confused with Null. Null means that the Variant variable does contain invalid data.
In Variant, Error is a special value used to indicate when an error occurs during the process. However, unlike other kinds of errors, the program does not perform ordinary application-level error handling. This allows the programmer, or the application itself, to take additional action based on the error value. Error values can be generated by converting real numbers to error values using the CVErr function.
Recommended tutorial: "PHP"
The above is the detailed content of What data type is Variant?. For more information, please follow other related articles on the PHP Chinese website!