# Language Reference - Datatypes

AutoIt uses a Variant implementation to represent variables and constants. Variables and constants can contain numeric or string data and AutoIt decides how to interpret the datatype depending on the situation, although you can force a particular datatype if required.

This means that if you use a mathematical operator on 2 variables they will be treated as numbers; if you concatenate (join) them they will be treated as strings. Note that the datatype of the result of the operation may not be the same as that of the original variables:

For example, using * to multiply two values returns a number

10 * 20 : results in the number 200
10 * "20" : results in the number 200
"10" * "20" : results in the number 200

Whereas using & to concatenate (join) two values returns a string

10 & 20 : results in the string "1020"

In each case an implicit call to the Number() or String() function is made to convert the value to the appropriate type, which may result in unexpected results. For instance, if a string value does not contain a valid number, it will be assumed to equal 0. For example,

10 * "fgh" : results in the number 0.

Beware of this automatic conversion as it can cause problems if you do not explicitly declare the exact datatype of the content of a variable. For example, values read from an .ini file are ALWAYS strings and so a simple comparison between them can lead to peculiar results as strings are compared alphabetically:

"11" will be considered less than "2"

rather then numerically

11 is considered greater than 2

You are advised to make use of the Number() and String() functions to force the contents of variables and constants into the same format before carrying out any comparisons between them.

Remember that VarGetType() can be used to ascertain the actual datatype of variables, literals and constants.

## Numbers

Supported types are signed integers and floating-point: Int32, Int64 and Double. Bitsize of an integer depends on its magnitude and is automatically adjusted.

Numbers can be standard decimal numbers: 2, 4.566, -7.

Scientific notation is also supported: i.e. 1.5e3 instead of 1500.

Integers (whole numbers) can also be represented in hexadecimal notation by preceding the integer with 0x: e.g. 0x409 or 0x4fff.

Enum is a keyword of the language but is not a datatype per se, since enumerated values directly map to integers.

## Strings

Native AutoIt string use the UCS2 character set (the first 64k codepoints of Unicode, also called the BMP). They are enclosed in double-quotes like "this".

$s = "abc"
$s = "déçu"
$s = "" ; An empty string

If you want a string to actually contain a double-quote use it twice:

"here is a ""double-quote"" - ok?"

You can also use single-quotes like 'this' and 'here is a ' 'single-quote' ' - ok?'

You can mix quote types to make for easier working and to avoid having to double-up your quotes to get what you want. For example if you want to use a lot of double-quotes in your strings then you should use single-quotes for declaring them:

'This "sentence" contains "lots" of "double-quotes" does it not?'

is much simpler than:

"This ""sentence"" contains ""lots"" of ""double-quotes"" does it not?"

When evaluated, strings can have Env variables or Var variables substitution according to Opt() function definition.

It is recommended to use UTF8 for source file encoding. See here for more details on how to convert strings to/from UCS2, UTF8, etc and how to deal with codepages.

Chr(0) characters inside strings are handled as any characters. Only StringIs...() functions stops checking if a Chr(0) is encountered inside the string. Internally the C function is used to speed up the processing. StringIsSpace() does not stop to be coherent with StringStripWS().

## Booleans

Booleans are logical values and only two exist: True and False. They can be assigned to variables and constants and used with the Boolean operators And, Or and Not.

Examples:

$bBoolean1 = True
$bBoolean2 = False
$bBoolean3 = $bBoolean1 And $bBoolean2 : results in $bBoolean3 = False

$bBoolean1 = False
$bBoolean2 = Not $bBoolean1 : results in $bBoolean2 = True

Strings and numbers can be used as Booleans. An empty string "" equals Boolean False as does the number 0. Any other number value will be equal to Boolean True

Example:

$iNumber1 = 0
$bBoolean1 = True
$bBoolean2 = $iNumber1 And $bBoolean1 : results in $bBoolean2 = False

It is strongly advised not to use Booleans in arithmetic expressions, but the following rules apply in this case:

A Boolean True will be converted into the numeric value 1
A Boolean False will be converted into the numeric value 0

Example:

$bBoolean1 = True
$iNumber1 = 100
$iNumber2 = $bBoolean1 + $iNumber1 : results in $iNumber2 = 101

Concatenating Booleans with strings converts the Boolean value into the appropriate string: "True" or "False":

Example:

$bBoolean1 = True
$sString1 = "Test is: "
$sString2 = $sString1 & $bBoolean1 : results in $sString2 = "Test is: True"

However, when using string comparisons with Boolean values, the following rules apply:

Only an empty string ("") will be a Boolean False.
Any other string values (including a string equal "0") will be a Boolean True.

## Binary

Binary type can store any byte value. they are converted in hexadecimal representation when stored in a string variable. Example:

$dBin = Binary("abc")
$sString = String($dBin) : results in $sString = "0x616263"

## Pointer

Pointer types store a memory address which is 32bits or 64bits depending on if the 32bit or 64-bit version of AutoIt is used. They are converted to hexadecimal representation when stored in a string variable. Window handles (HWnd) as returned from WinGetHandle() are a pointer type.

Variables created with DllStructCreate() can be used as pointer if a 'struct*' type in the DllCall() is used. A pointer defined by DllStructGetPtr() can be passed to such parameter with a 'struct*' type.

## DllStruct

This datatype is used for mapping AutoIt data to C/C++ structs for invoking functions in DLLs.

## Keyword

AutoIt uses 4 Keywords as datatypes

True Boolean True - e.g. 7 = 7
False Boolean False - e.g. 5 >= 14
Default Only used for assigning a default value to optional arguments of a function.
Null An unknown value. (Note this keyword is NOT part of a 3-valued logic as in other languages such as SQL).

## Object

Object refers to a "Component Object Model" as used by Microsoft. Creating an object allows you to use Autoit code to interact with it using the object's various properties and/or methods. See here for more discussion on using COM within AutoIt.

## Function and User Function

AutoIt has both native functions and user-defined functions - the former being part of the core AutoIt code while the later are written as AutoIt scripts either within an include library file or by you within your own script. Both types are first-class objects and can be assigned to a variable, or used as a parameter and/or return value from another function. See here for more details.

## Arrays and Maps

AutoIt has 2 types of data collection variables: Array and Maps.

Arrays are much faster for random access and can have multiple dimensions - a dimension size is fixed at the initially declared value (although it can be altered using ReDim()). Arrays are indexed using integer values referring to the order of elements and start at element[0] - elements can be extracted using the integer index or iterated by a simple For...Next loop.

Maps are better for records/dictionary type access and have a single dimension. They are indexed using either integer or string keys (integers do not refer to the order of elements) and are dynamically resized as values are added or removed. A value can only be accessed by using the original key - these keys can be iterated using the MapKeys() function.

See here for more details.

## Datatypes and Ranges

The following table shows the internal variant datatypes and their ranges.

Data Sub-type | Range and Notes
--- | ---
Int32 | A 32bit signed integer number.
Int64 | A 64bit signed integer number
Double | A double-precision floating point number.
String | Can contain strings of up to 2147483647 characters.
Binary | Binary data, can contain up to 2147483647 bytes.
Pointer | A memory address pointer. 32bit or 64bit depending on the version of AutoIt used.

Some functions in AutoIt only work with 32-bit numbers (e.g. BitAND() ) and are converted automatically - these functions are documented where required.