Method

# VarType

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Used to determine the data type of a variable.

## Usage

``` xojo
result = VarType(value)
```

| Part   | Type                               | Description                         |
|--------|------------------------------------|-------------------------------------|
| result | `Integer</api/data_types/integer>` | Indicates the data type of *value*. |
| value  | `Variant</api/data_types/variant>` | Value to be typed.                  |

## Notes

Result takes on the following values:

| Result                                       | Variant Class Constant | Description                                                                                                                                                   |
|----------------------------------------------|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 0                                            | TypeNil                | `Nil</api/language/nil>`                                                                                                                                      |
| 2                                            | TypeInt32              | `Integer</api/data_types/integer>` types of 32 bits or less, signed or unsigned. This is equivalent to TypeInteger. To detect 64-bit integers, use TypeInt64. |
| 3                                            | TypeInt64              | `Int64</api/data_types/additional_types/int64>` or `UInt64</api/data_types/additional_types/uint64>`. This is the replacement for TypeLong.                   |
| 4                                            | TypeSingle             | `Single</api/data_types/single>`                                                                                                                              |
| 5                                            | TypeDouble             | `Double</api/data_types/double>`                                                                                                                              |
| 6                                            | TypeCurrency           | `Currency</api/data_types/currency>`                                                                                                                          |
| 8                                            | TypeString             | `String</api/data_types/string>`                                                                                                                              |
| 9                                            | TypeObject             | `Object</api/data_types/additional_types/object>`                                                                                                             |
| 11                                           | TypeBoolean            | `Boolean</api/data_types/boolean>`                                                                                                                            |
| 16                                           | TypeColor              | `Color</api/data_types/color>`                                                                                                                                |
| 18                                           | TypeCString            | `CString</api/data_types/additional_types/cstring>`                                                                                                           |
| 19                                           | TypeWString            | `WString</api/data_types/additional_types/wstring>`                                                                                                           |
| 20                                           | TypePString            | `PString</api/data_types/additional_types/pstring>`                                                                                                           |
| 21                                           | TypeCFStringRef        | `CFStringRef</api/data_types/additional_types/cfstringref>`                                                                                                   |
| 22                                           | TypeWindowPtr          | `DesktopWindow.Handle<desktopwindow.handle>`                                                                                                                  |
| 23                                           | TypeOSType             | `OSType</api/data_types/additional_types/ostype>`                                                                                                             |
| 26                                           | TypePtr                | `Ptr</api/data_types/additional_types/ptr>`                                                                                                                   |
| 36                                           | TypeStructure          | `Structure</api/language/structure>`                                                                                                                          |
| 38                                           | TypeDateTime           | `DateTime</api/data_types/datetime>`                                                                                                                          |
| 39                                           | TypeDelegate           | `Integer</api/data_types/integer>`                                                                                                                            |
| 4096, logically OR'ed with the element type. | TypeArray              | `Array</api/language/arrays>`                                                                                                                                 |

In the case of an array, the result is 4096 logically OR'ed with the array element type. You can get the element type by calling `Variant</api/data_types/variant>`.ArrayElementType. See the example for getting the <span class="title-ref">VarType</span> of an `Integer</api/data_types/integer>` array.

## Sample code

The following line of code returns 8 (data type of `String</api/data_types/string>`):

``` xojo
Var dataType As Integer = VarType("Herman")
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following returns 4098 (data type of an array (4096) logically OR'ed with the <span class="title-ref">VarType</span> of the element type of Int32 (2)).

``` xojo
Var a(2) As Int32 = Array(0, 1, 2)
Var dataType As Integer = VarType(a) ' 4098
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`Variant</api/data_types/variant>` class, `Boolean</api/data_types/boolean>`, `CFStringRef</api/data_types/additional_types/cfstringref>`, `Color</api/data_types/color>`, `Currency</api/data_types/currency>`, `CString</api/data_types/additional_types/cstring>`, `Delegate</api/data_types/additional_types/delegate>`, `Double</api/data_types/double>`, `Int8</api/data_types/additional_types/int8>`, `Int16</api/data_types/additional_types/int16>`, `Int32</api/data_types/additional_types/int32>`, `Int64</api/data_types/additional_types/int64>`, `Integer</api/data_types/integer>`, `OSType</api/data_types/additional_types/ostype>`, `PString</api/data_types/additional_types/pstring>`, `Ptr</api/data_types/additional_types/ptr>`, `Single</api/data_types/single>`, `String</api/data_types/string>`, `Structure</api/language/structure>`, `UInt8</api/data_types/additional_types/uint8>`, `Uint16</api/data_types/additional_types/uint16>`, `UInt32</api/data_types/additional_types/uint32>`, `UInt64</api/data_types/additional_types/uint64>`, `DesktopWindow.Handle<desktopwindow.handle>`, `WString</api/data_types/additional_types/wstring>` data types; `IsNumeric</api/language/isnumeric>`, `Nil</api/language/nil>` functions.

</div>
