Tricks
This page is intended to list simple but useful tricks.
Show Error Message and Exit in one line
The following line shows an error message and exits the script with an error code of 99 if $x is bigger than 5:
If $x > 5 Then Exit 99 + 0*MsgBox(0, 'Error', '$x is bigger than 5!')
The trick works as follows: When $x is bigger than 5, the statement after the "Then" is executed. This statement consists of a calculation. While parsing this calculation, AutoIt notes that it has to execute the MsgBox() function to be able to fill in all values into the calculation. However, since the value can change depending on which button is used to close the box, we need to eliminate the return code from our calculation. That's why the return value of the MsgBox() function is multiplied by 0. Since we don't want 0 to be the error code we'll just add 99 to it. Now AutoIt is able to execute the Exit command so the script exits at this point.
Save a variable to a file
A variable's value can be saved to a file for later use. For example if you have a variable called $Data and you wanted to save it for later just use IniWrite.
IniWrite("Variables.ini","Main","Data",$Data)
To get it back later just do.
$Data = IniRead("Variables.ini","Main","Data","")
You can even get it back after the script has exited and restarted.
AutoIt configuration
Has it's own page called Tricks Autoit Configuration