In AutoIt there is only one datatype called a Variant. A variant can contain numeric or string data and decides how to use the data depending on the situation it is being used in. For example, if you try and multiply two variants they will be treated as numbers, if you try and concatenate (join) two variants they will be treated as strings.
10 * 20 equals the number 200 (* is used to multiply two numbers)
10 * "20" equals the number 200
"10" * "20" equals the number 200
10 & 20 equals the string "1020" (& is used to join strings)
If a string is used as a number, an implicit call to Number() function is done. So if it doesn't contain a valid number, it will be assumed to equal 0. For example,
10 * "fgh" equals the number 0.
If a string is used as a boolean and it is an empty string "" , it will be assumed to equal False (see below). For example,
Not "" equals the Boolean True.
Numbers can be standard decimal numbers like 2, 4.566, and -7.
Scientific notation is also supported; therefore, you could write 1.5e3 instead of 1500.
Integers (whole numbers) can also be represented in hexadecimal notation by preceding the integer with 0x as in 0x409 or 0x4fff.
Strings are enclosed in double-quotes like "this". If you want a string to actually contain a double-quote use it twice like:
"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.
All AutoIt strings use UTF-16 (in fact and more precisely UCS-2) encoding.
Booleans are logical values. Only two Boolean values exist: True and False.
They can be used in variable assignments, together with the Boolean operators And, Or and Not.
$fBoolean1 = True
$fBoolean2 = False
$fBoolean3 = $fBoolean1 AND $fBoolean2
This will result in $fBoolean3 being False
$fBoolean1 = False
$fBoolean2 = Not $fBoolean1
This will result in $fBoolean2 being True
If Boolean values are used together with numbers, the following rules apply:
A value 0 will be equal to Boolean False
Any other number value will be equal to Boolean True
$iNumber1 = 0
$fBoolean1 = True
$fBoolean2 = $iNumber1 And $fBoolean1
This will result in $fBoolean2 being False
If you use arithmetics together with Boolean values (which is not advisable!), the following rules apply:
A Boolean True will be converted into the numeric value 1
A Boolean False will be converted into the numeric value 0
$fBoolean1 = True
$iNumber1 = 100
$iNumber2 = $fBoolean1 + $iNumber1
This will result in $iNumber2 to be the numeric value 101
If you use strings together with Boolean values, they will be converted as follows:
A Boolean True will be the string value "True"
A Boolean False will be the string value "False"
$sString1="Test is: "
$sString2=$sString1 & $fBoolean1
This will result in $sString2 being the string value "Test is: True"
The other way around however is different. When you use 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 type can store any byte value. they are converted in hexadecimal representation when stored in a string variable. Example:
$bin = Binary("abc")
$str = String($bin) ; "0x616263"
Pointer types store a memory address which is 32bits or 64bits depending on if the 32bit or 64 bit 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.
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.