Type

Returns the exact type of a value.

Type := Type(Value)

Return Value

Type: String

This function returns the type of Value. For primitive values, the return value is one of the following:

If Value is an object, the return value is the object's class name.

For the Object type, the class name is dynamic and is determined using an algorithm like the one below:

Object_Type(Value) {
    if ObjHasKey(Value, "__Class")  ; Ensures classes aren't reported as an instance of the base class.
        return "Class"
    while Value := Value.base
        if ObjHasKey(Value, "__Class")
            return Value.__Class
    return "Object"
}

However, unlike this function, the Type function does not cause the object's meta-functions to be called.

For COM wrapper objects, the return value depends on the wrapped variant type. It is determined as follows:

ComObject_Type(obj)
{
    if ComObjType(obj) & 0x2000 ; VT_ARRAY
        return "ComObjArray"
    if ComObjType(obj) & 0x4000 ; VT_BYREF
        return "ComObjRef"
    if (ComObjType(obj) = 9 || ComObjType(obj) = 13) ; VT_DISPATCH || VT_UNKNOWN
        && ComObjValue(obj) != 0
    {
        if (classname := ComObjType(obj, "Class")) != ""
            return classname
        if ComObjType(obj) = 9 ; VT_DISPATCH
            return "ComObject"
    }
    return "ComObj"
}

Remarks

This function typically shouldn't be used to determine if a value is numeric, since numeric strings are valid in math expressions and with most built-in functions. However, in some cases the exact type of a value is more important. For instance, if NumPut is passed a variable containing a pure integer (not a numeric string), the integer will be used instead of the address of the variable.

To check if a value can be used as a number, use the expression value is type, where type is "number", "integer" or "float".

To check for any type of object, use the expression value is 'object'.

To check if an object is derived from a particular user-defined class, use value is ClassName.

For built-in types, the object's class cannot be referenced directly.

Related

Values, Expressions, Value is Type, Integer, Float, String

Examples

a := 1, b := 2.0, c := "3"
MsgBox Type(a)  ; Integer
MsgBox Type(b)  ; Float
MsgBox Type(c)  ; String