<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.autoitscript.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=BrewManNH</id>
	<title>AutoIt Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.autoitscript.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=BrewManNH"/>
	<link rel="alternate" type="text/html" href="https://www.autoitscript.com/wiki/Special:Contributions/BrewManNH"/>
	<updated>2026-04-13T00:24:11Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Decompiling_FAQ&amp;diff=13651</id>
		<title>Decompiling FAQ</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Decompiling_FAQ&amp;diff=13651"/>
		<updated>2017-06-26T09:59:25Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Is there a 3rd-party decompiler? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Below are frequently asked questions about decompiling AutoIt scripts.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Is there a decompiler available? ==&lt;br /&gt;
Yes, sort of.  The official decompiler will only decompile scripts compiled with AutoIt v3.2.5.1 and earlier.  Any script compiled with a version later than that will not decompile.&lt;br /&gt;
&lt;br /&gt;
== Where can I find the decompiler? ==&lt;br /&gt;
If the version of AutoIt is v3.2.5.1 or lower, then the decompiler is located at &#039;&#039;C:\Program Files\AutoIt3\Extras\Exe2Aut\Exe2Aut.exe&#039;&#039; by default.  The directory may be different if you performed a custom installation. For all other newer versions, the decompiler has been removed.&lt;br /&gt;
&lt;br /&gt;
== What if I need to decompile a script compiled with a newer version of AutoIt? ==&lt;br /&gt;
You are mostly out of luck.  Take the opportunity to learn how to properly back up your important files.  The developers can decompile scripts but you must be prepared to prove you own the script.  This is not done very often and the developers reserve the right to say no for any reason.&lt;br /&gt;
&lt;br /&gt;
== Is there a 3rd-party decompiler? ==&lt;br /&gt;
Yes.  There is software in existence which can decompile all versions of AutoIt.  Creation or &#039;&#039;&#039;use&#039;&#039;&#039; of such software may be a violation of the law depending on your local laws.  &#039;&#039;&#039;DO NOT USE IT.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== What happens if I use the 3rd-party decompiler? ==&lt;br /&gt;
If you mention you have used a 3rd-party decompiler you will be permanently blocked from the forum and issue tracker.  You may be blocked for any of the following:&lt;br /&gt;
 * Admitting you have decompiled your own script with a 3rd-party decompiler.&lt;br /&gt;
 * Admitting you have decompiled another user&#039;s script with a 3rd-party decompiler.&lt;br /&gt;
 * Posting any script that has been decompiled by a 3rd-party decompiler.&lt;br /&gt;
This includes decompiling scripts users have posted in binary-only form.  Under no circumstances are scripts to be decompiled unless the author grants their explicit permission and the script can be decompiled with the official decompiler.&lt;br /&gt;
 &lt;br /&gt;
== Are my compiled scripts safe? ==&lt;br /&gt;
No.  Any unscrupulous user may decompile your compiled script.  There is not much you can do to stop decompilation.  A determined user will get your source code if they truly want it.&lt;br /&gt;
&lt;br /&gt;
== I designed a counter-measure to break the 3rd-party decompiler, may I share it? ==&lt;br /&gt;
No.  It is theoretically possible to modify compiled scripts in a way that it still works but a decompiler fails to extract the source.  However, tools that are capable of doing this violate the reverse engineering clause of the AutoIt license (the very same clause the 3rd-party decompiler violates).&lt;br /&gt;
&lt;br /&gt;
== Where in the AutoIt license does it mention decompilation? ==&lt;br /&gt;
This clause:&lt;br /&gt;
:Reverse engineering. You may not reverse engineer or disassemble the SOFTWARE PRODUCT or compiled scripts that were created with the SOFTWARE PRODUCT.&lt;br /&gt;
That clause covers both reverse engineering how AutoIt works (in order to create a working decompiler or a counter-measure to decompiling) as well as decompilation of compiled scripts.&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Decompiling_FAQ&amp;diff=13650</id>
		<title>Decompiling FAQ</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Decompiling_FAQ&amp;diff=13650"/>
		<updated>2017-06-26T09:56:13Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Where can I find the decompiler? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Below are frequently asked questions about decompiling AutoIt scripts.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Is there a decompiler available? ==&lt;br /&gt;
Yes, sort of.  The official decompiler will only decompile scripts compiled with AutoIt v3.2.5.1 and earlier.  Any script compiled with a version later than that will not decompile.&lt;br /&gt;
&lt;br /&gt;
== Where can I find the decompiler? ==&lt;br /&gt;
If the version of AutoIt is v3.2.5.1 or lower, then the decompiler is located at &#039;&#039;C:\Program Files\AutoIt3\Extras\Exe2Aut\Exe2Aut.exe&#039;&#039; by default.  The directory may be different if you performed a custom installation. For all other newer versions, the decompiler has been removed.&lt;br /&gt;
&lt;br /&gt;
== What if I need to decompile a script compiled with a newer version of AutoIt? ==&lt;br /&gt;
You are mostly out of luck.  Take the opportunity to learn how to properly back up your important files.  The developers can decompile scripts but you must be prepared to prove you own the script.  This is not done very often and the developers reserve the right to say no for any reason.&lt;br /&gt;
&lt;br /&gt;
== Is there a 3rd-party decompiler? ==&lt;br /&gt;
Yes.  There is software in existence which can decompile all versions of AutoIt.  This software is in direct violation of the AutoIt license agreement.  Creation or &#039;&#039;&#039;use&#039;&#039;&#039; of such software may be a violation of the law depending on your local laws.  &#039;&#039;&#039;DO NOT USE IT.&lt;br /&gt;
&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== What happens if I use the 3rd-party decompiler? ==&lt;br /&gt;
If you mention you have used a 3rd-party decompiler you will be permanently blocked from the forum and issue tracker.  You may be blocked for any of the following:&lt;br /&gt;
 * Admitting you have decompiled your own script with a 3rd-party decompiler.&lt;br /&gt;
 * Admitting you have decompiled another user&#039;s script with a 3rd-party decompiler.&lt;br /&gt;
 * Posting any script that has been decompiled by a 3rd-party decompiler.&lt;br /&gt;
This includes decompiling scripts users have posted in binary-only form.  Under no circumstances are scripts to be decompiled unless the author grants their explicit permission and the script can be decompiled with the official decompiler.&lt;br /&gt;
 &lt;br /&gt;
== Are my compiled scripts safe? ==&lt;br /&gt;
No.  Any unscrupulous user may decompile your compiled script.  There is not much you can do to stop decompilation.  A determined user will get your source code if they truly want it.&lt;br /&gt;
&lt;br /&gt;
== I designed a counter-measure to break the 3rd-party decompiler, may I share it? ==&lt;br /&gt;
No.  It is theoretically possible to modify compiled scripts in a way that it still works but a decompiler fails to extract the source.  However, tools that are capable of doing this violate the reverse engineering clause of the AutoIt license (the very same clause the 3rd-party decompiler violates).&lt;br /&gt;
&lt;br /&gt;
== Where in the AutoIt license does it mention decompilation? ==&lt;br /&gt;
This clause:&lt;br /&gt;
:Reverse engineering. You may not reverse engineer or disassemble the SOFTWARE PRODUCT or compiled scripts that were created with the SOFTWARE PRODUCT.&lt;br /&gt;
That clause covers both reverse engineering how AutoIt works (in order to create a working decompiler or a counter-measure to decompiling) as well as decompilation of compiled scripts.&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13505</id>
		<title>Best coding practices</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13505"/>
		<updated>2016-07-20T20:27:30Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Include-once directive */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what are to be considered the best coding practices within AutoIt. These recommendations are based on accepted coding practices common to a number of other programming languages. You do not need to follow them, but it is recommended that you do.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: You must use AutoIt v3.3.10.0 or above to run the examples below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Using Functions ==&lt;br /&gt;
If a function sets the @error flag, you should always check it before using a return value - if @error indicates an error then the function return value is generally undefined.&lt;br /&gt;
&lt;br /&gt;
Learn more about using Functions by reading &amp;quot;[https://www.autoitscript.com/autoit3/docs/function_notes.htm Function Notes]&amp;quot; from HelpFile.&lt;br /&gt;
&lt;br /&gt;
== Names of Variables ==&lt;br /&gt;
The variable naming convention used in AutoIt is based on [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation]. The prefix defines the logical data type rather than the physical data type: in this way, it gives a hint as to what the variable&#039;s purpose is, or what it represents. The prefix does not encode the actual data type: this occurs during assignment. See the table below for accepted standards.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! example&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $bBool = True&lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $dBinary = Binary(&amp;quot;0x80000000&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452 &lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $hGUI = GUICreate(&amp;quot;My GUI&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlID || $idButton_Ok = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;Hello world&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|v || Variant || $vData = ClipGet()&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! dollar prefix !! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| $ || a || h || Handles&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a local variable the integer 7&lt;br /&gt;
Local $iWeekDays = 7&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable the value of Pi&lt;br /&gt;
Local $fPi = 3.14159265358979&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable an array of strings&lt;br /&gt;
Local $asArray[7] = [&#039;mon&#039;, &#039;tue&#039;, &#039;wed&#039;, &#039;thu&#039;, &#039;fri&#039;, &#039;sat&#039;, &#039;sun&#039;]&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable an array of numbers&lt;br /&gt;
Local $anArray[4] = [0, 0.25, 3 / 4, 12]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variable Initialization ==&lt;br /&gt;
When initializing variables there are several points to consider. It is bad practice to hog memory by assigning data which is not immediately required. It is therefore recommended that you declare and initialize variables immediately prior to use. If you wish to assign a default value to a variable which you intend to overwrite later, then the data should be of the same (or the most logical representation of its) type and use as little memory as possible.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Inconsistent data types are considered bad&lt;br /&gt;
Local $iInteger = &amp;quot;0&amp;quot;&lt;br /&gt;
Local $sString = False&lt;br /&gt;
&lt;br /&gt;
; Correct initialization&lt;br /&gt;
Local $iInteger = 0&lt;br /&gt;
Local $sString = &#039;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the following table, recommended default values are shown for each data type. Some data types have more than one possibile default value which can be used for initialization.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Default Value !! covering type&lt;br /&gt;
|-&lt;br /&gt;
| Binary(&amp;quot;&amp;quot;) || $d&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot; || $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| 0 || $a, $h, $i, $id, $m, $n, $o, $p, $t, $tag, $v&lt;br /&gt;
|-&lt;br /&gt;
| 0.0 || $f&lt;br /&gt;
|-&lt;br /&gt;
| Null || $o, $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| False (or True) || $b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Declare and initialize a variable with the recommended default value&lt;br /&gt;
Local $vUndefined = Null ; This does not require much memory&lt;br /&gt;
&lt;br /&gt;
; Some time later:&lt;br /&gt;
$vUndefined = 0xB0AD1CEA ; Assign an appropriate value as and when needed&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To reduce bloat, multiple variables can be declared on a single line. When declaring multiple variables on the same line, it is generally recommended that you stick to declaring one data type on each line. The intention here is to make the code easier to follow and manage in a future, however the best layout will vary according to circumstance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Not recommended&lt;br /&gt;
Local $sString = &amp;quot;&amp;quot;, $iInteger = 0, $asArray = [&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;] ; Mixed data types&lt;br /&gt;
&lt;br /&gt;
; Recommended&lt;br /&gt;
Local $iLeft = 10, $iTop = 10 ; Integers&lt;br /&gt;
Local $idButton_Go = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop) ; ControlIds&lt;br /&gt;
Local $idButton_Quit = GUICtrlCreateButton(&amp;quot;Quit&amp;quot;, 50, 10) ; ControlIds&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some languages it is essential to initialize variables on declaration, but this is not the case with AutoIt. Regarding data type, variables declared without being initialized should be considered as being undefined.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
Variables should also be named according to their scope.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Global UDF variable !! Global variable !! Local variable&lt;br /&gt;
|-&lt;br /&gt;
| $__g_iSomeVar || $g_iSomeVar || $iSomeVar&lt;br /&gt;
|}&lt;br /&gt;
With this method, you will avoid unwanted re-assignments.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Assign a Global variable the number 0&lt;br /&gt;
Global $iSomeVar1 = 0&lt;br /&gt;
; Assign a Global variable the number 5&lt;br /&gt;
Global $g_iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
SomeFunc()&lt;br /&gt;
&lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; Assign Local variables respectively the numbers 3 and 4&lt;br /&gt;
    Local $iSomeVar1 = 3, $iSomeVar2 = 4&lt;br /&gt;
&lt;br /&gt;
    ; Note: The user inadvertently re-assigned the global variable $iSomeVar1, because this one is not named as &amp;quot;global&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $iSomeVar1&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $iSomeVar1: &amp;quot; &amp;amp; $iSomeVar1)&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $iSomeVar2&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $iSomeVar2: &amp;quot; &amp;amp; $iSomeVar2)&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $g_iSomeVar2&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $g_iSomeVar2: &amp;quot; &amp;amp; $g_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&amp;lt;br /&amp;gt;Always declare your global variables in the global scope, not in a function. It will prevent another function from using it before its declaration and the declaration is implicit (see [[#jumpsec1|examples]]).&lt;br /&gt;
&lt;br /&gt;
* A variable declared locally (with the Local keyword), has a visibility which depends of the scope where it&#039;s declared.&lt;br /&gt;
:Declaration in the global scope: the variable is visible everywhere; declare it as Local if this one is only to be used in the same scope, i.e. outside of any functions. A variable declared as Local in the Global scope is still a Global variable, it&#039;s only for the sake of code clarity that you&#039;d use the Local declaration in the Global scope.&lt;br /&gt;
:Declaration in a function: the variable is visible by the function itself and nowhere else.&lt;br /&gt;
&lt;br /&gt;
Structure of a code scope:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Global scope&lt;br /&gt;
&lt;br /&gt;
; Include the Constants file, it contains various constants; it&#039;s needed here for the $MB_SYSTEMMODAL flag of the MsgBox function)&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; This scope is either Global or Local, depending on where you use the variables&lt;br /&gt;
&lt;br /&gt;
; Assign a Global variable the number 0 (which corresponds to an initialization of a variable number), its scope is Global because it&#039;s used in at least one function&lt;br /&gt;
Global $g_iVar1 = 0&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the string &amp;quot;foo&amp;quot;, its scope is Local because it&#039;s use is used only in this scope&lt;br /&gt;
Local $sVar2 = &amp;quot;foo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; Display the content of $sVar2&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar2: &amp;quot; &amp;amp; $sVar2)&lt;br /&gt;
&lt;br /&gt;
; Re-assign a Local variable the string returned by the function MyFunc&lt;br /&gt;
$sVar2 = MyFunc()&lt;br /&gt;
&lt;br /&gt;
; Re-Display the content of $sVar2&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar2: &amp;quot; &amp;amp; $sVar2)&lt;br /&gt;
&lt;br /&gt;
; Declare a function (its main utility is described later in Functions, we can see one here which is to create a Local scope)&lt;br /&gt;
Func MyFunc()&lt;br /&gt;
    ; Local scope&lt;br /&gt;
&lt;br /&gt;
    ; Display the content of $g_iVar1&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $g_iVar1: &amp;quot; &amp;amp; $g_iVar1)&lt;br /&gt;
&lt;br /&gt;
    ; Assign a Local variable the string &amp;quot;bar&amp;quot;, its scope is Local because it&#039;s use is restricted to the function&#039;s scope&lt;br /&gt;
    Local $sVar3 = &amp;quot;bar&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Display the content of $sVar3&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar3: &amp;quot; &amp;amp; $sVar3)&lt;br /&gt;
&lt;br /&gt;
    ; Return the $sVar3 content, it will be visible (if used) to the scope where the function is called&lt;br /&gt;
    Return $sVar3&lt;br /&gt;
EndFunc   ;==&amp;gt;MyFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Concerning the Dim keyword, its recommended usage is limited to empty an existing array (Example 1) or to redeclare a function parameter (Example 2).&lt;br /&gt;
&lt;br /&gt;
Example 1:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Include the Array UDF, it&#039;s needed here for the _ArrayDisplay function&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
; Assign a Local variable an array containing numbers with a size of 5&lt;br /&gt;
; Note than an array is 0 based, to access the first element the code is: $aiArray[0]&lt;br /&gt;
Local $aiArray[5] = [1, 2, 3, 4, 5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aiArray)&lt;br /&gt;
 &lt;br /&gt;
; Empty the array (and keep its size)&lt;br /&gt;
Dim $aiArray[5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aiArray)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Remark: The variable type of an emptied array is a string, every non initialized variable is a string.&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Call MyFunc with default parameters ($vParam1 = 0)&lt;br /&gt;
MyFunc()&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array containing integers&lt;br /&gt;
Local $aiArray[3] = [3, 4, 5]&lt;br /&gt;
; Call MyFunc with $aiArray as parameter ($vParam1 = $aiArray)&lt;br /&gt;
MyFunc($aiArray)&lt;br /&gt;
&lt;br /&gt;
Func MyFunc($vParam1 = 0)&lt;br /&gt;
    ; If $vParam1 is NOT an array then redeclare it to an array&lt;br /&gt;
    If Not IsArray($vParam1) Then&lt;br /&gt;
        Dim $vParam1[3] = [0, 1, 2]&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    ; Display the array&lt;br /&gt;
    _ArrayDisplay($vParam1)&lt;br /&gt;
EndFunc   ;==&amp;gt;MyFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the ReDim keyword, limit its use to resize an array when you want to keep its content:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Include the Array UDF, it&#039;s needed here for the _ArrayDisplay function&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
; Assign a Local variable an array containing numbers with a size of 5&lt;br /&gt;
; Note than an array is 0 based, to access the first element the code is: $aiArray[0]&lt;br /&gt;
Local $aArray[5] = [1, 2, 3, 4, 5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
 &lt;br /&gt;
; Resize the array (and keep its content)&lt;br /&gt;
ReDim $aArray[3]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why using Dim over Local/Global is not always a good option:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Dim $g_vVariableThatIsGlobal = &amp;quot;This is a variable that has &amp;quot;&amp;quot;Program Scope&amp;quot;&amp;quot; aka Global.&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;An example of why Dim can cause more problems than solve them.&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
Example()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, $g_vVariableThatIsGlobal) ; That looks alright to me as it displays the following text: This is a variable that has &amp;quot;Program Scope&amp;quot; aka Global&lt;br /&gt;
 &lt;br /&gt;
    Local $vReturn = SomeFunc() ; Call some random function&lt;br /&gt;
 &lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, $vReturn, $g_vVariableThatIsGlobal) ; The Global variable ($g_vVariableThatIsGlobal) changed because I totally forgot I had a duplicate variable name in &amp;quot;SomeFunc&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; This should create a variable in Local scope if the variable name doesn&amp;quot;t already exist&lt;br /&gt;
    ; For argument sake I totally forgot that I declared a variable already with the same name&lt;br /&gt;
    ; Well I only want this to be changed in the function and not the variable at the top of the script&lt;br /&gt;
    ; Should be OK right? Think again&lt;br /&gt;
    Dim $g_vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
    For $i = 1 To 10&lt;br /&gt;
        $g_vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $g_vVariableThatIsGlobal&lt;br /&gt;
    Next&lt;br /&gt;
    Return $g_vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;jumpsec1&amp;quot;&amp;gt;Declaring Global variables in a Function is never a good idea:&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling Example() first will initialise the Global variable $g_vVariableThatIsGlobal and therefore calling SomeFunc() won&#039;t return an error&lt;br /&gt;
; Now look at Example 2&lt;br /&gt;
Example()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script&lt;br /&gt;
    Global $g_vVariableThatIsGlobal = &#039;This is a variable that has &#039;&#039;File Scope&#039;&#039; aka Global.&#039;&lt;br /&gt;
    SomeFunc()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $g_vVariableThatIsGlobal) ; As the variable was initialised this will not return an error&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling SomeFunc() first will bypass the Global variable $g_vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $g_vVariableThatIsGlobal contains&lt;br /&gt;
SomeFunc()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script&lt;br /&gt;
    Global $g_vVariableThatIsGlobal = &#039;This is a variable that has &#039;&#039;File Scope&#039;&#039; aka Global.&#039;&lt;br /&gt;
    SomeFunc()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $g_vVariableThatIsGlobal) ; As the variable wasn&#039;t initialised this will return an error of &amp;quot;variable used without being declared.&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declaring variables in loops (For, While, Do etc..) can have an affect on efficiency:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables inside loops should be avoided as the variable is re-declared on each repetition&lt;br /&gt;
For $i = 1 To 10 ; $i is in &#039;loop scope.&#039;&lt;br /&gt;
    Local $iInt = $i&lt;br /&gt;
Next&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $iInt) ; This will display 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables outside of loops is more efficient in the long run&lt;br /&gt;
Local $iInt = 0&lt;br /&gt;
For $i = 1 To 10 ; $i is in &#039;loop scope.&#039;&lt;br /&gt;
    $iInt = $i&lt;br /&gt;
Next&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $iInt) ; This will display 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no requirement to declare the iteration count variable in a loop:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Correct&lt;br /&gt;
Local Const $iCount = 99&lt;br /&gt;
Local $aArray[$iCount]&lt;br /&gt;
For $i = 0 To UBound($iCount) - 1 ; $i is only used in the loop, so there is no requirement to declare it&lt;br /&gt;
    $aArray[$i] = $i&lt;br /&gt;
Next&lt;br /&gt;
&lt;br /&gt;
; Incorrect&lt;br /&gt;
Local Const $iCount = 99&lt;br /&gt;
Local $aArray[$iCount]&lt;br /&gt;
Local $i ; This is only used to store the iteration count value in the loop and therefore doesn&#039;t need to be declared. &lt;br /&gt;
For $i = 0 To UBound($iCount) - 1&lt;br /&gt;
    $aArray[$i] = $i&lt;br /&gt;
Next&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
As you can see, there is the Const keyword in the example, we are going to talk about it.&lt;br /&gt;
&lt;br /&gt;
== Const, Static, Enum ==&lt;br /&gt;
&lt;br /&gt;
=== Const ===&lt;br /&gt;
We won&#039;t talk about the advantages of using a constant variable, they are neglibible (for your information, an AutoIt constant variable is marked as read-only and remains a read-only variable when compiled).&lt;br /&gt;
&lt;br /&gt;
The Const keyword may be used first by some of you to avoid re-assignments.&lt;br /&gt;
The best way to use them is for real static values, meaning that these values won&#039;t change regardless of the instance of the program.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Not recommended&lt;br /&gt;
Local Const $hGUI = GUICreate(&amp;quot;MyGUI&amp;quot;)&lt;br /&gt;
; The handle of the window is unique, it&#039;s generated by Windows and changes&lt;br /&gt;
&lt;br /&gt;
; Recommended&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Static ===&lt;br /&gt;
Static variables are the solution to global variables being used in only one function.&lt;br /&gt;
e.g: Retain variable data once returned from a Function and only use that variable in that particular Function.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 1&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 2&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 3&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; This initialises a Static variable in Local scope. When a variable is declared just in Local scope (within a Function,)&lt;br /&gt;
    ; it&#039;s destroyed when the Function ends/returns. This isn&#039;t the case for a Static variable. Also, the variable can&#039;t be&lt;br /&gt;
    ; accessed from anywhere else in the script apart from the Function it was declared in&lt;br /&gt;
    Local Static $vVariableThatIsStatic = 0&lt;br /&gt;
    Local $vVariableThatIsLocal = 0&lt;br /&gt;
    $vVariableThatIsLocal += 1 ; This will always be 1 as it is destroyed once returned from SomeFunc&lt;br /&gt;
    $vVariableThatIsStatic += 1 ; This will increase by 1&lt;br /&gt;
    MsgBox(4096, $vVariableThatIsLocal, $vVariableThatIsStatic)&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enum ===&lt;br /&gt;
This statement is often practical in certain situations:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Create variables in Local scope and enumerate through the variables. Default is to start from 0&lt;br /&gt;
    Local Enum $eCat, $eDog, $eMouse, $eHamster ; $eHamster is equal to the value 3, not 4&lt;br /&gt;
&lt;br /&gt;
    ; Create an array in Local scope with 4 elements&lt;br /&gt;
    Local $aAnimalNames[4]&lt;br /&gt;
&lt;br /&gt;
    ; Assign each array element with the name of the respective animal. For example the name of the cat is Jasper&lt;br /&gt;
    $aAnimalNames[$eCat] = &#039;Jasper&#039; ; $eCat is equal to 0, similar to using $aAnimalNames[0]&lt;br /&gt;
    $aAnimalNames[$eDog] = &#039;Beethoven&#039; ; $eDog is equal to 1, similar to using $aAnimalNames[1]&lt;br /&gt;
    $aAnimalNames[$eMouse] = &#039;Pinky&#039; ; $eMouse is equal to 2, similar to using $aAnimalNames[2]&lt;br /&gt;
    $aAnimalNames[$eHamster] = &#039;Fidget&#039; ; $eHamster is equal to 3, similar to using $aAnimalNames[3]&lt;br /&gt;
&lt;br /&gt;
    ; Display the values of the array&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$aAnimalNames[$eCat] = &#039; &amp;amp; $aAnimalNames[$eCat] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eDog] = &#039; &amp;amp; $aAnimalNames[$eDog] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eMouse] = &#039; &amp;amp; $aAnimalNames[$eMouse] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eHamster] = &#039; &amp;amp; $aAnimalNames[$eHamster] &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Sometimes using this approach for accessing an element is more practical than using a numerical value, due to the fact changing the index value of&lt;br /&gt;
    ; the enum constant has no affect on it&#039;s position in the array. Therefore changing the location of $eCat in the array is as simple as changing the order&lt;br /&gt;
    ; it appears in the initial declaration e.g&lt;br /&gt;
&lt;br /&gt;
    ; Local Enum $eDog, $eMouse, $eCat, $eHamster&lt;br /&gt;
&lt;br /&gt;
    ; Now $eCat is the 2nd element in the array. If you were using numerical values, you would have to manually change all references of $aAnimalNames[0] to&lt;br /&gt;
    ; $aAnimalNames[2], as well as for the other elements which have now shifted&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Au3Check directive ==&lt;br /&gt;
As you may know (and we hope), the Au3Check tool checks your code for syntax errors, variables used without being declared etc. which is a good thing to fix your script.&lt;br /&gt;
&lt;br /&gt;
With the official custom directive used to check the helpfile examples/includes, you can apply the good coding practices listed above:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Note: this directive is only used if you&#039;ve installed the full version of [https://www.autoitscript.com/cgi-bin/getfile.pl?../autoit3/scite/download/SciTE4AutoIt3.exe Scite4AutoIt3]&lt;br /&gt;
&lt;br /&gt;
== Magic Numbers ==&lt;br /&gt;
Magic numbers are arbitrary numbers interspersed throughout a program&#039;s source code which do not have an associated identifier. The downside to this is not being able to derive a meaning from the number. &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox(262144, &amp;quot;Magic Numbers&amp;quot;, &amp;quot;It&#039;s Adventure Time!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In this example, the magic number is 262144 with the identifier being $MB_TOPMOST according to the helpfile.&lt;br /&gt;
&lt;br /&gt;
The corrected example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox($MB_TOPMOST, &amp;quot;Magic Numbers&amp;quot;, &amp;quot;It&#039;s Adventure Time!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Imagine you&#039;re a new user to AutoIt and you come across this code, where would you find -3, -4 or -5 in the help file?&lt;br /&gt;
; Since AutoIt is relatively a new concept to you, your first thought isn&#039;t to search through all the include files, I mean&lt;br /&gt;
; why would you, the help file is there for a reason&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    GUICtrlCreateLabel(&#039;Why magic numbers are counter productive.&#039;, 5, 5)&lt;br /&gt;
    GUICtrlSetState(Default, 128) ; Does this hide, show or disable it?&lt;br /&gt;
    GUICtrlSetState(Default, 64) ; Does this hide, show or disable it?&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case -3 ; Doesn&#039;t really tell much about what it does&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
            Case -4, -5 ; Again, no idea what these are. MouseMove? MouseClick? Restore?&lt;br /&gt;
                MsgBox(4096, &#039;&#039;, &#039;Do something when this action takes place.&#039;)&lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Did you understand the numbers were these:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    GUICtrlCreateLabel(&#039;Why magic numbers are counter productive.&#039;, 5, 5)&lt;br /&gt;
    GUICtrlSetState(Default, $GUI_DISABLE) ; Better, this is documented in the help file&lt;br /&gt;
    GUICtrlSetState(Default, $GUI_ENABLE) ; Better, this is documented in the help file&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE ; Better, this is documented in the help file. Ah, it&#039;s the close action&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
            Case $GUI_EVENT_MINIMIZE, $GUI_EVENT_RESTORE ; Better, this is documented in the help file&lt;br /&gt;
                MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;Do something when this action takes place.&#039;) &lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Magic_number_(programming) Magic number (programming)]&lt;br /&gt;
&lt;br /&gt;
== Include-once directive ==&lt;br /&gt;
This one is designed for standard includes and UDFs, it&#039;s highly recommended to use it only for that.&lt;br /&gt;
&lt;br /&gt;
Those includes may be used in more than one file of your project because they are needed for some includes or your script itself.&lt;br /&gt;
In that case, the code would be duplicated, which is not a good thing especially if you have constants declared in those files, in so far as the constants cannot be redeclared/reassigned you will get error messages about trying to redeclare them; same thing for functions, you can&#039;t use a function name more than once.&lt;br /&gt;
&lt;br /&gt;
Put the directive at the top of your UDF (library) to avoid it from being included more than once :&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include-once&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13504</id>
		<title>Best coding practices</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13504"/>
		<updated>2016-07-20T20:22:52Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Magic Numbers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what are to be considered the best coding practices within AutoIt. These recommendations are based on accepted coding practices common to a number of other programming languages. You do not need to follow them, but it is recommended that you do.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: You must use AutoIt v3.3.10.0 or above to run the examples below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Using Functions ==&lt;br /&gt;
If a function sets the @error flag, you should always check it before using a return value - if @error indicates an error then the function return value is generally undefined.&lt;br /&gt;
&lt;br /&gt;
Learn more about using Functions by reading &amp;quot;[https://www.autoitscript.com/autoit3/docs/function_notes.htm Function Notes]&amp;quot; from HelpFile.&lt;br /&gt;
&lt;br /&gt;
== Names of Variables ==&lt;br /&gt;
The variable naming convention used in AutoIt is based on [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation]. The prefix defines the logical data type rather than the physical data type: in this way, it gives a hint as to what the variable&#039;s purpose is, or what it represents. The prefix does not encode the actual data type: this occurs during assignment. See the table below for accepted standards.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! example&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $bBool = True&lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $dBinary = Binary(&amp;quot;0x80000000&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452 &lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $hGUI = GUICreate(&amp;quot;My GUI&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlID || $idButton_Ok = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;Hello world&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|v || Variant || $vData = ClipGet()&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! dollar prefix !! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| $ || a || h || Handles&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a local variable the integer 7&lt;br /&gt;
Local $iWeekDays = 7&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable the value of Pi&lt;br /&gt;
Local $fPi = 3.14159265358979&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable an array of strings&lt;br /&gt;
Local $asArray[7] = [&#039;mon&#039;, &#039;tue&#039;, &#039;wed&#039;, &#039;thu&#039;, &#039;fri&#039;, &#039;sat&#039;, &#039;sun&#039;]&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable an array of numbers&lt;br /&gt;
Local $anArray[4] = [0, 0.25, 3 / 4, 12]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variable Initialization ==&lt;br /&gt;
When initializing variables there are several points to consider. It is bad practice to hog memory by assigning data which is not immediately required. It is therefore recommended that you declare and initialize variables immediately prior to use. If you wish to assign a default value to a variable which you intend to overwrite later, then the data should be of the same (or the most logical representation of its) type and use as little memory as possible.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Inconsistent data types are considered bad&lt;br /&gt;
Local $iInteger = &amp;quot;0&amp;quot;&lt;br /&gt;
Local $sString = False&lt;br /&gt;
&lt;br /&gt;
; Correct initialization&lt;br /&gt;
Local $iInteger = 0&lt;br /&gt;
Local $sString = &#039;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the following table, recommended default values are shown for each data type. Some data types have more than one possibile default value which can be used for initialization.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Default Value !! covering type&lt;br /&gt;
|-&lt;br /&gt;
| Binary(&amp;quot;&amp;quot;) || $d&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot; || $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| 0 || $a, $h, $i, $id, $m, $n, $o, $p, $t, $tag, $v&lt;br /&gt;
|-&lt;br /&gt;
| 0.0 || $f&lt;br /&gt;
|-&lt;br /&gt;
| Null || $o, $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| False (or True) || $b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Declare and initialize a variable with the recommended default value&lt;br /&gt;
Local $vUndefined = Null ; This does not require much memory&lt;br /&gt;
&lt;br /&gt;
; Some time later:&lt;br /&gt;
$vUndefined = 0xB0AD1CEA ; Assign an appropriate value as and when needed&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To reduce bloat, multiple variables can be declared on a single line. When declaring multiple variables on the same line, it is generally recommended that you stick to declaring one data type on each line. The intention here is to make the code easier to follow and manage in a future, however the best layout will vary according to circumstance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Not recommended&lt;br /&gt;
Local $sString = &amp;quot;&amp;quot;, $iInteger = 0, $asArray = [&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;] ; Mixed data types&lt;br /&gt;
&lt;br /&gt;
; Recommended&lt;br /&gt;
Local $iLeft = 10, $iTop = 10 ; Integers&lt;br /&gt;
Local $idButton_Go = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop) ; ControlIds&lt;br /&gt;
Local $idButton_Quit = GUICtrlCreateButton(&amp;quot;Quit&amp;quot;, 50, 10) ; ControlIds&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some languages it is essential to initialize variables on declaration, but this is not the case with AutoIt. Regarding data type, variables declared without being initialized should be considered as being undefined.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
Variables should also be named according to their scope.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Global UDF variable !! Global variable !! Local variable&lt;br /&gt;
|-&lt;br /&gt;
| $__g_iSomeVar || $g_iSomeVar || $iSomeVar&lt;br /&gt;
|}&lt;br /&gt;
With this method, you will avoid unwanted re-assignments.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Assign a Global variable the number 0&lt;br /&gt;
Global $iSomeVar1 = 0&lt;br /&gt;
; Assign a Global variable the number 5&lt;br /&gt;
Global $g_iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
SomeFunc()&lt;br /&gt;
&lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; Assign Local variables respectively the numbers 3 and 4&lt;br /&gt;
    Local $iSomeVar1 = 3, $iSomeVar2 = 4&lt;br /&gt;
&lt;br /&gt;
    ; Note: The user inadvertently re-assigned the global variable $iSomeVar1, because this one is not named as &amp;quot;global&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $iSomeVar1&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $iSomeVar1: &amp;quot; &amp;amp; $iSomeVar1)&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $iSomeVar2&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $iSomeVar2: &amp;quot; &amp;amp; $iSomeVar2)&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $g_iSomeVar2&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $g_iSomeVar2: &amp;quot; &amp;amp; $g_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&amp;lt;br /&amp;gt;Always declare your global variables in the global scope, not in a function. It will prevent another function from using it before its declaration and the declaration is implicit (see [[#jumpsec1|examples]]).&lt;br /&gt;
&lt;br /&gt;
* A variable declared locally (with the Local keyword), has a visibility which depends of the scope where it&#039;s declared.&lt;br /&gt;
:Declaration in the global scope: the variable is visible everywhere; declare it as Local if this one is only to be used in the same scope, i.e. outside of any functions. A variable declared as Local in the Global scope is still a Global variable, it&#039;s only for the sake of code clarity that you&#039;d use the Local declaration in the Global scope.&lt;br /&gt;
:Declaration in a function: the variable is visible by the function itself and nowhere else.&lt;br /&gt;
&lt;br /&gt;
Structure of a code scope:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Global scope&lt;br /&gt;
&lt;br /&gt;
; Include the Constants file, it contains various constants; it&#039;s needed here for the $MB_SYSTEMMODAL flag of the MsgBox function)&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; This scope is either Global or Local, depending on where you use the variables&lt;br /&gt;
&lt;br /&gt;
; Assign a Global variable the number 0 (which corresponds to an initialization of a variable number), its scope is Global because it&#039;s used in at least one function&lt;br /&gt;
Global $g_iVar1 = 0&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the string &amp;quot;foo&amp;quot;, its scope is Local because it&#039;s use is used only in this scope&lt;br /&gt;
Local $sVar2 = &amp;quot;foo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; Display the content of $sVar2&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar2: &amp;quot; &amp;amp; $sVar2)&lt;br /&gt;
&lt;br /&gt;
; Re-assign a Local variable the string returned by the function MyFunc&lt;br /&gt;
$sVar2 = MyFunc()&lt;br /&gt;
&lt;br /&gt;
; Re-Display the content of $sVar2&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar2: &amp;quot; &amp;amp; $sVar2)&lt;br /&gt;
&lt;br /&gt;
; Declare a function (its main utility is described later in Functions, we can see one here which is to create a Local scope)&lt;br /&gt;
Func MyFunc()&lt;br /&gt;
    ; Local scope&lt;br /&gt;
&lt;br /&gt;
    ; Display the content of $g_iVar1&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $g_iVar1: &amp;quot; &amp;amp; $g_iVar1)&lt;br /&gt;
&lt;br /&gt;
    ; Assign a Local variable the string &amp;quot;bar&amp;quot;, its scope is Local because it&#039;s use is restricted to the function&#039;s scope&lt;br /&gt;
    Local $sVar3 = &amp;quot;bar&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Display the content of $sVar3&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar3: &amp;quot; &amp;amp; $sVar3)&lt;br /&gt;
&lt;br /&gt;
    ; Return the $sVar3 content, it will be visible (if used) to the scope where the function is called&lt;br /&gt;
    Return $sVar3&lt;br /&gt;
EndFunc   ;==&amp;gt;MyFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Concerning the Dim keyword, its recommended usage is limited to empty an existing array (Example 1) or to redeclare a function parameter (Example 2).&lt;br /&gt;
&lt;br /&gt;
Example 1:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Include the Array UDF, it&#039;s needed here for the _ArrayDisplay function&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
; Assign a Local variable an array containing numbers with a size of 5&lt;br /&gt;
; Note than an array is 0 based, to access the first element the code is: $aiArray[0]&lt;br /&gt;
Local $aiArray[5] = [1, 2, 3, 4, 5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aiArray)&lt;br /&gt;
 &lt;br /&gt;
; Empty the array (and keep its size)&lt;br /&gt;
Dim $aiArray[5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aiArray)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Remark: The variable type of an emptied array is a string, every non initialized variable is a string.&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Call MyFunc with default parameters ($vParam1 = 0)&lt;br /&gt;
MyFunc()&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array containing integers&lt;br /&gt;
Local $aiArray[3] = [3, 4, 5]&lt;br /&gt;
; Call MyFunc with $aiArray as parameter ($vParam1 = $aiArray)&lt;br /&gt;
MyFunc($aiArray)&lt;br /&gt;
&lt;br /&gt;
Func MyFunc($vParam1 = 0)&lt;br /&gt;
    ; If $vParam1 is NOT an array then redeclare it to an array&lt;br /&gt;
    If Not IsArray($vParam1) Then&lt;br /&gt;
        Dim $vParam1[3] = [0, 1, 2]&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    ; Display the array&lt;br /&gt;
    _ArrayDisplay($vParam1)&lt;br /&gt;
EndFunc   ;==&amp;gt;MyFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the ReDim keyword, limit its use to resize an array when you want to keep its content:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Include the Array UDF, it&#039;s needed here for the _ArrayDisplay function&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
; Assign a Local variable an array containing numbers with a size of 5&lt;br /&gt;
; Note than an array is 0 based, to access the first element the code is: $aiArray[0]&lt;br /&gt;
Local $aArray[5] = [1, 2, 3, 4, 5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
 &lt;br /&gt;
; Resize the array (and keep its content)&lt;br /&gt;
ReDim $aArray[3]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why using Dim over Local/Global is not always a good option:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Dim $g_vVariableThatIsGlobal = &amp;quot;This is a variable that has &amp;quot;&amp;quot;Program Scope&amp;quot;&amp;quot; aka Global.&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;An example of why Dim can cause more problems than solve them.&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
Example()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, $g_vVariableThatIsGlobal) ; That looks alright to me as it displays the following text: This is a variable that has &amp;quot;Program Scope&amp;quot; aka Global&lt;br /&gt;
 &lt;br /&gt;
    Local $vReturn = SomeFunc() ; Call some random function&lt;br /&gt;
 &lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, $vReturn, $g_vVariableThatIsGlobal) ; The Global variable ($g_vVariableThatIsGlobal) changed because I totally forgot I had a duplicate variable name in &amp;quot;SomeFunc&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; This should create a variable in Local scope if the variable name doesn&amp;quot;t already exist&lt;br /&gt;
    ; For argument sake I totally forgot that I declared a variable already with the same name&lt;br /&gt;
    ; Well I only want this to be changed in the function and not the variable at the top of the script&lt;br /&gt;
    ; Should be OK right? Think again&lt;br /&gt;
    Dim $g_vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
    For $i = 1 To 10&lt;br /&gt;
        $g_vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $g_vVariableThatIsGlobal&lt;br /&gt;
    Next&lt;br /&gt;
    Return $g_vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;jumpsec1&amp;quot;&amp;gt;Declaring Global variables in a Function is never a good idea:&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling Example() first will initialise the Global variable $g_vVariableThatIsGlobal and therefore calling SomeFunc() won&#039;t return an error&lt;br /&gt;
; Now look at Example 2&lt;br /&gt;
Example()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script&lt;br /&gt;
    Global $g_vVariableThatIsGlobal = &#039;This is a variable that has &#039;&#039;File Scope&#039;&#039; aka Global.&#039;&lt;br /&gt;
    SomeFunc()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $g_vVariableThatIsGlobal) ; As the variable was initialised this will not return an error&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling SomeFunc() first will bypass the Global variable $g_vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $g_vVariableThatIsGlobal contains&lt;br /&gt;
SomeFunc()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script&lt;br /&gt;
    Global $g_vVariableThatIsGlobal = &#039;This is a variable that has &#039;&#039;File Scope&#039;&#039; aka Global.&#039;&lt;br /&gt;
    SomeFunc()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $g_vVariableThatIsGlobal) ; As the variable wasn&#039;t initialised this will return an error of &amp;quot;variable used without being declared.&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declaring variables in loops (For, While, Do etc..) can have an affect on efficiency:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables inside loops should be avoided as the variable is re-declared on each repetition&lt;br /&gt;
For $i = 1 To 10 ; $i is in &#039;loop scope.&#039;&lt;br /&gt;
    Local $iInt = $i&lt;br /&gt;
Next&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $iInt) ; This will display 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables outside of loops is more efficient in the long run&lt;br /&gt;
Local $iInt = 0&lt;br /&gt;
For $i = 1 To 10 ; $i is in &#039;loop scope.&#039;&lt;br /&gt;
    $iInt = $i&lt;br /&gt;
Next&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $iInt) ; This will display 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no requirement to declare the iteration count variable in a loop:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Correct&lt;br /&gt;
Local Const $iCount = 99&lt;br /&gt;
Local $aArray[$iCount]&lt;br /&gt;
For $i = 0 To UBound($iCount) - 1 ; $i is only used in the loop, so there is no requirement to declare it&lt;br /&gt;
    $aArray[$i] = $i&lt;br /&gt;
Next&lt;br /&gt;
&lt;br /&gt;
; Incorrect&lt;br /&gt;
Local Const $iCount = 99&lt;br /&gt;
Local $aArray[$iCount]&lt;br /&gt;
Local $i ; This is only used to store the iteration count value in the loop and therefore doesn&#039;t need to be declared. &lt;br /&gt;
For $i = 0 To UBound($iCount) - 1&lt;br /&gt;
    $aArray[$i] = $i&lt;br /&gt;
Next&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
As you can see, there is the Const keyword in the example, we are going to talk about it.&lt;br /&gt;
&lt;br /&gt;
== Const, Static, Enum ==&lt;br /&gt;
&lt;br /&gt;
=== Const ===&lt;br /&gt;
We won&#039;t talk about the advantages of using a constant variable, they are neglibible (for your information, an AutoIt constant variable is marked as read-only and remains a read-only variable when compiled).&lt;br /&gt;
&lt;br /&gt;
The Const keyword may be used first by some of you to avoid re-assignments.&lt;br /&gt;
The best way to use them is for real static values, meaning that these values won&#039;t change regardless of the instance of the program.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Not recommended&lt;br /&gt;
Local Const $hGUI = GUICreate(&amp;quot;MyGUI&amp;quot;)&lt;br /&gt;
; The handle of the window is unique, it&#039;s generated by Windows and changes&lt;br /&gt;
&lt;br /&gt;
; Recommended&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Static ===&lt;br /&gt;
Static variables are the solution to global variables being used in only one function.&lt;br /&gt;
e.g: Retain variable data once returned from a Function and only use that variable in that particular Function.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 1&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 2&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 3&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; This initialises a Static variable in Local scope. When a variable is declared just in Local scope (within a Function,)&lt;br /&gt;
    ; it&#039;s destroyed when the Function ends/returns. This isn&#039;t the case for a Static variable. Also, the variable can&#039;t be&lt;br /&gt;
    ; accessed from anywhere else in the script apart from the Function it was declared in&lt;br /&gt;
    Local Static $vVariableThatIsStatic = 0&lt;br /&gt;
    Local $vVariableThatIsLocal = 0&lt;br /&gt;
    $vVariableThatIsLocal += 1 ; This will always be 1 as it is destroyed once returned from SomeFunc&lt;br /&gt;
    $vVariableThatIsStatic += 1 ; This will increase by 1&lt;br /&gt;
    MsgBox(4096, $vVariableThatIsLocal, $vVariableThatIsStatic)&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enum ===&lt;br /&gt;
This statement is often practical in certain situations:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Create variables in Local scope and enumerate through the variables. Default is to start from 0&lt;br /&gt;
    Local Enum $eCat, $eDog, $eMouse, $eHamster ; $eHamster is equal to the value 3, not 4&lt;br /&gt;
&lt;br /&gt;
    ; Create an array in Local scope with 4 elements&lt;br /&gt;
    Local $aAnimalNames[4]&lt;br /&gt;
&lt;br /&gt;
    ; Assign each array element with the name of the respective animal. For example the name of the cat is Jasper&lt;br /&gt;
    $aAnimalNames[$eCat] = &#039;Jasper&#039; ; $eCat is equal to 0, similar to using $aAnimalNames[0]&lt;br /&gt;
    $aAnimalNames[$eDog] = &#039;Beethoven&#039; ; $eDog is equal to 1, similar to using $aAnimalNames[1]&lt;br /&gt;
    $aAnimalNames[$eMouse] = &#039;Pinky&#039; ; $eMouse is equal to 2, similar to using $aAnimalNames[2]&lt;br /&gt;
    $aAnimalNames[$eHamster] = &#039;Fidget&#039; ; $eHamster is equal to 3, similar to using $aAnimalNames[3]&lt;br /&gt;
&lt;br /&gt;
    ; Display the values of the array&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$aAnimalNames[$eCat] = &#039; &amp;amp; $aAnimalNames[$eCat] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eDog] = &#039; &amp;amp; $aAnimalNames[$eDog] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eMouse] = &#039; &amp;amp; $aAnimalNames[$eMouse] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eHamster] = &#039; &amp;amp; $aAnimalNames[$eHamster] &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Sometimes using this approach for accessing an element is more practical than using a numerical value, due to the fact changing the index value of&lt;br /&gt;
    ; the enum constant has no affect on it&#039;s position in the array. Therefore changing the location of $eCat in the array is as simple as changing the order&lt;br /&gt;
    ; it appears in the initial declaration e.g&lt;br /&gt;
&lt;br /&gt;
    ; Local Enum $eDog, $eMouse, $eCat, $eHamster&lt;br /&gt;
&lt;br /&gt;
    ; Now $eCat is the 2nd element in the array. If you were using numerical values, you would have to manually change all references of $aAnimalNames[0] to&lt;br /&gt;
    ; $aAnimalNames[2], as well as for the other elements which have now shifted&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Au3Check directive ==&lt;br /&gt;
As you may know (and we hope), the Au3Check tool checks your code for syntax errors, variables used without being declared etc. which is a good thing to fix your script.&lt;br /&gt;
&lt;br /&gt;
With the official custom directive used to check the helpfile examples/includes, you can apply the good coding practices listed above:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Note: this directive is only used if you&#039;ve installed the full version of [https://www.autoitscript.com/cgi-bin/getfile.pl?../autoit3/scite/download/SciTE4AutoIt3.exe Scite4AutoIt3]&lt;br /&gt;
&lt;br /&gt;
== Magic Numbers ==&lt;br /&gt;
Magic numbers are arbitrary numbers interspersed throughout a program&#039;s source code which do not have an associated identifier. The downside to this is not being able to derive a meaning from the number. &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox(262144, &amp;quot;Magic Numbers&amp;quot;, &amp;quot;It&#039;s Adventure Time!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In this example, the magic number is 262144 with the identifier being $MB_TOPMOST according to the helpfile.&lt;br /&gt;
&lt;br /&gt;
The corrected example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox($MB_TOPMOST, &amp;quot;Magic Numbers&amp;quot;, &amp;quot;It&#039;s Adventure Time!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Imagine you&#039;re a new user to AutoIt and you come across this code, where would you find -3, -4 or -5 in the help file?&lt;br /&gt;
; Since AutoIt is relatively a new concept to you, your first thought isn&#039;t to search through all the include files, I mean&lt;br /&gt;
; why would you, the help file is there for a reason&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    GUICtrlCreateLabel(&#039;Why magic numbers are counter productive.&#039;, 5, 5)&lt;br /&gt;
    GUICtrlSetState(Default, 128) ; Does this hide, show or disable it?&lt;br /&gt;
    GUICtrlSetState(Default, 64) ; Does this hide, show or disable it?&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case -3 ; Doesn&#039;t really tell much about what it does&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
            Case -4, -5 ; Again, no idea what these are. MouseMove? MouseClick? Restore?&lt;br /&gt;
                MsgBox(4096, &#039;&#039;, &#039;Do something when this action takes place.&#039;)&lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Did you understand the numbers were these:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    GUICtrlCreateLabel(&#039;Why magic numbers are counter productive.&#039;, 5, 5)&lt;br /&gt;
    GUICtrlSetState(Default, $GUI_DISABLE) ; Better, this is documented in the help file&lt;br /&gt;
    GUICtrlSetState(Default, $GUI_ENABLE) ; Better, this is documented in the help file&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE ; Better, this is documented in the help file. Ah, it&#039;s the close action&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
            Case $GUI_EVENT_MINIMIZE, $GUI_EVENT_RESTORE ; Better, this is documented in the help file&lt;br /&gt;
                MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;Do something when this action takes place.&#039;) &lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Magic_number_(programming) Magic number (programming)]&lt;br /&gt;
&lt;br /&gt;
== Include-once directive ==&lt;br /&gt;
This one is designed for standard includes and UDFs, it&#039;s highly recommended to use it.&lt;br /&gt;
&lt;br /&gt;
Those includes may be included in more than one script of your project because they are needed for some includes or your script itself.&lt;br /&gt;
In that case, the code will be duplicated which is not a good thing especially if you have (and it&#039;s mainly the case) constants declared in those files, in so far as the constants cannot be redeclared/reassigned; same thing for functions&lt;br /&gt;
&lt;br /&gt;
Put the directive in top of your UDF (library) to avoid itself to be included more than once :&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include-once&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13503</id>
		<title>Best coding practices</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13503"/>
		<updated>2016-07-20T20:21:00Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Au3Check directive */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what are to be considered the best coding practices within AutoIt. These recommendations are based on accepted coding practices common to a number of other programming languages. You do not need to follow them, but it is recommended that you do.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: You must use AutoIt v3.3.10.0 or above to run the examples below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Using Functions ==&lt;br /&gt;
If a function sets the @error flag, you should always check it before using a return value - if @error indicates an error then the function return value is generally undefined.&lt;br /&gt;
&lt;br /&gt;
Learn more about using Functions by reading &amp;quot;[https://www.autoitscript.com/autoit3/docs/function_notes.htm Function Notes]&amp;quot; from HelpFile.&lt;br /&gt;
&lt;br /&gt;
== Names of Variables ==&lt;br /&gt;
The variable naming convention used in AutoIt is based on [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation]. The prefix defines the logical data type rather than the physical data type: in this way, it gives a hint as to what the variable&#039;s purpose is, or what it represents. The prefix does not encode the actual data type: this occurs during assignment. See the table below for accepted standards.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! example&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $bBool = True&lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $dBinary = Binary(&amp;quot;0x80000000&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452 &lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $hGUI = GUICreate(&amp;quot;My GUI&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlID || $idButton_Ok = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;Hello world&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|v || Variant || $vData = ClipGet()&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! dollar prefix !! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| $ || a || h || Handles&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a local variable the integer 7&lt;br /&gt;
Local $iWeekDays = 7&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable the value of Pi&lt;br /&gt;
Local $fPi = 3.14159265358979&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable an array of strings&lt;br /&gt;
Local $asArray[7] = [&#039;mon&#039;, &#039;tue&#039;, &#039;wed&#039;, &#039;thu&#039;, &#039;fri&#039;, &#039;sat&#039;, &#039;sun&#039;]&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable an array of numbers&lt;br /&gt;
Local $anArray[4] = [0, 0.25, 3 / 4, 12]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variable Initialization ==&lt;br /&gt;
When initializing variables there are several points to consider. It is bad practice to hog memory by assigning data which is not immediately required. It is therefore recommended that you declare and initialize variables immediately prior to use. If you wish to assign a default value to a variable which you intend to overwrite later, then the data should be of the same (or the most logical representation of its) type and use as little memory as possible.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Inconsistent data types are considered bad&lt;br /&gt;
Local $iInteger = &amp;quot;0&amp;quot;&lt;br /&gt;
Local $sString = False&lt;br /&gt;
&lt;br /&gt;
; Correct initialization&lt;br /&gt;
Local $iInteger = 0&lt;br /&gt;
Local $sString = &#039;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the following table, recommended default values are shown for each data type. Some data types have more than one possibile default value which can be used for initialization.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Default Value !! covering type&lt;br /&gt;
|-&lt;br /&gt;
| Binary(&amp;quot;&amp;quot;) || $d&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot; || $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| 0 || $a, $h, $i, $id, $m, $n, $o, $p, $t, $tag, $v&lt;br /&gt;
|-&lt;br /&gt;
| 0.0 || $f&lt;br /&gt;
|-&lt;br /&gt;
| Null || $o, $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| False (or True) || $b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Declare and initialize a variable with the recommended default value&lt;br /&gt;
Local $vUndefined = Null ; This does not require much memory&lt;br /&gt;
&lt;br /&gt;
; Some time later:&lt;br /&gt;
$vUndefined = 0xB0AD1CEA ; Assign an appropriate value as and when needed&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To reduce bloat, multiple variables can be declared on a single line. When declaring multiple variables on the same line, it is generally recommended that you stick to declaring one data type on each line. The intention here is to make the code easier to follow and manage in a future, however the best layout will vary according to circumstance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Not recommended&lt;br /&gt;
Local $sString = &amp;quot;&amp;quot;, $iInteger = 0, $asArray = [&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;] ; Mixed data types&lt;br /&gt;
&lt;br /&gt;
; Recommended&lt;br /&gt;
Local $iLeft = 10, $iTop = 10 ; Integers&lt;br /&gt;
Local $idButton_Go = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop) ; ControlIds&lt;br /&gt;
Local $idButton_Quit = GUICtrlCreateButton(&amp;quot;Quit&amp;quot;, 50, 10) ; ControlIds&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some languages it is essential to initialize variables on declaration, but this is not the case with AutoIt. Regarding data type, variables declared without being initialized should be considered as being undefined.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
Variables should also be named according to their scope.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Global UDF variable !! Global variable !! Local variable&lt;br /&gt;
|-&lt;br /&gt;
| $__g_iSomeVar || $g_iSomeVar || $iSomeVar&lt;br /&gt;
|}&lt;br /&gt;
With this method, you will avoid unwanted re-assignments.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Assign a Global variable the number 0&lt;br /&gt;
Global $iSomeVar1 = 0&lt;br /&gt;
; Assign a Global variable the number 5&lt;br /&gt;
Global $g_iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
SomeFunc()&lt;br /&gt;
&lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; Assign Local variables respectively the numbers 3 and 4&lt;br /&gt;
    Local $iSomeVar1 = 3, $iSomeVar2 = 4&lt;br /&gt;
&lt;br /&gt;
    ; Note: The user inadvertently re-assigned the global variable $iSomeVar1, because this one is not named as &amp;quot;global&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $iSomeVar1&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $iSomeVar1: &amp;quot; &amp;amp; $iSomeVar1)&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $iSomeVar2&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $iSomeVar2: &amp;quot; &amp;amp; $iSomeVar2)&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $g_iSomeVar2&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $g_iSomeVar2: &amp;quot; &amp;amp; $g_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&amp;lt;br /&amp;gt;Always declare your global variables in the global scope, not in a function. It will prevent another function from using it before its declaration and the declaration is implicit (see [[#jumpsec1|examples]]).&lt;br /&gt;
&lt;br /&gt;
* A variable declared locally (with the Local keyword), has a visibility which depends of the scope where it&#039;s declared.&lt;br /&gt;
:Declaration in the global scope: the variable is visible everywhere; declare it as Local if this one is only to be used in the same scope, i.e. outside of any functions. A variable declared as Local in the Global scope is still a Global variable, it&#039;s only for the sake of code clarity that you&#039;d use the Local declaration in the Global scope.&lt;br /&gt;
:Declaration in a function: the variable is visible by the function itself and nowhere else.&lt;br /&gt;
&lt;br /&gt;
Structure of a code scope:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Global scope&lt;br /&gt;
&lt;br /&gt;
; Include the Constants file, it contains various constants; it&#039;s needed here for the $MB_SYSTEMMODAL flag of the MsgBox function)&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; This scope is either Global or Local, depending on where you use the variables&lt;br /&gt;
&lt;br /&gt;
; Assign a Global variable the number 0 (which corresponds to an initialization of a variable number), its scope is Global because it&#039;s used in at least one function&lt;br /&gt;
Global $g_iVar1 = 0&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the string &amp;quot;foo&amp;quot;, its scope is Local because it&#039;s use is used only in this scope&lt;br /&gt;
Local $sVar2 = &amp;quot;foo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; Display the content of $sVar2&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar2: &amp;quot; &amp;amp; $sVar2)&lt;br /&gt;
&lt;br /&gt;
; Re-assign a Local variable the string returned by the function MyFunc&lt;br /&gt;
$sVar2 = MyFunc()&lt;br /&gt;
&lt;br /&gt;
; Re-Display the content of $sVar2&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar2: &amp;quot; &amp;amp; $sVar2)&lt;br /&gt;
&lt;br /&gt;
; Declare a function (its main utility is described later in Functions, we can see one here which is to create a Local scope)&lt;br /&gt;
Func MyFunc()&lt;br /&gt;
    ; Local scope&lt;br /&gt;
&lt;br /&gt;
    ; Display the content of $g_iVar1&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $g_iVar1: &amp;quot; &amp;amp; $g_iVar1)&lt;br /&gt;
&lt;br /&gt;
    ; Assign a Local variable the string &amp;quot;bar&amp;quot;, its scope is Local because it&#039;s use is restricted to the function&#039;s scope&lt;br /&gt;
    Local $sVar3 = &amp;quot;bar&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Display the content of $sVar3&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar3: &amp;quot; &amp;amp; $sVar3)&lt;br /&gt;
&lt;br /&gt;
    ; Return the $sVar3 content, it will be visible (if used) to the scope where the function is called&lt;br /&gt;
    Return $sVar3&lt;br /&gt;
EndFunc   ;==&amp;gt;MyFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Concerning the Dim keyword, its recommended usage is limited to empty an existing array (Example 1) or to redeclare a function parameter (Example 2).&lt;br /&gt;
&lt;br /&gt;
Example 1:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Include the Array UDF, it&#039;s needed here for the _ArrayDisplay function&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
; Assign a Local variable an array containing numbers with a size of 5&lt;br /&gt;
; Note than an array is 0 based, to access the first element the code is: $aiArray[0]&lt;br /&gt;
Local $aiArray[5] = [1, 2, 3, 4, 5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aiArray)&lt;br /&gt;
 &lt;br /&gt;
; Empty the array (and keep its size)&lt;br /&gt;
Dim $aiArray[5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aiArray)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Remark: The variable type of an emptied array is a string, every non initialized variable is a string.&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Call MyFunc with default parameters ($vParam1 = 0)&lt;br /&gt;
MyFunc()&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array containing integers&lt;br /&gt;
Local $aiArray[3] = [3, 4, 5]&lt;br /&gt;
; Call MyFunc with $aiArray as parameter ($vParam1 = $aiArray)&lt;br /&gt;
MyFunc($aiArray)&lt;br /&gt;
&lt;br /&gt;
Func MyFunc($vParam1 = 0)&lt;br /&gt;
    ; If $vParam1 is NOT an array then redeclare it to an array&lt;br /&gt;
    If Not IsArray($vParam1) Then&lt;br /&gt;
        Dim $vParam1[3] = [0, 1, 2]&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    ; Display the array&lt;br /&gt;
    _ArrayDisplay($vParam1)&lt;br /&gt;
EndFunc   ;==&amp;gt;MyFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the ReDim keyword, limit its use to resize an array when you want to keep its content:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Include the Array UDF, it&#039;s needed here for the _ArrayDisplay function&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
; Assign a Local variable an array containing numbers with a size of 5&lt;br /&gt;
; Note than an array is 0 based, to access the first element the code is: $aiArray[0]&lt;br /&gt;
Local $aArray[5] = [1, 2, 3, 4, 5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
 &lt;br /&gt;
; Resize the array (and keep its content)&lt;br /&gt;
ReDim $aArray[3]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why using Dim over Local/Global is not always a good option:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Dim $g_vVariableThatIsGlobal = &amp;quot;This is a variable that has &amp;quot;&amp;quot;Program Scope&amp;quot;&amp;quot; aka Global.&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;An example of why Dim can cause more problems than solve them.&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
Example()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, $g_vVariableThatIsGlobal) ; That looks alright to me as it displays the following text: This is a variable that has &amp;quot;Program Scope&amp;quot; aka Global&lt;br /&gt;
 &lt;br /&gt;
    Local $vReturn = SomeFunc() ; Call some random function&lt;br /&gt;
 &lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, $vReturn, $g_vVariableThatIsGlobal) ; The Global variable ($g_vVariableThatIsGlobal) changed because I totally forgot I had a duplicate variable name in &amp;quot;SomeFunc&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; This should create a variable in Local scope if the variable name doesn&amp;quot;t already exist&lt;br /&gt;
    ; For argument sake I totally forgot that I declared a variable already with the same name&lt;br /&gt;
    ; Well I only want this to be changed in the function and not the variable at the top of the script&lt;br /&gt;
    ; Should be OK right? Think again&lt;br /&gt;
    Dim $g_vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
    For $i = 1 To 10&lt;br /&gt;
        $g_vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $g_vVariableThatIsGlobal&lt;br /&gt;
    Next&lt;br /&gt;
    Return $g_vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;jumpsec1&amp;quot;&amp;gt;Declaring Global variables in a Function is never a good idea:&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling Example() first will initialise the Global variable $g_vVariableThatIsGlobal and therefore calling SomeFunc() won&#039;t return an error&lt;br /&gt;
; Now look at Example 2&lt;br /&gt;
Example()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script&lt;br /&gt;
    Global $g_vVariableThatIsGlobal = &#039;This is a variable that has &#039;&#039;File Scope&#039;&#039; aka Global.&#039;&lt;br /&gt;
    SomeFunc()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $g_vVariableThatIsGlobal) ; As the variable was initialised this will not return an error&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling SomeFunc() first will bypass the Global variable $g_vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $g_vVariableThatIsGlobal contains&lt;br /&gt;
SomeFunc()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script&lt;br /&gt;
    Global $g_vVariableThatIsGlobal = &#039;This is a variable that has &#039;&#039;File Scope&#039;&#039; aka Global.&#039;&lt;br /&gt;
    SomeFunc()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $g_vVariableThatIsGlobal) ; As the variable wasn&#039;t initialised this will return an error of &amp;quot;variable used without being declared.&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declaring variables in loops (For, While, Do etc..) can have an affect on efficiency:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables inside loops should be avoided as the variable is re-declared on each repetition&lt;br /&gt;
For $i = 1 To 10 ; $i is in &#039;loop scope.&#039;&lt;br /&gt;
    Local $iInt = $i&lt;br /&gt;
Next&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $iInt) ; This will display 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables outside of loops is more efficient in the long run&lt;br /&gt;
Local $iInt = 0&lt;br /&gt;
For $i = 1 To 10 ; $i is in &#039;loop scope.&#039;&lt;br /&gt;
    $iInt = $i&lt;br /&gt;
Next&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $iInt) ; This will display 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no requirement to declare the iteration count variable in a loop:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Correct&lt;br /&gt;
Local Const $iCount = 99&lt;br /&gt;
Local $aArray[$iCount]&lt;br /&gt;
For $i = 0 To UBound($iCount) - 1 ; $i is only used in the loop, so there is no requirement to declare it&lt;br /&gt;
    $aArray[$i] = $i&lt;br /&gt;
Next&lt;br /&gt;
&lt;br /&gt;
; Incorrect&lt;br /&gt;
Local Const $iCount = 99&lt;br /&gt;
Local $aArray[$iCount]&lt;br /&gt;
Local $i ; This is only used to store the iteration count value in the loop and therefore doesn&#039;t need to be declared. &lt;br /&gt;
For $i = 0 To UBound($iCount) - 1&lt;br /&gt;
    $aArray[$i] = $i&lt;br /&gt;
Next&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
As you can see, there is the Const keyword in the example, we are going to talk about it.&lt;br /&gt;
&lt;br /&gt;
== Const, Static, Enum ==&lt;br /&gt;
&lt;br /&gt;
=== Const ===&lt;br /&gt;
We won&#039;t talk about the advantages of using a constant variable, they are neglibible (for your information, an AutoIt constant variable is marked as read-only and remains a read-only variable when compiled).&lt;br /&gt;
&lt;br /&gt;
The Const keyword may be used first by some of you to avoid re-assignments.&lt;br /&gt;
The best way to use them is for real static values, meaning that these values won&#039;t change regardless of the instance of the program.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Not recommended&lt;br /&gt;
Local Const $hGUI = GUICreate(&amp;quot;MyGUI&amp;quot;)&lt;br /&gt;
; The handle of the window is unique, it&#039;s generated by Windows and changes&lt;br /&gt;
&lt;br /&gt;
; Recommended&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Static ===&lt;br /&gt;
Static variables are the solution to global variables being used in only one function.&lt;br /&gt;
e.g: Retain variable data once returned from a Function and only use that variable in that particular Function.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 1&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 2&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 3&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; This initialises a Static variable in Local scope. When a variable is declared just in Local scope (within a Function,)&lt;br /&gt;
    ; it&#039;s destroyed when the Function ends/returns. This isn&#039;t the case for a Static variable. Also, the variable can&#039;t be&lt;br /&gt;
    ; accessed from anywhere else in the script apart from the Function it was declared in&lt;br /&gt;
    Local Static $vVariableThatIsStatic = 0&lt;br /&gt;
    Local $vVariableThatIsLocal = 0&lt;br /&gt;
    $vVariableThatIsLocal += 1 ; This will always be 1 as it is destroyed once returned from SomeFunc&lt;br /&gt;
    $vVariableThatIsStatic += 1 ; This will increase by 1&lt;br /&gt;
    MsgBox(4096, $vVariableThatIsLocal, $vVariableThatIsStatic)&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enum ===&lt;br /&gt;
This statement is often practical in certain situations:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Create variables in Local scope and enumerate through the variables. Default is to start from 0&lt;br /&gt;
    Local Enum $eCat, $eDog, $eMouse, $eHamster ; $eHamster is equal to the value 3, not 4&lt;br /&gt;
&lt;br /&gt;
    ; Create an array in Local scope with 4 elements&lt;br /&gt;
    Local $aAnimalNames[4]&lt;br /&gt;
&lt;br /&gt;
    ; Assign each array element with the name of the respective animal. For example the name of the cat is Jasper&lt;br /&gt;
    $aAnimalNames[$eCat] = &#039;Jasper&#039; ; $eCat is equal to 0, similar to using $aAnimalNames[0]&lt;br /&gt;
    $aAnimalNames[$eDog] = &#039;Beethoven&#039; ; $eDog is equal to 1, similar to using $aAnimalNames[1]&lt;br /&gt;
    $aAnimalNames[$eMouse] = &#039;Pinky&#039; ; $eMouse is equal to 2, similar to using $aAnimalNames[2]&lt;br /&gt;
    $aAnimalNames[$eHamster] = &#039;Fidget&#039; ; $eHamster is equal to 3, similar to using $aAnimalNames[3]&lt;br /&gt;
&lt;br /&gt;
    ; Display the values of the array&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$aAnimalNames[$eCat] = &#039; &amp;amp; $aAnimalNames[$eCat] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eDog] = &#039; &amp;amp; $aAnimalNames[$eDog] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eMouse] = &#039; &amp;amp; $aAnimalNames[$eMouse] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eHamster] = &#039; &amp;amp; $aAnimalNames[$eHamster] &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Sometimes using this approach for accessing an element is more practical than using a numerical value, due to the fact changing the index value of&lt;br /&gt;
    ; the enum constant has no affect on it&#039;s position in the array. Therefore changing the location of $eCat in the array is as simple as changing the order&lt;br /&gt;
    ; it appears in the initial declaration e.g&lt;br /&gt;
&lt;br /&gt;
    ; Local Enum $eDog, $eMouse, $eCat, $eHamster&lt;br /&gt;
&lt;br /&gt;
    ; Now $eCat is the 2nd element in the array. If you were using numerical values, you would have to manually change all references of $aAnimalNames[0] to&lt;br /&gt;
    ; $aAnimalNames[2], as well as for the other elements which have now shifted&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Au3Check directive ==&lt;br /&gt;
As you may know (and we hope), the Au3Check tool checks your code for syntax errors, variables used without being declared etc. which is a good thing to fix your script.&lt;br /&gt;
&lt;br /&gt;
With the official custom directive used to check the helpfile examples/includes, you can apply the good coding practices listed above:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Note: this directive is only used if you&#039;ve installed the full version of [https://www.autoitscript.com/cgi-bin/getfile.pl?../autoit3/scite/download/SciTE4AutoIt3.exe Scite4AutoIt3]&lt;br /&gt;
&lt;br /&gt;
== Magic Numbers ==&lt;br /&gt;
Magic numbers are arbitrary numbers interspersed throughout a program&#039;s source code which do not have an associated identifier. The downside to this is not being able to derive a meaning from the number. &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox(262144, &amp;quot;Magic Numbers&amp;quot;, &amp;quot;It&#039;s Adventure Time!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In this example, the magic number is 262144 with the identifier being $MB_TOPMOST according to the helpfile.&lt;br /&gt;
&lt;br /&gt;
The corrected example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox($MB_TOPMOST, &amp;quot;Magic Numbers&amp;quot;, &amp;quot;It&#039;s Adventure Time!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Imagine you&#039;re a new user to AutoIt and you come across this code, where would you find -3, -4 or -5 in the help file?&lt;br /&gt;
; Since AutoIt is relatively a new concept to you, your first thought isn&#039;t to search through all the include files, I mean&lt;br /&gt;
; why would you, the help file is there for a reason&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    GUICtrlCreateLabel(&#039;Why magic numbers are counter productive.&#039;, 5, 5)&lt;br /&gt;
    GUICtrlSetState(Default, 128) ; Does this hide, show or disable it?&lt;br /&gt;
    GUICtrlSetState(Default, 64) ; Does this hide, show or disable it?&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case -3 ; Doesn&#039;t really tell much about what it does&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
            Case -4, -5 ; Again, no idea what these are. MouseMove? MouseClick? Restore?&lt;br /&gt;
                MsgBox(4096, &#039;&#039;, &#039;Do something when this action takes place.&#039;)&lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Did you understand the numbers were these:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    GUICtrlCreateLabel(&#039;Why magic numbers are counter productive.&#039;, 5, 5)&lt;br /&gt;
    GUICtrlSetState(Default, $GUI_DISABLE) ; Better, this is documented in the help file&lt;br /&gt;
    GUICtrlSetState(Default, $GUI_ENABLE) ; Better, this is documented in the help file&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE ; Better, this is documented in the help file. Ah, it&#039;s the close action&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
            Case $GUI_EVENT_MINIMIZE, $GUI_EVENT_RESTORE ; Better, this is documented in the help file&lt;br /&gt;
                MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;Do something when this action takes place.&#039;) ; Better, this is documented in the help file&lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Magic_number_(programming) Magic number (programming)]&lt;br /&gt;
&lt;br /&gt;
== Include-once directive ==&lt;br /&gt;
This one is designed for standard includes and UDFs, it&#039;s highly recommended to use it.&lt;br /&gt;
&lt;br /&gt;
Those includes may be included in more than one script of your project because they are needed for some includes or your script itself.&lt;br /&gt;
In that case, the code will be duplicated which is not a good thing especially if you have (and it&#039;s mainly the case) constants declared in those files, in so far as the constants cannot be redeclared/reassigned; same thing for functions&lt;br /&gt;
&lt;br /&gt;
Put the directive in top of your UDF (library) to avoid itself to be included more than once :&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include-once&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13502</id>
		<title>Best coding practices</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13502"/>
		<updated>2016-07-20T20:16:39Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Static */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what are to be considered the best coding practices within AutoIt. These recommendations are based on accepted coding practices common to a number of other programming languages. You do not need to follow them, but it is recommended that you do.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: You must use AutoIt v3.3.10.0 or above to run the examples below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Using Functions ==&lt;br /&gt;
If a function sets the @error flag, you should always check it before using a return value - if @error indicates an error then the function return value is generally undefined.&lt;br /&gt;
&lt;br /&gt;
Learn more about using Functions by reading &amp;quot;[https://www.autoitscript.com/autoit3/docs/function_notes.htm Function Notes]&amp;quot; from HelpFile.&lt;br /&gt;
&lt;br /&gt;
== Names of Variables ==&lt;br /&gt;
The variable naming convention used in AutoIt is based on [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation]. The prefix defines the logical data type rather than the physical data type: in this way, it gives a hint as to what the variable&#039;s purpose is, or what it represents. The prefix does not encode the actual data type: this occurs during assignment. See the table below for accepted standards.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! example&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $bBool = True&lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $dBinary = Binary(&amp;quot;0x80000000&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452 &lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $hGUI = GUICreate(&amp;quot;My GUI&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlID || $idButton_Ok = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;Hello world&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|v || Variant || $vData = ClipGet()&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! dollar prefix !! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| $ || a || h || Handles&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a local variable the integer 7&lt;br /&gt;
Local $iWeekDays = 7&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable the value of Pi&lt;br /&gt;
Local $fPi = 3.14159265358979&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable an array of strings&lt;br /&gt;
Local $asArray[7] = [&#039;mon&#039;, &#039;tue&#039;, &#039;wed&#039;, &#039;thu&#039;, &#039;fri&#039;, &#039;sat&#039;, &#039;sun&#039;]&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable an array of numbers&lt;br /&gt;
Local $anArray[4] = [0, 0.25, 3 / 4, 12]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variable Initialization ==&lt;br /&gt;
When initializing variables there are several points to consider. It is bad practice to hog memory by assigning data which is not immediately required. It is therefore recommended that you declare and initialize variables immediately prior to use. If you wish to assign a default value to a variable which you intend to overwrite later, then the data should be of the same (or the most logical representation of its) type and use as little memory as possible.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Inconsistent data types are considered bad&lt;br /&gt;
Local $iInteger = &amp;quot;0&amp;quot;&lt;br /&gt;
Local $sString = False&lt;br /&gt;
&lt;br /&gt;
; Correct initialization&lt;br /&gt;
Local $iInteger = 0&lt;br /&gt;
Local $sString = &#039;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the following table, recommended default values are shown for each data type. Some data types have more than one possibile default value which can be used for initialization.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Default Value !! covering type&lt;br /&gt;
|-&lt;br /&gt;
| Binary(&amp;quot;&amp;quot;) || $d&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot; || $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| 0 || $a, $h, $i, $id, $m, $n, $o, $p, $t, $tag, $v&lt;br /&gt;
|-&lt;br /&gt;
| 0.0 || $f&lt;br /&gt;
|-&lt;br /&gt;
| Null || $o, $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| False (or True) || $b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Declare and initialize a variable with the recommended default value&lt;br /&gt;
Local $vUndefined = Null ; This does not require much memory&lt;br /&gt;
&lt;br /&gt;
; Some time later:&lt;br /&gt;
$vUndefined = 0xB0AD1CEA ; Assign an appropriate value as and when needed&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To reduce bloat, multiple variables can be declared on a single line. When declaring multiple variables on the same line, it is generally recommended that you stick to declaring one data type on each line. The intention here is to make the code easier to follow and manage in a future, however the best layout will vary according to circumstance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Not recommended&lt;br /&gt;
Local $sString = &amp;quot;&amp;quot;, $iInteger = 0, $asArray = [&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;] ; Mixed data types&lt;br /&gt;
&lt;br /&gt;
; Recommended&lt;br /&gt;
Local $iLeft = 10, $iTop = 10 ; Integers&lt;br /&gt;
Local $idButton_Go = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop) ; ControlIds&lt;br /&gt;
Local $idButton_Quit = GUICtrlCreateButton(&amp;quot;Quit&amp;quot;, 50, 10) ; ControlIds&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some languages it is essential to initialize variables on declaration, but this is not the case with AutoIt. Regarding data type, variables declared without being initialized should be considered as being undefined.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
Variables should also be named according to their scope.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Global UDF variable !! Global variable !! Local variable&lt;br /&gt;
|-&lt;br /&gt;
| $__g_iSomeVar || $g_iSomeVar || $iSomeVar&lt;br /&gt;
|}&lt;br /&gt;
With this method, you will avoid unwanted re-assignments.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Assign a Global variable the number 0&lt;br /&gt;
Global $iSomeVar1 = 0&lt;br /&gt;
; Assign a Global variable the number 5&lt;br /&gt;
Global $g_iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
SomeFunc()&lt;br /&gt;
&lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; Assign Local variables respectively the numbers 3 and 4&lt;br /&gt;
    Local $iSomeVar1 = 3, $iSomeVar2 = 4&lt;br /&gt;
&lt;br /&gt;
    ; Note: The user inadvertently re-assigned the global variable $iSomeVar1, because this one is not named as &amp;quot;global&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $iSomeVar1&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $iSomeVar1: &amp;quot; &amp;amp; $iSomeVar1)&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $iSomeVar2&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $iSomeVar2: &amp;quot; &amp;amp; $iSomeVar2)&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $g_iSomeVar2&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $g_iSomeVar2: &amp;quot; &amp;amp; $g_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&amp;lt;br /&amp;gt;Always declare your global variables in the global scope, not in a function. It will prevent another function from using it before its declaration and the declaration is implicit (see [[#jumpsec1|examples]]).&lt;br /&gt;
&lt;br /&gt;
* A variable declared locally (with the Local keyword), has a visibility which depends of the scope where it&#039;s declared.&lt;br /&gt;
:Declaration in the global scope: the variable is visible everywhere; declare it as Local if this one is only to be used in the same scope, i.e. outside of any functions. A variable declared as Local in the Global scope is still a Global variable, it&#039;s only for the sake of code clarity that you&#039;d use the Local declaration in the Global scope.&lt;br /&gt;
:Declaration in a function: the variable is visible by the function itself and nowhere else.&lt;br /&gt;
&lt;br /&gt;
Structure of a code scope:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Global scope&lt;br /&gt;
&lt;br /&gt;
; Include the Constants file, it contains various constants; it&#039;s needed here for the $MB_SYSTEMMODAL flag of the MsgBox function)&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; This scope is either Global or Local, depending on where you use the variables&lt;br /&gt;
&lt;br /&gt;
; Assign a Global variable the number 0 (which corresponds to an initialization of a variable number), its scope is Global because it&#039;s used in at least one function&lt;br /&gt;
Global $g_iVar1 = 0&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the string &amp;quot;foo&amp;quot;, its scope is Local because it&#039;s use is used only in this scope&lt;br /&gt;
Local $sVar2 = &amp;quot;foo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; Display the content of $sVar2&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar2: &amp;quot; &amp;amp; $sVar2)&lt;br /&gt;
&lt;br /&gt;
; Re-assign a Local variable the string returned by the function MyFunc&lt;br /&gt;
$sVar2 = MyFunc()&lt;br /&gt;
&lt;br /&gt;
; Re-Display the content of $sVar2&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar2: &amp;quot; &amp;amp; $sVar2)&lt;br /&gt;
&lt;br /&gt;
; Declare a function (its main utility is described later in Functions, we can see one here which is to create a Local scope)&lt;br /&gt;
Func MyFunc()&lt;br /&gt;
    ; Local scope&lt;br /&gt;
&lt;br /&gt;
    ; Display the content of $g_iVar1&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $g_iVar1: &amp;quot; &amp;amp; $g_iVar1)&lt;br /&gt;
&lt;br /&gt;
    ; Assign a Local variable the string &amp;quot;bar&amp;quot;, its scope is Local because it&#039;s use is restricted to the function&#039;s scope&lt;br /&gt;
    Local $sVar3 = &amp;quot;bar&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Display the content of $sVar3&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar3: &amp;quot; &amp;amp; $sVar3)&lt;br /&gt;
&lt;br /&gt;
    ; Return the $sVar3 content, it will be visible (if used) to the scope where the function is called&lt;br /&gt;
    Return $sVar3&lt;br /&gt;
EndFunc   ;==&amp;gt;MyFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Concerning the Dim keyword, its recommended usage is limited to empty an existing array (Example 1) or to redeclare a function parameter (Example 2).&lt;br /&gt;
&lt;br /&gt;
Example 1:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Include the Array UDF, it&#039;s needed here for the _ArrayDisplay function&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
; Assign a Local variable an array containing numbers with a size of 5&lt;br /&gt;
; Note than an array is 0 based, to access the first element the code is: $aiArray[0]&lt;br /&gt;
Local $aiArray[5] = [1, 2, 3, 4, 5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aiArray)&lt;br /&gt;
 &lt;br /&gt;
; Empty the array (and keep its size)&lt;br /&gt;
Dim $aiArray[5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aiArray)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Remark: The variable type of an emptied array is a string, every non initialized variable is a string.&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Call MyFunc with default parameters ($vParam1 = 0)&lt;br /&gt;
MyFunc()&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array containing integers&lt;br /&gt;
Local $aiArray[3] = [3, 4, 5]&lt;br /&gt;
; Call MyFunc with $aiArray as parameter ($vParam1 = $aiArray)&lt;br /&gt;
MyFunc($aiArray)&lt;br /&gt;
&lt;br /&gt;
Func MyFunc($vParam1 = 0)&lt;br /&gt;
    ; If $vParam1 is NOT an array then redeclare it to an array&lt;br /&gt;
    If Not IsArray($vParam1) Then&lt;br /&gt;
        Dim $vParam1[3] = [0, 1, 2]&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    ; Display the array&lt;br /&gt;
    _ArrayDisplay($vParam1)&lt;br /&gt;
EndFunc   ;==&amp;gt;MyFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the ReDim keyword, limit its use to resize an array when you want to keep its content:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Include the Array UDF, it&#039;s needed here for the _ArrayDisplay function&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
; Assign a Local variable an array containing numbers with a size of 5&lt;br /&gt;
; Note than an array is 0 based, to access the first element the code is: $aiArray[0]&lt;br /&gt;
Local $aArray[5] = [1, 2, 3, 4, 5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
 &lt;br /&gt;
; Resize the array (and keep its content)&lt;br /&gt;
ReDim $aArray[3]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why using Dim over Local/Global is not always a good option:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Dim $g_vVariableThatIsGlobal = &amp;quot;This is a variable that has &amp;quot;&amp;quot;Program Scope&amp;quot;&amp;quot; aka Global.&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;An example of why Dim can cause more problems than solve them.&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
Example()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, $g_vVariableThatIsGlobal) ; That looks alright to me as it displays the following text: This is a variable that has &amp;quot;Program Scope&amp;quot; aka Global&lt;br /&gt;
 &lt;br /&gt;
    Local $vReturn = SomeFunc() ; Call some random function&lt;br /&gt;
 &lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, $vReturn, $g_vVariableThatIsGlobal) ; The Global variable ($g_vVariableThatIsGlobal) changed because I totally forgot I had a duplicate variable name in &amp;quot;SomeFunc&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; This should create a variable in Local scope if the variable name doesn&amp;quot;t already exist&lt;br /&gt;
    ; For argument sake I totally forgot that I declared a variable already with the same name&lt;br /&gt;
    ; Well I only want this to be changed in the function and not the variable at the top of the script&lt;br /&gt;
    ; Should be OK right? Think again&lt;br /&gt;
    Dim $g_vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
    For $i = 1 To 10&lt;br /&gt;
        $g_vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $g_vVariableThatIsGlobal&lt;br /&gt;
    Next&lt;br /&gt;
    Return $g_vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;jumpsec1&amp;quot;&amp;gt;Declaring Global variables in a Function is never a good idea:&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling Example() first will initialise the Global variable $g_vVariableThatIsGlobal and therefore calling SomeFunc() won&#039;t return an error&lt;br /&gt;
; Now look at Example 2&lt;br /&gt;
Example()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script&lt;br /&gt;
    Global $g_vVariableThatIsGlobal = &#039;This is a variable that has &#039;&#039;File Scope&#039;&#039; aka Global.&#039;&lt;br /&gt;
    SomeFunc()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $g_vVariableThatIsGlobal) ; As the variable was initialised this will not return an error&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling SomeFunc() first will bypass the Global variable $g_vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $g_vVariableThatIsGlobal contains&lt;br /&gt;
SomeFunc()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script&lt;br /&gt;
    Global $g_vVariableThatIsGlobal = &#039;This is a variable that has &#039;&#039;File Scope&#039;&#039; aka Global.&#039;&lt;br /&gt;
    SomeFunc()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $g_vVariableThatIsGlobal) ; As the variable wasn&#039;t initialised this will return an error of &amp;quot;variable used without being declared.&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declaring variables in loops (For, While, Do etc..) can have an affect on efficiency:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables inside loops should be avoided as the variable is re-declared on each repetition&lt;br /&gt;
For $i = 1 To 10 ; $i is in &#039;loop scope.&#039;&lt;br /&gt;
    Local $iInt = $i&lt;br /&gt;
Next&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $iInt) ; This will display 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables outside of loops is more efficient in the long run&lt;br /&gt;
Local $iInt = 0&lt;br /&gt;
For $i = 1 To 10 ; $i is in &#039;loop scope.&#039;&lt;br /&gt;
    $iInt = $i&lt;br /&gt;
Next&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $iInt) ; This will display 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no requirement to declare the iteration count variable in a loop:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Correct&lt;br /&gt;
Local Const $iCount = 99&lt;br /&gt;
Local $aArray[$iCount]&lt;br /&gt;
For $i = 0 To UBound($iCount) - 1 ; $i is only used in the loop, so there is no requirement to declare it&lt;br /&gt;
    $aArray[$i] = $i&lt;br /&gt;
Next&lt;br /&gt;
&lt;br /&gt;
; Incorrect&lt;br /&gt;
Local Const $iCount = 99&lt;br /&gt;
Local $aArray[$iCount]&lt;br /&gt;
Local $i ; This is only used to store the iteration count value in the loop and therefore doesn&#039;t need to be declared. &lt;br /&gt;
For $i = 0 To UBound($iCount) - 1&lt;br /&gt;
    $aArray[$i] = $i&lt;br /&gt;
Next&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
As you can see, there is the Const keyword in the example, we are going to talk about it.&lt;br /&gt;
&lt;br /&gt;
== Const, Static, Enum ==&lt;br /&gt;
&lt;br /&gt;
=== Const ===&lt;br /&gt;
We won&#039;t talk about the advantages of using a constant variable, they are neglibible (for your information, an AutoIt constant variable is marked as read-only and remains a read-only variable when compiled).&lt;br /&gt;
&lt;br /&gt;
The Const keyword may be used first by some of you to avoid re-assignments.&lt;br /&gt;
The best way to use them is for real static values, meaning that these values won&#039;t change regardless of the instance of the program.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Not recommended&lt;br /&gt;
Local Const $hGUI = GUICreate(&amp;quot;MyGUI&amp;quot;)&lt;br /&gt;
; The handle of the window is unique, it&#039;s generated by Windows and changes&lt;br /&gt;
&lt;br /&gt;
; Recommended&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Static ===&lt;br /&gt;
Static variables are the solution to global variables being used in only one function.&lt;br /&gt;
e.g: Retain variable data once returned from a Function and only use that variable in that particular Function.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 1&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 2&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 3&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; This initialises a Static variable in Local scope. When a variable is declared just in Local scope (within a Function,)&lt;br /&gt;
    ; it&#039;s destroyed when the Function ends/returns. This isn&#039;t the case for a Static variable. Also, the variable can&#039;t be&lt;br /&gt;
    ; accessed from anywhere else in the script apart from the Function it was declared in&lt;br /&gt;
    Local Static $vVariableThatIsStatic = 0&lt;br /&gt;
    Local $vVariableThatIsLocal = 0&lt;br /&gt;
    $vVariableThatIsLocal += 1 ; This will always be 1 as it is destroyed once returned from SomeFunc&lt;br /&gt;
    $vVariableThatIsStatic += 1 ; This will increase by 1&lt;br /&gt;
    MsgBox(4096, $vVariableThatIsLocal, $vVariableThatIsStatic)&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enum ===&lt;br /&gt;
This statement is often practical in certain situations:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Create variables in Local scope and enumerate through the variables. Default is to start from 0&lt;br /&gt;
    Local Enum $eCat, $eDog, $eMouse, $eHamster ; $eHamster is equal to the value 3, not 4&lt;br /&gt;
&lt;br /&gt;
    ; Create an array in Local scope with 4 elements&lt;br /&gt;
    Local $aAnimalNames[4]&lt;br /&gt;
&lt;br /&gt;
    ; Assign each array element with the name of the respective animal. For example the name of the cat is Jasper&lt;br /&gt;
    $aAnimalNames[$eCat] = &#039;Jasper&#039; ; $eCat is equal to 0, similar to using $aAnimalNames[0]&lt;br /&gt;
    $aAnimalNames[$eDog] = &#039;Beethoven&#039; ; $eDog is equal to 1, similar to using $aAnimalNames[1]&lt;br /&gt;
    $aAnimalNames[$eMouse] = &#039;Pinky&#039; ; $eMouse is equal to 2, similar to using $aAnimalNames[2]&lt;br /&gt;
    $aAnimalNames[$eHamster] = &#039;Fidget&#039; ; $eHamster is equal to 3, similar to using $aAnimalNames[3]&lt;br /&gt;
&lt;br /&gt;
    ; Display the values of the array&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$aAnimalNames[$eCat] = &#039; &amp;amp; $aAnimalNames[$eCat] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eDog] = &#039; &amp;amp; $aAnimalNames[$eDog] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eMouse] = &#039; &amp;amp; $aAnimalNames[$eMouse] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eHamster] = &#039; &amp;amp; $aAnimalNames[$eHamster] &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Sometimes using this approach for accessing an element is more practical than using a numerical value, due to the fact changing the index value of&lt;br /&gt;
    ; the enum constant has no affect on it&#039;s position in the array. Therefore changing the location of $eCat in the array is as simple as changing the order&lt;br /&gt;
    ; it appears in the initial declaration e.g&lt;br /&gt;
&lt;br /&gt;
    ; Local Enum $eDog, $eMouse, $eCat, $eHamster&lt;br /&gt;
&lt;br /&gt;
    ; Now $eCat is the 2nd element in the array. If you were using numerical values, you would have to manually change all references of $aAnimalNames[0] to&lt;br /&gt;
    ; $aAnimalNames[2], as well as for the other elements which have now shifted&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Au3Check directive ==&lt;br /&gt;
As you may know (and we hope), the Au3Check tool checks your code for syntax errors, variables used without being declared etc. which is a good thing to fix your script.&lt;br /&gt;
&lt;br /&gt;
With the official custom directive used to check the helpfile examples/includes, you can apply the good coding practices listed above:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Magic Numbers ==&lt;br /&gt;
Magic numbers are arbitrary numbers interspersed throughout a program&#039;s source code which do not have an associated identifier. The downside to this is not being able to derive a meaning from the number. &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox(262144, &amp;quot;Magic Numbers&amp;quot;, &amp;quot;It&#039;s Adventure Time!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In this example, the magic number is 262144 with the identifier being $MB_TOPMOST according to the helpfile.&lt;br /&gt;
&lt;br /&gt;
The corrected example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox($MB_TOPMOST, &amp;quot;Magic Numbers&amp;quot;, &amp;quot;It&#039;s Adventure Time!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Imagine you&#039;re a new user to AutoIt and you come across this code, where would you find -3, -4 or -5 in the help file?&lt;br /&gt;
; Since AutoIt is relatively a new concept to you, your first thought isn&#039;t to search through all the include files, I mean&lt;br /&gt;
; why would you, the help file is there for a reason&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    GUICtrlCreateLabel(&#039;Why magic numbers are counter productive.&#039;, 5, 5)&lt;br /&gt;
    GUICtrlSetState(Default, 128) ; Does this hide, show or disable it?&lt;br /&gt;
    GUICtrlSetState(Default, 64) ; Does this hide, show or disable it?&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case -3 ; Doesn&#039;t really tell much about what it does&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
            Case -4, -5 ; Again, no idea what these are. MouseMove? MouseClick? Restore?&lt;br /&gt;
                MsgBox(4096, &#039;&#039;, &#039;Do something when this action takes place.&#039;)&lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Did you understand the numbers were these:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    GUICtrlCreateLabel(&#039;Why magic numbers are counter productive.&#039;, 5, 5)&lt;br /&gt;
    GUICtrlSetState(Default, $GUI_DISABLE) ; Better, this is documented in the help file&lt;br /&gt;
    GUICtrlSetState(Default, $GUI_ENABLE) ; Better, this is documented in the help file&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE ; Better, this is documented in the help file. Ah, it&#039;s the close action&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
            Case $GUI_EVENT_MINIMIZE, $GUI_EVENT_RESTORE ; Better, this is documented in the help file&lt;br /&gt;
                MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;Do something when this action takes place.&#039;) ; Better, this is documented in the help file&lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Magic_number_(programming) Magic number (programming)]&lt;br /&gt;
&lt;br /&gt;
== Include-once directive ==&lt;br /&gt;
This one is designed for standard includes and UDFs, it&#039;s highly recommended to use it.&lt;br /&gt;
&lt;br /&gt;
Those includes may be included in more than one script of your project because they are needed for some includes or your script itself.&lt;br /&gt;
In that case, the code will be duplicated which is not a good thing especially if you have (and it&#039;s mainly the case) constants declared in those files, in so far as the constants cannot be redeclared/reassigned; same thing for functions&lt;br /&gt;
&lt;br /&gt;
Put the directive in top of your UDF (library) to avoid itself to be included more than once :&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include-once&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13501</id>
		<title>Best coding practices</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13501"/>
		<updated>2016-07-20T20:14:37Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Const */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what are to be considered the best coding practices within AutoIt. These recommendations are based on accepted coding practices common to a number of other programming languages. You do not need to follow them, but it is recommended that you do.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: You must use AutoIt v3.3.10.0 or above to run the examples below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Using Functions ==&lt;br /&gt;
If a function sets the @error flag, you should always check it before using a return value - if @error indicates an error then the function return value is generally undefined.&lt;br /&gt;
&lt;br /&gt;
Learn more about using Functions by reading &amp;quot;[https://www.autoitscript.com/autoit3/docs/function_notes.htm Function Notes]&amp;quot; from HelpFile.&lt;br /&gt;
&lt;br /&gt;
== Names of Variables ==&lt;br /&gt;
The variable naming convention used in AutoIt is based on [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation]. The prefix defines the logical data type rather than the physical data type: in this way, it gives a hint as to what the variable&#039;s purpose is, or what it represents. The prefix does not encode the actual data type: this occurs during assignment. See the table below for accepted standards.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! example&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $bBool = True&lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $dBinary = Binary(&amp;quot;0x80000000&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452 &lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $hGUI = GUICreate(&amp;quot;My GUI&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlID || $idButton_Ok = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;Hello world&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|v || Variant || $vData = ClipGet()&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! dollar prefix !! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| $ || a || h || Handles&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a local variable the integer 7&lt;br /&gt;
Local $iWeekDays = 7&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable the value of Pi&lt;br /&gt;
Local $fPi = 3.14159265358979&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable an array of strings&lt;br /&gt;
Local $asArray[7] = [&#039;mon&#039;, &#039;tue&#039;, &#039;wed&#039;, &#039;thu&#039;, &#039;fri&#039;, &#039;sat&#039;, &#039;sun&#039;]&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable an array of numbers&lt;br /&gt;
Local $anArray[4] = [0, 0.25, 3 / 4, 12]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variable Initialization ==&lt;br /&gt;
When initializing variables there are several points to consider. It is bad practice to hog memory by assigning data which is not immediately required. It is therefore recommended that you declare and initialize variables immediately prior to use. If you wish to assign a default value to a variable which you intend to overwrite later, then the data should be of the same (or the most logical representation of its) type and use as little memory as possible.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Inconsistent data types are considered bad&lt;br /&gt;
Local $iInteger = &amp;quot;0&amp;quot;&lt;br /&gt;
Local $sString = False&lt;br /&gt;
&lt;br /&gt;
; Correct initialization&lt;br /&gt;
Local $iInteger = 0&lt;br /&gt;
Local $sString = &#039;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the following table, recommended default values are shown for each data type. Some data types have more than one possibile default value which can be used for initialization.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Default Value !! covering type&lt;br /&gt;
|-&lt;br /&gt;
| Binary(&amp;quot;&amp;quot;) || $d&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot; || $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| 0 || $a, $h, $i, $id, $m, $n, $o, $p, $t, $tag, $v&lt;br /&gt;
|-&lt;br /&gt;
| 0.0 || $f&lt;br /&gt;
|-&lt;br /&gt;
| Null || $o, $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| False (or True) || $b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Declare and initialize a variable with the recommended default value&lt;br /&gt;
Local $vUndefined = Null ; This does not require much memory&lt;br /&gt;
&lt;br /&gt;
; Some time later:&lt;br /&gt;
$vUndefined = 0xB0AD1CEA ; Assign an appropriate value as and when needed&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To reduce bloat, multiple variables can be declared on a single line. When declaring multiple variables on the same line, it is generally recommended that you stick to declaring one data type on each line. The intention here is to make the code easier to follow and manage in a future, however the best layout will vary according to circumstance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Not recommended&lt;br /&gt;
Local $sString = &amp;quot;&amp;quot;, $iInteger = 0, $asArray = [&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;] ; Mixed data types&lt;br /&gt;
&lt;br /&gt;
; Recommended&lt;br /&gt;
Local $iLeft = 10, $iTop = 10 ; Integers&lt;br /&gt;
Local $idButton_Go = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop) ; ControlIds&lt;br /&gt;
Local $idButton_Quit = GUICtrlCreateButton(&amp;quot;Quit&amp;quot;, 50, 10) ; ControlIds&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some languages it is essential to initialize variables on declaration, but this is not the case with AutoIt. Regarding data type, variables declared without being initialized should be considered as being undefined.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
Variables should also be named according to their scope.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Global UDF variable !! Global variable !! Local variable&lt;br /&gt;
|-&lt;br /&gt;
| $__g_iSomeVar || $g_iSomeVar || $iSomeVar&lt;br /&gt;
|}&lt;br /&gt;
With this method, you will avoid unwanted re-assignments.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Assign a Global variable the number 0&lt;br /&gt;
Global $iSomeVar1 = 0&lt;br /&gt;
; Assign a Global variable the number 5&lt;br /&gt;
Global $g_iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
SomeFunc()&lt;br /&gt;
&lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; Assign Local variables respectively the numbers 3 and 4&lt;br /&gt;
    Local $iSomeVar1 = 3, $iSomeVar2 = 4&lt;br /&gt;
&lt;br /&gt;
    ; Note: The user inadvertently re-assigned the global variable $iSomeVar1, because this one is not named as &amp;quot;global&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $iSomeVar1&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $iSomeVar1: &amp;quot; &amp;amp; $iSomeVar1)&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $iSomeVar2&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $iSomeVar2: &amp;quot; &amp;amp; $iSomeVar2)&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $g_iSomeVar2&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $g_iSomeVar2: &amp;quot; &amp;amp; $g_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&amp;lt;br /&amp;gt;Always declare your global variables in the global scope, not in a function. It will prevent another function from using it before its declaration and the declaration is implicit (see [[#jumpsec1|examples]]).&lt;br /&gt;
&lt;br /&gt;
* A variable declared locally (with the Local keyword), has a visibility which depends of the scope where it&#039;s declared.&lt;br /&gt;
:Declaration in the global scope: the variable is visible everywhere; declare it as Local if this one is only to be used in the same scope, i.e. outside of any functions. A variable declared as Local in the Global scope is still a Global variable, it&#039;s only for the sake of code clarity that you&#039;d use the Local declaration in the Global scope.&lt;br /&gt;
:Declaration in a function: the variable is visible by the function itself and nowhere else.&lt;br /&gt;
&lt;br /&gt;
Structure of a code scope:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Global scope&lt;br /&gt;
&lt;br /&gt;
; Include the Constants file, it contains various constants; it&#039;s needed here for the $MB_SYSTEMMODAL flag of the MsgBox function)&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; This scope is either Global or Local, depending on where you use the variables&lt;br /&gt;
&lt;br /&gt;
; Assign a Global variable the number 0 (which corresponds to an initialization of a variable number), its scope is Global because it&#039;s used in at least one function&lt;br /&gt;
Global $g_iVar1 = 0&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the string &amp;quot;foo&amp;quot;, its scope is Local because it&#039;s use is used only in this scope&lt;br /&gt;
Local $sVar2 = &amp;quot;foo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; Display the content of $sVar2&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar2: &amp;quot; &amp;amp; $sVar2)&lt;br /&gt;
&lt;br /&gt;
; Re-assign a Local variable the string returned by the function MyFunc&lt;br /&gt;
$sVar2 = MyFunc()&lt;br /&gt;
&lt;br /&gt;
; Re-Display the content of $sVar2&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar2: &amp;quot; &amp;amp; $sVar2)&lt;br /&gt;
&lt;br /&gt;
; Declare a function (its main utility is described later in Functions, we can see one here which is to create a Local scope)&lt;br /&gt;
Func MyFunc()&lt;br /&gt;
    ; Local scope&lt;br /&gt;
&lt;br /&gt;
    ; Display the content of $g_iVar1&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $g_iVar1: &amp;quot; &amp;amp; $g_iVar1)&lt;br /&gt;
&lt;br /&gt;
    ; Assign a Local variable the string &amp;quot;bar&amp;quot;, its scope is Local because it&#039;s use is restricted to the function&#039;s scope&lt;br /&gt;
    Local $sVar3 = &amp;quot;bar&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Display the content of $sVar3&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar3: &amp;quot; &amp;amp; $sVar3)&lt;br /&gt;
&lt;br /&gt;
    ; Return the $sVar3 content, it will be visible (if used) to the scope where the function is called&lt;br /&gt;
    Return $sVar3&lt;br /&gt;
EndFunc   ;==&amp;gt;MyFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Concerning the Dim keyword, its recommended usage is limited to empty an existing array (Example 1) or to redeclare a function parameter (Example 2).&lt;br /&gt;
&lt;br /&gt;
Example 1:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Include the Array UDF, it&#039;s needed here for the _ArrayDisplay function&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
; Assign a Local variable an array containing numbers with a size of 5&lt;br /&gt;
; Note than an array is 0 based, to access the first element the code is: $aiArray[0]&lt;br /&gt;
Local $aiArray[5] = [1, 2, 3, 4, 5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aiArray)&lt;br /&gt;
 &lt;br /&gt;
; Empty the array (and keep its size)&lt;br /&gt;
Dim $aiArray[5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aiArray)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Remark: The variable type of an emptied array is a string, every non initialized variable is a string.&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Call MyFunc with default parameters ($vParam1 = 0)&lt;br /&gt;
MyFunc()&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array containing integers&lt;br /&gt;
Local $aiArray[3] = [3, 4, 5]&lt;br /&gt;
; Call MyFunc with $aiArray as parameter ($vParam1 = $aiArray)&lt;br /&gt;
MyFunc($aiArray)&lt;br /&gt;
&lt;br /&gt;
Func MyFunc($vParam1 = 0)&lt;br /&gt;
    ; If $vParam1 is NOT an array then redeclare it to an array&lt;br /&gt;
    If Not IsArray($vParam1) Then&lt;br /&gt;
        Dim $vParam1[3] = [0, 1, 2]&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    ; Display the array&lt;br /&gt;
    _ArrayDisplay($vParam1)&lt;br /&gt;
EndFunc   ;==&amp;gt;MyFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the ReDim keyword, limit its use to resize an array when you want to keep its content:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Include the Array UDF, it&#039;s needed here for the _ArrayDisplay function&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
; Assign a Local variable an array containing numbers with a size of 5&lt;br /&gt;
; Note than an array is 0 based, to access the first element the code is: $aiArray[0]&lt;br /&gt;
Local $aArray[5] = [1, 2, 3, 4, 5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
 &lt;br /&gt;
; Resize the array (and keep its content)&lt;br /&gt;
ReDim $aArray[3]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why using Dim over Local/Global is not always a good option:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Dim $g_vVariableThatIsGlobal = &amp;quot;This is a variable that has &amp;quot;&amp;quot;Program Scope&amp;quot;&amp;quot; aka Global.&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;An example of why Dim can cause more problems than solve them.&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
Example()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, $g_vVariableThatIsGlobal) ; That looks alright to me as it displays the following text: This is a variable that has &amp;quot;Program Scope&amp;quot; aka Global&lt;br /&gt;
 &lt;br /&gt;
    Local $vReturn = SomeFunc() ; Call some random function&lt;br /&gt;
 &lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, $vReturn, $g_vVariableThatIsGlobal) ; The Global variable ($g_vVariableThatIsGlobal) changed because I totally forgot I had a duplicate variable name in &amp;quot;SomeFunc&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; This should create a variable in Local scope if the variable name doesn&amp;quot;t already exist&lt;br /&gt;
    ; For argument sake I totally forgot that I declared a variable already with the same name&lt;br /&gt;
    ; Well I only want this to be changed in the function and not the variable at the top of the script&lt;br /&gt;
    ; Should be OK right? Think again&lt;br /&gt;
    Dim $g_vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
    For $i = 1 To 10&lt;br /&gt;
        $g_vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $g_vVariableThatIsGlobal&lt;br /&gt;
    Next&lt;br /&gt;
    Return $g_vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;jumpsec1&amp;quot;&amp;gt;Declaring Global variables in a Function is never a good idea:&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling Example() first will initialise the Global variable $g_vVariableThatIsGlobal and therefore calling SomeFunc() won&#039;t return an error&lt;br /&gt;
; Now look at Example 2&lt;br /&gt;
Example()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script&lt;br /&gt;
    Global $g_vVariableThatIsGlobal = &#039;This is a variable that has &#039;&#039;File Scope&#039;&#039; aka Global.&#039;&lt;br /&gt;
    SomeFunc()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $g_vVariableThatIsGlobal) ; As the variable was initialised this will not return an error&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling SomeFunc() first will bypass the Global variable $g_vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $g_vVariableThatIsGlobal contains&lt;br /&gt;
SomeFunc()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script&lt;br /&gt;
    Global $g_vVariableThatIsGlobal = &#039;This is a variable that has &#039;&#039;File Scope&#039;&#039; aka Global.&#039;&lt;br /&gt;
    SomeFunc()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $g_vVariableThatIsGlobal) ; As the variable wasn&#039;t initialised this will return an error of &amp;quot;variable used without being declared.&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declaring variables in loops (For, While, Do etc..) can have an affect on efficiency:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables inside loops should be avoided as the variable is re-declared on each repetition&lt;br /&gt;
For $i = 1 To 10 ; $i is in &#039;loop scope.&#039;&lt;br /&gt;
    Local $iInt = $i&lt;br /&gt;
Next&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $iInt) ; This will display 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables outside of loops is more efficient in the long run&lt;br /&gt;
Local $iInt = 0&lt;br /&gt;
For $i = 1 To 10 ; $i is in &#039;loop scope.&#039;&lt;br /&gt;
    $iInt = $i&lt;br /&gt;
Next&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $iInt) ; This will display 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no requirement to declare the iteration count variable in a loop:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Correct&lt;br /&gt;
Local Const $iCount = 99&lt;br /&gt;
Local $aArray[$iCount]&lt;br /&gt;
For $i = 0 To UBound($iCount) - 1 ; $i is only used in the loop, so there is no requirement to declare it&lt;br /&gt;
    $aArray[$i] = $i&lt;br /&gt;
Next&lt;br /&gt;
&lt;br /&gt;
; Incorrect&lt;br /&gt;
Local Const $iCount = 99&lt;br /&gt;
Local $aArray[$iCount]&lt;br /&gt;
Local $i ; This is only used to store the iteration count value in the loop and therefore doesn&#039;t need to be declared. &lt;br /&gt;
For $i = 0 To UBound($iCount) - 1&lt;br /&gt;
    $aArray[$i] = $i&lt;br /&gt;
Next&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
As you can see, there is the Const keyword in the example, we are going to talk about it.&lt;br /&gt;
&lt;br /&gt;
== Const, Static, Enum ==&lt;br /&gt;
&lt;br /&gt;
=== Const ===&lt;br /&gt;
We won&#039;t talk about the advantages of using a constant variable, they are neglibible (for your information, an AutoIt constant variable is marked as read-only and remains a read-only variable when compiled).&lt;br /&gt;
&lt;br /&gt;
The Const keyword may be used first by some of you to avoid re-assignments.&lt;br /&gt;
The best way to use them is for real static values, meaning that these values won&#039;t change regardless of the instance of the program.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Not recommended&lt;br /&gt;
Local Const $hGUI = GUICreate(&amp;quot;MyGUI&amp;quot;)&lt;br /&gt;
; The handle of the window is unique, it&#039;s generated by Windows and changes&lt;br /&gt;
&lt;br /&gt;
; Recommended&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Static ===&lt;br /&gt;
Static variables are the solution to the global variables used in only one function.&lt;br /&gt;
e.g: Retain variable data once returned from a Function and only use that variable in that particular Function.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 1&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 2&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 3&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; This initialises a Static variable in Local scope. When a variable is declared just in Local scope (within a Function,)&lt;br /&gt;
    ; it&#039;s destroyed when the Function ends/returns. This isn&#039;t the case for a Static variable. The variable can&#039;t be&lt;br /&gt;
    ; accessed from anywhere else in the script apart from the Function it was declared in&lt;br /&gt;
    Local Static $vVariableThatIsStatic = 0&lt;br /&gt;
    Local $vVariableThatIsLocal = 0&lt;br /&gt;
    $vVariableThatIsLocal += 1 ; This will always be 1 as it was destroyed once returned from SomeFunc&lt;br /&gt;
    $vVariableThatIsStatic += 1 ; This will increase by 1&lt;br /&gt;
    MsgBox(4096, $vVariableThatIsLocal, $vVariableThatIsStatic)&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enum ===&lt;br /&gt;
This statement is often practical in certain situations:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Create variables in Local scope and enumerate through the variables. Default is to start from 0&lt;br /&gt;
    Local Enum $eCat, $eDog, $eMouse, $eHamster ; $eHamster is equal to the value 3, not 4&lt;br /&gt;
&lt;br /&gt;
    ; Create an array in Local scope with 4 elements&lt;br /&gt;
    Local $aAnimalNames[4]&lt;br /&gt;
&lt;br /&gt;
    ; Assign each array element with the name of the respective animal. For example the name of the cat is Jasper&lt;br /&gt;
    $aAnimalNames[$eCat] = &#039;Jasper&#039; ; $eCat is equal to 0, similar to using $aAnimalNames[0]&lt;br /&gt;
    $aAnimalNames[$eDog] = &#039;Beethoven&#039; ; $eDog is equal to 1, similar to using $aAnimalNames[1]&lt;br /&gt;
    $aAnimalNames[$eMouse] = &#039;Pinky&#039; ; $eMouse is equal to 2, similar to using $aAnimalNames[2]&lt;br /&gt;
    $aAnimalNames[$eHamster] = &#039;Fidget&#039; ; $eHamster is equal to 3, similar to using $aAnimalNames[3]&lt;br /&gt;
&lt;br /&gt;
    ; Display the values of the array&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$aAnimalNames[$eCat] = &#039; &amp;amp; $aAnimalNames[$eCat] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eDog] = &#039; &amp;amp; $aAnimalNames[$eDog] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eMouse] = &#039; &amp;amp; $aAnimalNames[$eMouse] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eHamster] = &#039; &amp;amp; $aAnimalNames[$eHamster] &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Sometimes using this approach for accessing an element is more practical than using a numerical value, due to the fact changing the index value of&lt;br /&gt;
    ; the enum constant has no affect on it&#039;s position in the array. Therefore changing the location of $eCat in the array is as simple as changing the order&lt;br /&gt;
    ; it appears in the initial declaration e.g&lt;br /&gt;
&lt;br /&gt;
    ; Local Enum $eDog, $eMouse, $eCat, $eHamster&lt;br /&gt;
&lt;br /&gt;
    ; Now $eCat is the 2nd element in the array. If you were using numerical values, you would have to manually change all references of $aAnimalNames[0] to&lt;br /&gt;
    ; $aAnimalNames[2], as well as for the other elements which have now shifted&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Au3Check directive ==&lt;br /&gt;
As you may know (and we hope), the Au3Check tool checks your code for syntax errors, variables used without being declared etc. which is a good thing to fix your script.&lt;br /&gt;
&lt;br /&gt;
With the official custom directive used to check the helpfile examples/includes, you can apply the good coding practices listed above:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Magic Numbers ==&lt;br /&gt;
Magic numbers are arbitrary numbers interspersed throughout a program&#039;s source code which do not have an associated identifier. The downside to this is not being able to derive a meaning from the number. &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox(262144, &amp;quot;Magic Numbers&amp;quot;, &amp;quot;It&#039;s Adventure Time!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In this example, the magic number is 262144 with the identifier being $MB_TOPMOST according to the helpfile.&lt;br /&gt;
&lt;br /&gt;
The corrected example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox($MB_TOPMOST, &amp;quot;Magic Numbers&amp;quot;, &amp;quot;It&#039;s Adventure Time!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Imagine you&#039;re a new user to AutoIt and you come across this code, where would you find -3, -4 or -5 in the help file?&lt;br /&gt;
; Since AutoIt is relatively a new concept to you, your first thought isn&#039;t to search through all the include files, I mean&lt;br /&gt;
; why would you, the help file is there for a reason&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    GUICtrlCreateLabel(&#039;Why magic numbers are counter productive.&#039;, 5, 5)&lt;br /&gt;
    GUICtrlSetState(Default, 128) ; Does this hide, show or disable it?&lt;br /&gt;
    GUICtrlSetState(Default, 64) ; Does this hide, show or disable it?&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case -3 ; Doesn&#039;t really tell much about what it does&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
            Case -4, -5 ; Again, no idea what these are. MouseMove? MouseClick? Restore?&lt;br /&gt;
                MsgBox(4096, &#039;&#039;, &#039;Do something when this action takes place.&#039;)&lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Did you understand the numbers were these:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    GUICtrlCreateLabel(&#039;Why magic numbers are counter productive.&#039;, 5, 5)&lt;br /&gt;
    GUICtrlSetState(Default, $GUI_DISABLE) ; Better, this is documented in the help file&lt;br /&gt;
    GUICtrlSetState(Default, $GUI_ENABLE) ; Better, this is documented in the help file&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE ; Better, this is documented in the help file. Ah, it&#039;s the close action&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
            Case $GUI_EVENT_MINIMIZE, $GUI_EVENT_RESTORE ; Better, this is documented in the help file&lt;br /&gt;
                MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;Do something when this action takes place.&#039;) ; Better, this is documented in the help file&lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Magic_number_(programming) Magic number (programming)]&lt;br /&gt;
&lt;br /&gt;
== Include-once directive ==&lt;br /&gt;
This one is designed for standard includes and UDFs, it&#039;s highly recommended to use it.&lt;br /&gt;
&lt;br /&gt;
Those includes may be included in more than one script of your project because they are needed for some includes or your script itself.&lt;br /&gt;
In that case, the code will be duplicated which is not a good thing especially if you have (and it&#039;s mainly the case) constants declared in those files, in so far as the constants cannot be redeclared/reassigned; same thing for functions&lt;br /&gt;
&lt;br /&gt;
Put the directive in top of your UDF (library) to avoid itself to be included more than once :&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include-once&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13500</id>
		<title>Best coding practices</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13500"/>
		<updated>2016-07-20T20:11:30Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Scopes of Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what are to be considered the best coding practices within AutoIt. These recommendations are based on accepted coding practices common to a number of other programming languages. You do not need to follow them, but it is recommended that you do.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: You must use AutoIt v3.3.10.0 or above to run the examples below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Using Functions ==&lt;br /&gt;
If a function sets the @error flag, you should always check it before using a return value - if @error indicates an error then the function return value is generally undefined.&lt;br /&gt;
&lt;br /&gt;
Learn more about using Functions by reading &amp;quot;[https://www.autoitscript.com/autoit3/docs/function_notes.htm Function Notes]&amp;quot; from HelpFile.&lt;br /&gt;
&lt;br /&gt;
== Names of Variables ==&lt;br /&gt;
The variable naming convention used in AutoIt is based on [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation]. The prefix defines the logical data type rather than the physical data type: in this way, it gives a hint as to what the variable&#039;s purpose is, or what it represents. The prefix does not encode the actual data type: this occurs during assignment. See the table below for accepted standards.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! example&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $bBool = True&lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $dBinary = Binary(&amp;quot;0x80000000&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452 &lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $hGUI = GUICreate(&amp;quot;My GUI&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlID || $idButton_Ok = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;Hello world&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|v || Variant || $vData = ClipGet()&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! dollar prefix !! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| $ || a || h || Handles&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a local variable the integer 7&lt;br /&gt;
Local $iWeekDays = 7&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable the value of Pi&lt;br /&gt;
Local $fPi = 3.14159265358979&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable an array of strings&lt;br /&gt;
Local $asArray[7] = [&#039;mon&#039;, &#039;tue&#039;, &#039;wed&#039;, &#039;thu&#039;, &#039;fri&#039;, &#039;sat&#039;, &#039;sun&#039;]&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable an array of numbers&lt;br /&gt;
Local $anArray[4] = [0, 0.25, 3 / 4, 12]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variable Initialization ==&lt;br /&gt;
When initializing variables there are several points to consider. It is bad practice to hog memory by assigning data which is not immediately required. It is therefore recommended that you declare and initialize variables immediately prior to use. If you wish to assign a default value to a variable which you intend to overwrite later, then the data should be of the same (or the most logical representation of its) type and use as little memory as possible.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Inconsistent data types are considered bad&lt;br /&gt;
Local $iInteger = &amp;quot;0&amp;quot;&lt;br /&gt;
Local $sString = False&lt;br /&gt;
&lt;br /&gt;
; Correct initialization&lt;br /&gt;
Local $iInteger = 0&lt;br /&gt;
Local $sString = &#039;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the following table, recommended default values are shown for each data type. Some data types have more than one possibile default value which can be used for initialization.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Default Value !! covering type&lt;br /&gt;
|-&lt;br /&gt;
| Binary(&amp;quot;&amp;quot;) || $d&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot; || $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| 0 || $a, $h, $i, $id, $m, $n, $o, $p, $t, $tag, $v&lt;br /&gt;
|-&lt;br /&gt;
| 0.0 || $f&lt;br /&gt;
|-&lt;br /&gt;
| Null || $o, $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| False (or True) || $b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Declare and initialize a variable with the recommended default value&lt;br /&gt;
Local $vUndefined = Null ; This does not require much memory&lt;br /&gt;
&lt;br /&gt;
; Some time later:&lt;br /&gt;
$vUndefined = 0xB0AD1CEA ; Assign an appropriate value as and when needed&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To reduce bloat, multiple variables can be declared on a single line. When declaring multiple variables on the same line, it is generally recommended that you stick to declaring one data type on each line. The intention here is to make the code easier to follow and manage in a future, however the best layout will vary according to circumstance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Not recommended&lt;br /&gt;
Local $sString = &amp;quot;&amp;quot;, $iInteger = 0, $asArray = [&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;] ; Mixed data types&lt;br /&gt;
&lt;br /&gt;
; Recommended&lt;br /&gt;
Local $iLeft = 10, $iTop = 10 ; Integers&lt;br /&gt;
Local $idButton_Go = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop) ; ControlIds&lt;br /&gt;
Local $idButton_Quit = GUICtrlCreateButton(&amp;quot;Quit&amp;quot;, 50, 10) ; ControlIds&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some languages it is essential to initialize variables on declaration, but this is not the case with AutoIt. Regarding data type, variables declared without being initialized should be considered as being undefined.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
Variables should also be named according to their scope.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Global UDF variable !! Global variable !! Local variable&lt;br /&gt;
|-&lt;br /&gt;
| $__g_iSomeVar || $g_iSomeVar || $iSomeVar&lt;br /&gt;
|}&lt;br /&gt;
With this method, you will avoid unwanted re-assignments.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Assign a Global variable the number 0&lt;br /&gt;
Global $iSomeVar1 = 0&lt;br /&gt;
; Assign a Global variable the number 5&lt;br /&gt;
Global $g_iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
SomeFunc()&lt;br /&gt;
&lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; Assign Local variables respectively the numbers 3 and 4&lt;br /&gt;
    Local $iSomeVar1 = 3, $iSomeVar2 = 4&lt;br /&gt;
&lt;br /&gt;
    ; Note: The user inadvertently re-assigned the global variable $iSomeVar1, because this one is not named as &amp;quot;global&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $iSomeVar1&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $iSomeVar1: &amp;quot; &amp;amp; $iSomeVar1)&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $iSomeVar2&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $iSomeVar2: &amp;quot; &amp;amp; $iSomeVar2)&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $g_iSomeVar2&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $g_iSomeVar2: &amp;quot; &amp;amp; $g_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&amp;lt;br /&amp;gt;Always declare your global variables in the global scope, not in a function. It will prevent another function from using it before its declaration and the declaration is implicit (see [[#jumpsec1|examples]]).&lt;br /&gt;
&lt;br /&gt;
* A variable declared locally (with the Local keyword), has a visibility which depends of the scope where it&#039;s declared.&lt;br /&gt;
:Declaration in the global scope: the variable is visible everywhere; declare it as Local if this one is only to be used in the same scope, i.e. outside of any functions. A variable declared as Local in the Global scope is still a Global variable, it&#039;s only for the sake of code clarity that you&#039;d use the Local declaration in the Global scope.&lt;br /&gt;
:Declaration in a function: the variable is visible by the function itself and nowhere else.&lt;br /&gt;
&lt;br /&gt;
Structure of a code scope:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Global scope&lt;br /&gt;
&lt;br /&gt;
; Include the Constants file, it contains various constants; it&#039;s needed here for the $MB_SYSTEMMODAL flag of the MsgBox function)&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; This scope is either Global or Local, depending on where you use the variables&lt;br /&gt;
&lt;br /&gt;
; Assign a Global variable the number 0 (which corresponds to an initialization of a variable number), its scope is Global because it&#039;s used in at least one function&lt;br /&gt;
Global $g_iVar1 = 0&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the string &amp;quot;foo&amp;quot;, its scope is Local because it&#039;s use is used only in this scope&lt;br /&gt;
Local $sVar2 = &amp;quot;foo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; Display the content of $sVar2&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar2: &amp;quot; &amp;amp; $sVar2)&lt;br /&gt;
&lt;br /&gt;
; Re-assign a Local variable the string returned by the function MyFunc&lt;br /&gt;
$sVar2 = MyFunc()&lt;br /&gt;
&lt;br /&gt;
; Re-Display the content of $sVar2&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar2: &amp;quot; &amp;amp; $sVar2)&lt;br /&gt;
&lt;br /&gt;
; Declare a function (its main utility is described later in Functions, we can see one here which is to create a Local scope)&lt;br /&gt;
Func MyFunc()&lt;br /&gt;
    ; Local scope&lt;br /&gt;
&lt;br /&gt;
    ; Display the content of $g_iVar1&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $g_iVar1: &amp;quot; &amp;amp; $g_iVar1)&lt;br /&gt;
&lt;br /&gt;
    ; Assign a Local variable the string &amp;quot;bar&amp;quot;, its scope is Local because it&#039;s use is restricted to the function&#039;s scope&lt;br /&gt;
    Local $sVar3 = &amp;quot;bar&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Display the content of $sVar3&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar3: &amp;quot; &amp;amp; $sVar3)&lt;br /&gt;
&lt;br /&gt;
    ; Return the $sVar3 content, it will be visible (if used) to the scope where the function is called&lt;br /&gt;
    Return $sVar3&lt;br /&gt;
EndFunc   ;==&amp;gt;MyFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Concerning the Dim keyword, its recommended usage is limited to empty an existing array (Example 1) or to redeclare a function parameter (Example 2).&lt;br /&gt;
&lt;br /&gt;
Example 1:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Include the Array UDF, it&#039;s needed here for the _ArrayDisplay function&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
; Assign a Local variable an array containing numbers with a size of 5&lt;br /&gt;
; Note than an array is 0 based, to access the first element the code is: $aiArray[0]&lt;br /&gt;
Local $aiArray[5] = [1, 2, 3, 4, 5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aiArray)&lt;br /&gt;
 &lt;br /&gt;
; Empty the array (and keep its size)&lt;br /&gt;
Dim $aiArray[5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aiArray)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Remark: The variable type of an emptied array is a string, every non initialized variable is a string.&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Call MyFunc with default parameters ($vParam1 = 0)&lt;br /&gt;
MyFunc()&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array containing integers&lt;br /&gt;
Local $aiArray[3] = [3, 4, 5]&lt;br /&gt;
; Call MyFunc with $aiArray as parameter ($vParam1 = $aiArray)&lt;br /&gt;
MyFunc($aiArray)&lt;br /&gt;
&lt;br /&gt;
Func MyFunc($vParam1 = 0)&lt;br /&gt;
    ; If $vParam1 is NOT an array then redeclare it to an array&lt;br /&gt;
    If Not IsArray($vParam1) Then&lt;br /&gt;
        Dim $vParam1[3] = [0, 1, 2]&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    ; Display the array&lt;br /&gt;
    _ArrayDisplay($vParam1)&lt;br /&gt;
EndFunc   ;==&amp;gt;MyFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the ReDim keyword, limit its use to resize an array when you want to keep its content:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Include the Array UDF, it&#039;s needed here for the _ArrayDisplay function&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
; Assign a Local variable an array containing numbers with a size of 5&lt;br /&gt;
; Note than an array is 0 based, to access the first element the code is: $aiArray[0]&lt;br /&gt;
Local $aArray[5] = [1, 2, 3, 4, 5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
 &lt;br /&gt;
; Resize the array (and keep its content)&lt;br /&gt;
ReDim $aArray[3]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why using Dim over Local/Global is not always a good option:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Dim $g_vVariableThatIsGlobal = &amp;quot;This is a variable that has &amp;quot;&amp;quot;Program Scope&amp;quot;&amp;quot; aka Global.&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;An example of why Dim can cause more problems than solve them.&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
Example()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, $g_vVariableThatIsGlobal) ; That looks alright to me as it displays the following text: This is a variable that has &amp;quot;Program Scope&amp;quot; aka Global&lt;br /&gt;
 &lt;br /&gt;
    Local $vReturn = SomeFunc() ; Call some random function&lt;br /&gt;
 &lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, $vReturn, $g_vVariableThatIsGlobal) ; The Global variable ($g_vVariableThatIsGlobal) changed because I totally forgot I had a duplicate variable name in &amp;quot;SomeFunc&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; This should create a variable in Local scope if the variable name doesn&amp;quot;t already exist&lt;br /&gt;
    ; For argument sake I totally forgot that I declared a variable already with the same name&lt;br /&gt;
    ; Well I only want this to be changed in the function and not the variable at the top of the script&lt;br /&gt;
    ; Should be OK right? Think again&lt;br /&gt;
    Dim $g_vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
    For $i = 1 To 10&lt;br /&gt;
        $g_vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $g_vVariableThatIsGlobal&lt;br /&gt;
    Next&lt;br /&gt;
    Return $g_vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;jumpsec1&amp;quot;&amp;gt;Declaring Global variables in a Function is never a good idea:&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling Example() first will initialise the Global variable $g_vVariableThatIsGlobal and therefore calling SomeFunc() won&#039;t return an error&lt;br /&gt;
; Now look at Example 2&lt;br /&gt;
Example()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script&lt;br /&gt;
    Global $g_vVariableThatIsGlobal = &#039;This is a variable that has &#039;&#039;File Scope&#039;&#039; aka Global.&#039;&lt;br /&gt;
    SomeFunc()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $g_vVariableThatIsGlobal) ; As the variable was initialised this will not return an error&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling SomeFunc() first will bypass the Global variable $g_vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $g_vVariableThatIsGlobal contains&lt;br /&gt;
SomeFunc()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script&lt;br /&gt;
    Global $g_vVariableThatIsGlobal = &#039;This is a variable that has &#039;&#039;File Scope&#039;&#039; aka Global.&#039;&lt;br /&gt;
    SomeFunc()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $g_vVariableThatIsGlobal) ; As the variable wasn&#039;t initialised this will return an error of &amp;quot;variable used without being declared.&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declaring variables in loops (For, While, Do etc..) can have an affect on efficiency:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables inside loops should be avoided as the variable is re-declared on each repetition&lt;br /&gt;
For $i = 1 To 10 ; $i is in &#039;loop scope.&#039;&lt;br /&gt;
    Local $iInt = $i&lt;br /&gt;
Next&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $iInt) ; This will display 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables outside of loops is more efficient in the long run&lt;br /&gt;
Local $iInt = 0&lt;br /&gt;
For $i = 1 To 10 ; $i is in &#039;loop scope.&#039;&lt;br /&gt;
    $iInt = $i&lt;br /&gt;
Next&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $iInt) ; This will display 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no requirement to declare the iteration count variable in a loop:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Correct&lt;br /&gt;
Local Const $iCount = 99&lt;br /&gt;
Local $aArray[$iCount]&lt;br /&gt;
For $i = 0 To UBound($iCount) - 1 ; $i is only used in the loop, so there is no requirement to declare it&lt;br /&gt;
    $aArray[$i] = $i&lt;br /&gt;
Next&lt;br /&gt;
&lt;br /&gt;
; Incorrect&lt;br /&gt;
Local Const $iCount = 99&lt;br /&gt;
Local $aArray[$iCount]&lt;br /&gt;
Local $i ; This is only used to store the iteration count value in the loop and therefore doesn&#039;t need to be declared. &lt;br /&gt;
For $i = 0 To UBound($iCount) - 1&lt;br /&gt;
    $aArray[$i] = $i&lt;br /&gt;
Next&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
As you can see, there is the Const keyword in the example, we are going to talk about it.&lt;br /&gt;
&lt;br /&gt;
== Const, Static, Enum ==&lt;br /&gt;
&lt;br /&gt;
=== Const ===&lt;br /&gt;
We won&#039;t talk about the advantages of a constant variable, they are neglibible (for your information, an AutoIt constant variable is marked as read-only and remains a variable as read-only when compiled).&lt;br /&gt;
&lt;br /&gt;
The Const keyword may be used in a first by some of you to avoid re-assignments.&lt;br /&gt;
The best way to use them is not this last case, the constants should be used for real static variables, meaning that their value won&#039;t change regardless to the instance of the program.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Not recommended&lt;br /&gt;
Local Const $hGUI = GUICreate(&amp;quot;MyGUI&amp;quot;)&lt;br /&gt;
; The handle of the window is unique, it&#039;s generated by Windows and changes&lt;br /&gt;
&lt;br /&gt;
; Recommended&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Static ===&lt;br /&gt;
Static variables are the solution to the global variables used in only one function.&lt;br /&gt;
e.g: Retain variable data once returned from a Function and only use that variable in that particular Function.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 1&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 2&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 3&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; This initialises a Static variable in Local scope. When a variable is declared just in Local scope (within a Function,)&lt;br /&gt;
    ; it&#039;s destroyed when the Function ends/returns. This isn&#039;t the case for a Static variable. The variable can&#039;t be&lt;br /&gt;
    ; accessed from anywhere else in the script apart from the Function it was declared in&lt;br /&gt;
    Local Static $vVariableThatIsStatic = 0&lt;br /&gt;
    Local $vVariableThatIsLocal = 0&lt;br /&gt;
    $vVariableThatIsLocal += 1 ; This will always be 1 as it was destroyed once returned from SomeFunc&lt;br /&gt;
    $vVariableThatIsStatic += 1 ; This will increase by 1&lt;br /&gt;
    MsgBox(4096, $vVariableThatIsLocal, $vVariableThatIsStatic)&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enum ===&lt;br /&gt;
This statement is often practical in certain situations:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Create variables in Local scope and enumerate through the variables. Default is to start from 0&lt;br /&gt;
    Local Enum $eCat, $eDog, $eMouse, $eHamster ; $eHamster is equal to the value 3, not 4&lt;br /&gt;
&lt;br /&gt;
    ; Create an array in Local scope with 4 elements&lt;br /&gt;
    Local $aAnimalNames[4]&lt;br /&gt;
&lt;br /&gt;
    ; Assign each array element with the name of the respective animal. For example the name of the cat is Jasper&lt;br /&gt;
    $aAnimalNames[$eCat] = &#039;Jasper&#039; ; $eCat is equal to 0, similar to using $aAnimalNames[0]&lt;br /&gt;
    $aAnimalNames[$eDog] = &#039;Beethoven&#039; ; $eDog is equal to 1, similar to using $aAnimalNames[1]&lt;br /&gt;
    $aAnimalNames[$eMouse] = &#039;Pinky&#039; ; $eMouse is equal to 2, similar to using $aAnimalNames[2]&lt;br /&gt;
    $aAnimalNames[$eHamster] = &#039;Fidget&#039; ; $eHamster is equal to 3, similar to using $aAnimalNames[3]&lt;br /&gt;
&lt;br /&gt;
    ; Display the values of the array&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$aAnimalNames[$eCat] = &#039; &amp;amp; $aAnimalNames[$eCat] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eDog] = &#039; &amp;amp; $aAnimalNames[$eDog] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eMouse] = &#039; &amp;amp; $aAnimalNames[$eMouse] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eHamster] = &#039; &amp;amp; $aAnimalNames[$eHamster] &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Sometimes using this approach for accessing an element is more practical than using a numerical value, due to the fact changing the index value of&lt;br /&gt;
    ; the enum constant has no affect on it&#039;s position in the array. Therefore changing the location of $eCat in the array is as simple as changing the order&lt;br /&gt;
    ; it appears in the initial declaration e.g&lt;br /&gt;
&lt;br /&gt;
    ; Local Enum $eDog, $eMouse, $eCat, $eHamster&lt;br /&gt;
&lt;br /&gt;
    ; Now $eCat is the 2nd element in the array. If you were using numerical values, you would have to manually change all references of $aAnimalNames[0] to&lt;br /&gt;
    ; $aAnimalNames[2], as well as for the other elements which have now shifted&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Au3Check directive ==&lt;br /&gt;
As you may know (and we hope), the Au3Check tool checks your code for syntax errors, variables used without being declared etc. which is a good thing to fix your script.&lt;br /&gt;
&lt;br /&gt;
With the official custom directive used to check the helpfile examples/includes, you can apply the good coding practices listed above:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Magic Numbers ==&lt;br /&gt;
Magic numbers are arbitrary numbers interspersed throughout a program&#039;s source code which do not have an associated identifier. The downside to this is not being able to derive a meaning from the number. &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox(262144, &amp;quot;Magic Numbers&amp;quot;, &amp;quot;It&#039;s Adventure Time!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In this example, the magic number is 262144 with the identifier being $MB_TOPMOST according to the helpfile.&lt;br /&gt;
&lt;br /&gt;
The corrected example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox($MB_TOPMOST, &amp;quot;Magic Numbers&amp;quot;, &amp;quot;It&#039;s Adventure Time!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Imagine you&#039;re a new user to AutoIt and you come across this code, where would you find -3, -4 or -5 in the help file?&lt;br /&gt;
; Since AutoIt is relatively a new concept to you, your first thought isn&#039;t to search through all the include files, I mean&lt;br /&gt;
; why would you, the help file is there for a reason&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    GUICtrlCreateLabel(&#039;Why magic numbers are counter productive.&#039;, 5, 5)&lt;br /&gt;
    GUICtrlSetState(Default, 128) ; Does this hide, show or disable it?&lt;br /&gt;
    GUICtrlSetState(Default, 64) ; Does this hide, show or disable it?&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case -3 ; Doesn&#039;t really tell much about what it does&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
            Case -4, -5 ; Again, no idea what these are. MouseMove? MouseClick? Restore?&lt;br /&gt;
                MsgBox(4096, &#039;&#039;, &#039;Do something when this action takes place.&#039;)&lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Did you understand the numbers were these:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    GUICtrlCreateLabel(&#039;Why magic numbers are counter productive.&#039;, 5, 5)&lt;br /&gt;
    GUICtrlSetState(Default, $GUI_DISABLE) ; Better, this is documented in the help file&lt;br /&gt;
    GUICtrlSetState(Default, $GUI_ENABLE) ; Better, this is documented in the help file&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE ; Better, this is documented in the help file. Ah, it&#039;s the close action&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
            Case $GUI_EVENT_MINIMIZE, $GUI_EVENT_RESTORE ; Better, this is documented in the help file&lt;br /&gt;
                MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;Do something when this action takes place.&#039;) ; Better, this is documented in the help file&lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Magic_number_(programming) Magic number (programming)]&lt;br /&gt;
&lt;br /&gt;
== Include-once directive ==&lt;br /&gt;
This one is designed for standard includes and UDFs, it&#039;s highly recommended to use it.&lt;br /&gt;
&lt;br /&gt;
Those includes may be included in more than one script of your project because they are needed for some includes or your script itself.&lt;br /&gt;
In that case, the code will be duplicated which is not a good thing especially if you have (and it&#039;s mainly the case) constants declared in those files, in so far as the constants cannot be redeclared/reassigned; same thing for functions&lt;br /&gt;
&lt;br /&gt;
Put the directive in top of your UDF (library) to avoid itself to be included more than once :&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include-once&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13499</id>
		<title>Best coding practices</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13499"/>
		<updated>2016-07-20T19:46:44Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Names of Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what are to be considered the best coding practices within AutoIt. These recommendations are based on accepted coding practices common to a number of other programming languages. You do not need to follow them, but it is recommended that you do.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: You must use AutoIt v3.3.10.0 or above to run the examples below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Using Functions ==&lt;br /&gt;
If a function sets the @error flag, you should always check it before using a return value - if @error indicates an error then the function return value is generally undefined.&lt;br /&gt;
&lt;br /&gt;
Learn more about using Functions by reading &amp;quot;[https://www.autoitscript.com/autoit3/docs/function_notes.htm Function Notes]&amp;quot; from HelpFile.&lt;br /&gt;
&lt;br /&gt;
== Names of Variables ==&lt;br /&gt;
The variable naming convention used in AutoIt is based on [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation]. The prefix defines the logical data type rather than the physical data type: in this way, it gives a hint as to what the variable&#039;s purpose is, or what it represents. The prefix does not encode the actual data type: this occurs during assignment. See the table below for accepted standards.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! example&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $bBool = True&lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $dBinary = Binary(&amp;quot;0x80000000&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452 &lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $hGUI = GUICreate(&amp;quot;My GUI&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlID || $idButton_Ok = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;Hello world&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|v || Variant || $vData = ClipGet()&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! dollar prefix !! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| $ || a || h || Handles&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a local variable the integer 7&lt;br /&gt;
Local $iWeekDays = 7&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable the value of Pi&lt;br /&gt;
Local $fPi = 3.14159265358979&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable an array of strings&lt;br /&gt;
Local $asArray[7] = [&#039;mon&#039;, &#039;tue&#039;, &#039;wed&#039;, &#039;thu&#039;, &#039;fri&#039;, &#039;sat&#039;, &#039;sun&#039;]&lt;br /&gt;
&lt;br /&gt;
; Assign a local variable an array of numbers&lt;br /&gt;
Local $anArray[4] = [0, 0.25, 3 / 4, 12]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variable Initialization ==&lt;br /&gt;
When initializing variables there are several points to consider. It is bad practice to hog memory by assigning data which is not immediately required. It is therefore recommended that you declare and initialize variables immediately prior to use. If you wish to assign a default value to a variable which you intend to overwrite later, then the data should be of the same (or the most logical representation of its) type and use as little memory as possible.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Inconsistent data types are considered bad&lt;br /&gt;
Local $iInteger = &amp;quot;0&amp;quot;&lt;br /&gt;
Local $sString = False&lt;br /&gt;
&lt;br /&gt;
; Correct initialization&lt;br /&gt;
Local $iInteger = 0&lt;br /&gt;
Local $sString = &#039;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the following table, recommended default values are shown for each data type. Some data types have more than one possibile default value which can be used for initialization.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Default Value !! covering type&lt;br /&gt;
|-&lt;br /&gt;
| Binary(&amp;quot;&amp;quot;) || $d&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot; || $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| 0 || $a, $h, $i, $id, $m, $n, $o, $p, $t, $tag, $v&lt;br /&gt;
|-&lt;br /&gt;
| 0.0 || $f&lt;br /&gt;
|-&lt;br /&gt;
| Null || $o, $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| False (or True) || $b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Declare and initialize a variable with the recommended default value&lt;br /&gt;
Local $vUndefined = Null ; This does not require much memory&lt;br /&gt;
&lt;br /&gt;
; Some time later:&lt;br /&gt;
$vUndefined = 0xB0AD1CEA ; Assign an appropriate value as and when needed&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To reduce bloat, multiple variables can be declared on a single line. When declaring multiple variables on the same line, it is generally recommended that you stick to declaring one data type on each line. The intention here is to make the code easier to follow and manage in a future, however the best layout will vary according to circumstance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Not recommended&lt;br /&gt;
Local $sString = &amp;quot;&amp;quot;, $iInteger = 0, $asArray = [&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;] ; Mixed data types&lt;br /&gt;
&lt;br /&gt;
; Recommended&lt;br /&gt;
Local $iLeft = 10, $iTop = 10 ; Integers&lt;br /&gt;
Local $idButton_Go = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop) ; ControlIds&lt;br /&gt;
Local $idButton_Quit = GUICtrlCreateButton(&amp;quot;Quit&amp;quot;, 50, 10) ; ControlIds&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some languages it is essential to initialize variables on declaration, but this is not the case with AutoIt. Regarding data type, variables declared without being initialized should be considered as being undefined.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
Variables should also be named according to their scope.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Global UDF variable !! Global variable !! Local variable&lt;br /&gt;
|-&lt;br /&gt;
| $__g_iSomeVar || $g_iSomeVar || $iSomeVar&lt;br /&gt;
|}&lt;br /&gt;
With this method, you will avoid non wanted re-assignments.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Assign a Global variable the number 0&lt;br /&gt;
Global $iSomeVar1 = 0&lt;br /&gt;
; Assign a Global variable the number 5&lt;br /&gt;
Global $g_iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
SomeFunc()&lt;br /&gt;
&lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; Assign Local variables respectively the numbers 3 and 4&lt;br /&gt;
    Local $iSomeVar1 = 3, $iSomeVar2 = 4&lt;br /&gt;
&lt;br /&gt;
    ; Note: The user inadvertently re-assigned the global variable $iSomeVar1, because this one is not named as &amp;quot;global&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $iSomeVar1&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $iSomeVar1: &amp;quot; &amp;amp; $iSomeVar1)&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $iSomeVar2&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $iSomeVar2: &amp;quot; &amp;amp; $iSomeVar2)&lt;br /&gt;
&lt;br /&gt;
    ; Display the value of $g_iSomeVar2&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $g_iSomeVar2: &amp;quot; &amp;amp; $g_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&amp;lt;br /&amp;gt;Always declare your global variables in the global scope, not in the functions. It will prevent another function to use it before its declaration and the declaration is implicit (see [[#jumpsec1|examples]]).&lt;br /&gt;
&lt;br /&gt;
* A variable declared locally (with the Local keyword), has a visibility which depends of the scope where it&#039;s declared.&lt;br /&gt;
:Declaration in the global scope: the variable is nonetheless visible everywhere; declare it as Local if this one is only used in the same scope&lt;br /&gt;
:Declaration in a function: the variable is visible by the function itself and nowhere else.&lt;br /&gt;
&lt;br /&gt;
Structure of a code scope:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Global scope&lt;br /&gt;
&lt;br /&gt;
; Include the Constants file, it contains various constants; it&#039;s needed here for the $MB_SYSTEMMODAL flag of the MsgBox function)&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; This scope is either Global or Local, depending on where do you use the variables&lt;br /&gt;
&lt;br /&gt;
; Assign a Global variable the number 0 (which corresponds to an initialization of a variable number), its scope is Global because it&#039;s used at least in one function&lt;br /&gt;
Global $g_iVar1 = 0&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the string &amp;quot;foo&amp;quot;, its scope is Local because it&#039;s use is restricted to this scope&lt;br /&gt;
Local $sVar2 = &amp;quot;foo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; Display the content of $sVar2&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar2: &amp;quot; &amp;amp; $sVar2)&lt;br /&gt;
&lt;br /&gt;
; Re-assign a Local variable the string returned by the function MyFunc&lt;br /&gt;
$sVar2 = MyFunc()&lt;br /&gt;
&lt;br /&gt;
; Re-Display the content of $sVar2&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar2: &amp;quot; &amp;amp; $sVar2)&lt;br /&gt;
&lt;br /&gt;
; Declare a function (its main utility is described later in Functions, we can see one here which is to create a Local scope)&lt;br /&gt;
Func MyFunc()&lt;br /&gt;
    ; Local scope&lt;br /&gt;
&lt;br /&gt;
    ; Display the content of $g_iVar1&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $g_iVar1: &amp;quot; &amp;amp; $g_iVar1)&lt;br /&gt;
&lt;br /&gt;
    ; Assign a Local variable the string &amp;quot;bar&amp;quot;, its scope is Local because it&#039;s use is restricted to the function&#039;s scope&lt;br /&gt;
    Local $sVar3 = &amp;quot;bar&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Display the content of $sVar3&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $sVar3: &amp;quot; &amp;amp; $sVar3)&lt;br /&gt;
&lt;br /&gt;
    ; Return the $sVar3 content, it will be visible (if used) to the scope where the function is called&lt;br /&gt;
    Return $sVar3&lt;br /&gt;
EndFunc   ;==&amp;gt;MyFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Concerning the Dim keyword, its recommended usage is limited to empty an existing array (Example 1) or to redeclare a function parameter (Example 2).&lt;br /&gt;
&lt;br /&gt;
Example 1:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Include the Array UDF, it&#039;s needed here for the _ArrayDisplay function&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
; Assign a Local variable an array containing numbers with a size of 5&lt;br /&gt;
; Note than an array is based 0 index, to access the first element the code is: $aiArray[0]&lt;br /&gt;
Local $aiArray[5] = [1, 2, 3, 4, 5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aiArray)&lt;br /&gt;
 &lt;br /&gt;
; Empty the array (and keep its size)&lt;br /&gt;
Dim $aiArray[5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aiArray)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Remark: The variable type of the emptied array is a string, every variable non initialized is a string.&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Call MyFunc with default parameters ($vParam1 = 0)&lt;br /&gt;
MyFunc()&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array containing integers&lt;br /&gt;
Local $aiArray[3] = [3, 4, 5]&lt;br /&gt;
; Call MyFunc with $aiArray as parameter ($vParam1 = $aiArray)&lt;br /&gt;
MyFunc($aiArray)&lt;br /&gt;
&lt;br /&gt;
Func MyFunc($vParam1 = 0)&lt;br /&gt;
    ; If $vParam1 is NOT an array then redeclare it to an array&lt;br /&gt;
    If Not IsArray($vParam1) Then&lt;br /&gt;
        Dim $vParam1[3] = [0, 1, 2]&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    ; Display the array&lt;br /&gt;
    _ArrayDisplay($vParam1)&lt;br /&gt;
EndFunc   ;==&amp;gt;MyFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the ReDim keyword, limit its use to resize an array you want to keep its content:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Include the Array UDF, it&#039;s needed here for the _ArrayDisplay function&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
; Assign a Local variable an array containing numbers with a size of 5&lt;br /&gt;
; Note than an array is based 0 index, to access the first element the code is: $aiArray[0]&lt;br /&gt;
Local $aArray[5] = [1, 2, 3, 4, 5]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
 &lt;br /&gt;
; Resize the array (and keep its content)&lt;br /&gt;
ReDim $aArray[3]&lt;br /&gt;
 &lt;br /&gt;
; Display the contents&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why using Dim over Local/Global is not always a good option:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Dim $g_vVariableThatIsGlobal = &amp;quot;This is a variable that has &amp;quot;&amp;quot;Program Scope&amp;quot;&amp;quot; aka Global.&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;An example of why Dim can cause more problems than solve them.&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
Example()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, $g_vVariableThatIsGlobal) ; That looks alright to me as it displays the following text: This is a variable that has &amp;quot;Program Scope&amp;quot; aka Global&lt;br /&gt;
 &lt;br /&gt;
    Local $vReturn = SomeFunc() ; Call some random function&lt;br /&gt;
 &lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, $vReturn, $g_vVariableThatIsGlobal) ; The Global variable ($g_vVariableThatIsGlobal) changed because I totally forgot I had a duplicate variable name in &amp;quot;SomeFunc&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; This should create a variable in Local scope if the variable name doesn&amp;quot;t already exist&lt;br /&gt;
    ; For argument sake I totally forgot that I declared a variable already with the same name&lt;br /&gt;
    ; Well I only want this to be changed in the function and not the variable at the top of the script&lt;br /&gt;
    ; Should be OK right? Think again&lt;br /&gt;
    Dim $g_vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
    For $i = 1 To 10&lt;br /&gt;
        $g_vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $g_vVariableThatIsGlobal&lt;br /&gt;
    Next&lt;br /&gt;
    Return $g_vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;jumpsec1&amp;quot;&amp;gt;Declaring Global variables in a Function is never a good idea:&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling Example() first will initialise the Global variable $g_vVariableThatIsGlobal and therefore calling SomeFunc() won&#039;t return an error&lt;br /&gt;
; Now look at Example 2&lt;br /&gt;
Example()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script&lt;br /&gt;
    Global $g_vVariableThatIsGlobal = &#039;This is a variable that has &#039;&#039;File Scope&#039;&#039; aka Global.&#039;&lt;br /&gt;
    SomeFunc()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $g_vVariableThatIsGlobal) ; As the variable was initialised this will not return an error&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling SomeFunc() first will bypass the Global variable $g_vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $g_vVariableThatIsGlobal contains&lt;br /&gt;
SomeFunc()&lt;br /&gt;
 &lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script&lt;br /&gt;
    Global $g_vVariableThatIsGlobal = &#039;This is a variable that has &#039;&#039;File Scope&#039;&#039; aka Global.&#039;&lt;br /&gt;
    SomeFunc()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
 &lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $g_vVariableThatIsGlobal) ; As the variable wasn&#039;t initialised this will return an error of &amp;quot;variable used without being declared.&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declaring variables in loops (For, While, Do etc..) can have an affect on efficiency:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables inside loops should be avoided as the variable is re-declared on each repetition&lt;br /&gt;
For $i = 1 To 10 ; $i is in &#039;loop scope.&#039;&lt;br /&gt;
    Local $iInt = $i&lt;br /&gt;
Next&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $iInt) ; This will display 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables outside of loops is more efficient in the long run&lt;br /&gt;
Local $iInt = 0&lt;br /&gt;
For $i = 1 To 10 ; $i is in &#039;loop scope.&#039;&lt;br /&gt;
    $iInt = $i&lt;br /&gt;
Next&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, $iInt) ; This will display 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no requirement to declare the iteration count variable in a loop:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Correct&lt;br /&gt;
Local Const $iCount = 99&lt;br /&gt;
Local $aArray[$iCount]&lt;br /&gt;
For $i = 0 To UBound($iCount) - 1 ; $i is only used in the loop, so there is no requirement to declare it&lt;br /&gt;
    $aArray[$i] = $i&lt;br /&gt;
Next&lt;br /&gt;
&lt;br /&gt;
; Incorrect&lt;br /&gt;
Local Const $iCount = 99&lt;br /&gt;
Local $aArray[$iCount]&lt;br /&gt;
Local $i ; This is only used to store the iteration count value in the loop and therefore doesn&#039;t need to be declared. This is known as loop scope&lt;br /&gt;
For $i = 0 To UBound($iCount) - 1&lt;br /&gt;
    $aArray[$i] = $i&lt;br /&gt;
Next&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
As you can see, there is the Const keyword in the example, we are going to talk about it.&lt;br /&gt;
&lt;br /&gt;
== Const, Static, Enum ==&lt;br /&gt;
&lt;br /&gt;
=== Const ===&lt;br /&gt;
We won&#039;t talk about the advantages of a constant variable, they are neglibible (for your information, an AutoIt constant variable is marked as read-only and remains a variable as read-only when compiled).&lt;br /&gt;
&lt;br /&gt;
The Const keyword may be used in a first by some of you to avoid re-assignments.&lt;br /&gt;
The best way to use them is not this last case, the constants should be used for real static variables, meaning that their value won&#039;t change regardless to the instance of the program.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Not recommended&lt;br /&gt;
Local Const $hGUI = GUICreate(&amp;quot;MyGUI&amp;quot;)&lt;br /&gt;
; The handle of the window is unique, it&#039;s generated by Windows and changes&lt;br /&gt;
&lt;br /&gt;
; Recommended&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Static ===&lt;br /&gt;
Static variables are the solution to the global variables used in only one function.&lt;br /&gt;
e.g: Retain variable data once returned from a Function and only use that variable in that particular Function.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 1&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 2&lt;br /&gt;
    SomeFunc() ; This will display a message box of 1, 3&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func SomeFunc()&lt;br /&gt;
    ; This initialises a Static variable in Local scope. When a variable is declared just in Local scope (within a Function,)&lt;br /&gt;
    ; it&#039;s destroyed when the Function ends/returns. This isn&#039;t the case for a Static variable. The variable can&#039;t be&lt;br /&gt;
    ; accessed from anywhere else in the script apart from the Function it was declared in&lt;br /&gt;
    Local Static $vVariableThatIsStatic = 0&lt;br /&gt;
    Local $vVariableThatIsLocal = 0&lt;br /&gt;
    $vVariableThatIsLocal += 1 ; This will always be 1 as it was destroyed once returned from SomeFunc&lt;br /&gt;
    $vVariableThatIsStatic += 1 ; This will increase by 1&lt;br /&gt;
    MsgBox(4096, $vVariableThatIsLocal, $vVariableThatIsStatic)&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enum ===&lt;br /&gt;
This statement is often practical in certain situations:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Create variables in Local scope and enumerate through the variables. Default is to start from 0&lt;br /&gt;
    Local Enum $eCat, $eDog, $eMouse, $eHamster ; $eHamster is equal to the value 3, not 4&lt;br /&gt;
&lt;br /&gt;
    ; Create an array in Local scope with 4 elements&lt;br /&gt;
    Local $aAnimalNames[4]&lt;br /&gt;
&lt;br /&gt;
    ; Assign each array element with the name of the respective animal. For example the name of the cat is Jasper&lt;br /&gt;
    $aAnimalNames[$eCat] = &#039;Jasper&#039; ; $eCat is equal to 0, similar to using $aAnimalNames[0]&lt;br /&gt;
    $aAnimalNames[$eDog] = &#039;Beethoven&#039; ; $eDog is equal to 1, similar to using $aAnimalNames[1]&lt;br /&gt;
    $aAnimalNames[$eMouse] = &#039;Pinky&#039; ; $eMouse is equal to 2, similar to using $aAnimalNames[2]&lt;br /&gt;
    $aAnimalNames[$eHamster] = &#039;Fidget&#039; ; $eHamster is equal to 3, similar to using $aAnimalNames[3]&lt;br /&gt;
&lt;br /&gt;
    ; Display the values of the array&lt;br /&gt;
    MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$aAnimalNames[$eCat] = &#039; &amp;amp; $aAnimalNames[$eCat] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eDog] = &#039; &amp;amp; $aAnimalNames[$eDog] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eMouse] = &#039; &amp;amp; $aAnimalNames[$eMouse] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;$aAnimalNames[$eHamster] = &#039; &amp;amp; $aAnimalNames[$eHamster] &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Sometimes using this approach for accessing an element is more practical than using a numerical value, due to the fact changing the index value of&lt;br /&gt;
    ; the enum constant has no affect on it&#039;s position in the array. Therefore changing the location of $eCat in the array is as simple as changing the order&lt;br /&gt;
    ; it appears in the initial declaration e.g&lt;br /&gt;
&lt;br /&gt;
    ; Local Enum $eDog, $eMouse, $eCat, $eHamster&lt;br /&gt;
&lt;br /&gt;
    ; Now $eCat is the 2nd element in the array. If you were using numerical values, you would have to manually change all references of $aAnimalNames[0] to&lt;br /&gt;
    ; $aAnimalNames[2], as well as for the other elements which have now shifted&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Au3Check directive ==&lt;br /&gt;
As you may know (and we hope), the Au3Check tool checks your code for syntax errors, variables used without being declared etc. which is a good thing to fix your script.&lt;br /&gt;
&lt;br /&gt;
With the official custom directive used to check the helpfile examples/includes, you can apply the good coding practices listed above:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Magic Numbers ==&lt;br /&gt;
Magic numbers are arbitrary numbers interspersed throughout a program&#039;s source code which do not have an associated identifier. The downside to this is not being able to derive a meaning from the number. &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox(262144, &amp;quot;Magic Numbers&amp;quot;, &amp;quot;It&#039;s Adventure Time!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In this example, the magic number is 262144 with the identifier being $MB_TOPMOST according to the helpfile.&lt;br /&gt;
&lt;br /&gt;
The corrected example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox($MB_TOPMOST, &amp;quot;Magic Numbers&amp;quot;, &amp;quot;It&#039;s Adventure Time!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Imagine you&#039;re a new user to AutoIt and you come across this code, where would you find -3, -4 or -5 in the help file?&lt;br /&gt;
; Since AutoIt is relatively a new concept to you, your first thought isn&#039;t to search through all the include files, I mean&lt;br /&gt;
; why would you, the help file is there for a reason&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    GUICtrlCreateLabel(&#039;Why magic numbers are counter productive.&#039;, 5, 5)&lt;br /&gt;
    GUICtrlSetState(Default, 128) ; Does this hide, show or disable it?&lt;br /&gt;
    GUICtrlSetState(Default, 64) ; Does this hide, show or disable it?&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case -3 ; Doesn&#039;t really tell much about what it does&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
            Case -4, -5 ; Again, no idea what these are. MouseMove? MouseClick? Restore?&lt;br /&gt;
                MsgBox(4096, &#039;&#039;, &#039;Do something when this action takes place.&#039;)&lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Did you understand the numbers were these:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    GUICtrlCreateLabel(&#039;Why magic numbers are counter productive.&#039;, 5, 5)&lt;br /&gt;
    GUICtrlSetState(Default, $GUI_DISABLE) ; Better, this is documented in the help file&lt;br /&gt;
    GUICtrlSetState(Default, $GUI_ENABLE) ; Better, this is documented in the help file&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE ; Better, this is documented in the help file. Ah, it&#039;s the close action&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
            Case $GUI_EVENT_MINIMIZE, $GUI_EVENT_RESTORE ; Better, this is documented in the help file&lt;br /&gt;
                MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;Do something when this action takes place.&#039;) ; Better, this is documented in the help file&lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Magic_number_(programming) Magic number (programming)]&lt;br /&gt;
&lt;br /&gt;
== Include-once directive ==&lt;br /&gt;
This one is designed for standard includes and UDFs, it&#039;s highly recommended to use it.&lt;br /&gt;
&lt;br /&gt;
Those includes may be included in more than one script of your project because they are needed for some includes or your script itself.&lt;br /&gt;
In that case, the code will be duplicated which is not a good thing especially if you have (and it&#039;s mainly the case) constants declared in those files, in so far as the constants cannot be redeclared/reassigned; same thing for functions&lt;br /&gt;
&lt;br /&gt;
Put the directive in top of your UDF (library) to avoid itself to be included more than once :&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include-once&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Free_Software&amp;diff=12683</id>
		<title>Free Software</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Free_Software&amp;diff=12683"/>
		<updated>2014-10-27T20:33:51Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /*  Passwords &amp;amp; Encryption  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Welcome To The Free Software Page ~ This page is a place to find useful free software recommended by the AutoIt community&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Archive &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.7-zip.org/  7 Zip] ~ Compression Utility ~ CyberSlug&lt;br /&gt;
* [http://legroom.net/software/uniextract Universal Extractor] ~ decompress and extract files from any type of archive or installer ~ wakillon&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Antivirus, Malware &amp;amp; Spyware Programs &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.lavasoft.com/products/ad_aware_free.php Ad-Aware] ~ Antivirus Package ~ /dev/null &lt;br /&gt;
* [http://www.avast.com/index Avast] ~ Antivirus Package ~ killaz219&lt;br /&gt;
* [http://www.avira.com/en/avira-free-antivirus  Avira] ~ Antivirus Package ~ MSLx Fanboy&lt;br /&gt;
* [http://free.avg.com/gb-en/homepage AVG Free] ~ Antivirus Package ~ LxP&lt;br /&gt;
* [http://antivirus.baidu.com/en/  Baidu Antivirus] ~ Antivirus ~ wakillon&lt;br /&gt;
* [http://www.trendmicro.co.uk/products/free-tools-and-services/ Hijack This] ~ Threat Removal Tool. Should only be used if you know what you are doing. ~ jefhal&lt;br /&gt;
* [http://www.microsoft.com/security/pc-security/mse.aspx  Microsoft Security Essentials (WIN7 only)] ~ Malware/Spyware Tool ~ Valuater &lt;br /&gt;
* [http://www.safer-networking.org/en/index.html Spybot - Search &amp;amp; Destroy] ~ Spyware Removal ~ BigDod &lt;br /&gt;
* [http://www.javacoolsoftware.com/spywareblaster.html  SpywareBlaster] ~ Spyware Tool ~ forger&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Audio &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://audacity.sourceforge.net/ Audacity] ~ Audio Recording &amp;amp; Editing Tool ~ jefhal&lt;br /&gt;
* [http://mediaarea.net/en/MediaInfo MediaInfo] ~ Display technical and tag data for video and audio files ~ wakillon&lt;br /&gt;
* [http://mp3gain.sourceforge.net/ MP3Gain] ~ Normalize Music Files ~ maqleod &lt;br /&gt;
* [http://www.mp3tag.de/en/index.html Mp3tag] ~ Mp3 Metadata Editor ~ ning&lt;br /&gt;
* [http://www.synthfont.com/ SynthFont] ~ Midi Editing ~ LxP&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Browsers &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.qksoft.com/favorites-management-master/  Bookmark Master] ~ IE Bookmark Manager ~ MHz&lt;br /&gt;
* [http://toolbarcleaner.com/ Toolbar Cleaner] ~  Remove unwanted toolbars, apps, add-ons, and plug-ins   ~ wakillon&lt;br /&gt;
----&lt;br /&gt;
* [http://en.browser.baidu.com/  Baidu Spark Browser] ~ Web Browser ~ wakillon&lt;br /&gt;
* [http://chromium.woolyss.com/  Chromium] ~ Web Browser ~ wakillon&lt;br /&gt;
* [http://www.mozilla.org/en-US/firefox/fx/ Firefox] ~ Web Browser ~ LxP&lt;br /&gt;
* [http://www.srware.net/en/software_srware_iron.php Iron] ~ Web Browser ~ wakillon&lt;br /&gt;
* [http://www.maxthon.com/  Maxthon] ~ Web Browser ~ MHz&lt;br /&gt;
* [http://www.opera.com/  Opera] ~ Browser ~ photonbuddy&lt;br /&gt;
* [http://support.apple.com/kb/dl1531 Safari] ~ Web Browser ~ wakillon&lt;br /&gt;
* [http://www.slimbrowser.net/en/ Slim Browser] ~ Web Browser ~ jefhal&lt;br /&gt;
* [http://browser.yandex.com/  Yandex] ~ Web Browser ~ wakillon&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; CD &amp;amp; DVD Software &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.daemon-tools.cc/eng/products/dtLite  Daemon Tools Lite] ~ Virtual Disc Emulator ~ CyberSlug&lt;br /&gt;
* [http://www.deepburner.com/?r=products&amp;amp;pr=deepburner&amp;amp;prr=features  DeepBurner ] ~ CD/DVD Burner ~ MSLx Fanboy&lt;br /&gt;
* [http://www.magiciso.com/tutorials/miso-magicdisc-mount.htm MagicDisc] ~ Virtual CD/DVD-ROM ~ wakillon&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Coding &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.autoitscript.com/site/ AutoIt] ~ Scripting Language ~ layer&lt;br /&gt;
* [http://www.jrsoftware.org/isinfo.php  Inno Setup] ~ Program Installer Setup ~ gcriaco&lt;br /&gt;
* [http://notepad-plus-plus.org/  Notepad++] ~ Source Code Editing ~ maqleod&lt;br /&gt;
* [http://www.pspad.com/en/ PSPad] ~ Universal Editor ~ LxP&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Commandline &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://curl.haxx.se/ curl] ~ Commandline Https/Http/Ftp Client ~ /dev/null&lt;br /&gt;
* [http://www.ffmpeg.org/ FFmpeg] ~ Record, convert and stream audio and video ~ wakillon&lt;br /&gt;
* [http://www.poweradmin.com/paexec PAExec] ~ Launch Remote Windows Apps (PSEXEC &#039;&#039;&#039;Free&#039;&#039;&#039; alternative) ~ Pincopanco&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Document Management &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.openoffice.org/  Apache OpenOffice] ~ Office Suite ~ MSLx Fanboy&lt;br /&gt;
* [http://www.libreoffice.org/  LibreOffice] ~ Office Suite ~ Chimaera&lt;br /&gt;
* [http://liquidninja.com/metapad/ Metapad] ~ Notepad alternative ~ LxP &lt;br /&gt;
* [http://www.vim.org/ Vim] ~ Text Editor ~ /dev/null&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Explorer Replacements &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://explorerplusplus.com/ Explorer++] ~  File manager for Windows ~ wakillon&lt;br /&gt;
* [http://www.softwareok.com/?Freeware/Q-Dir Q-Dir] ~  File manager for Windows ~ wakillon&lt;br /&gt;
* [http://wde.codeplex.com/ Windows Double Explorer] ~  File manager for Windows ~ wakillon&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; FTP / Web Servers &amp;amp; Remote &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.jtsoft.com.pl/ A-Term] ~ Terminal emulator with API (COM / DLL) ~ mlipok&lt;br /&gt;
* [http://httpd.apache.org/  Apache] ~ Web Server ~ maqleod&lt;br /&gt;
* [http://filezilla-project.org/  Filezilla] ~ FTP Client &amp;amp; Server ~ MHz&lt;br /&gt;
* [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html putty] ~ SSP client ~ /dev/null&lt;br /&gt;
* [http://www.realvnc.com/  RealVNC] ~ Remote Control Software ~ ning&lt;br /&gt;
* [http://www.smartftp.com/ SmartFTP] ~ FTP client ~ LxP&lt;br /&gt;
* [http://www.teamviewer.com  TeamViewer] ~ Remote Desktop Software (More features than RealVNC and its free!)&lt;br /&gt;
* [http://www.ayera.com/teraterm/ TeraTerm Pro Web] ~ Enhanced Telnet/SSH2 Client ~ /dev/null&lt;br /&gt;
* [http://winscp.net/eng/index.php WinSCP] ~ FTP over SSH ~ LxP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Image Editing &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://blog.bahraniapps.com/ GifCam] ~  Animated gif creation  ~ wakillon&lt;br /&gt;
* [http://imageresizer.codeplex.com/  Image Resizer] ~ Image Manipulation ~ maqleod&lt;br /&gt;
* [http://inkscape.org/  Inkscape] ~ Vector Graphics Editor ~ Josbe&lt;br /&gt;
* [http://www.irfanview.com/ IrfanView] ~ Universal image editor ~ LxP&lt;br /&gt;
* [http://www.photofiltre-studio.com/pf7-en.htm PhotoFiltre] ~ Photo Editor ~ wakillon&lt;br /&gt;
* [http://picasa.google.co.uk/  Picasa] ~ Photo Editing Tool ~ jefhal&lt;br /&gt;
* [http://www.gimp.org/  The Gimp] ~ Image Editing ~ Blue_Drache &lt;br /&gt;
* [http://www.xnview.com/en/index.html  XnView] ~ Multimedia Convertor ~ LxP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Internet Messaging &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.miranda-im.org/  Miranda] ~ Multi IM ~ Lazycat&lt;br /&gt;
* [http://www.pidgin.im/ Pidgin] ~ Formerly Gaim ~ LxP&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Mail &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.poppeeper.com/ POP Peeper] ~ Email Client&amp;amp;Notifier ~ wakillon&lt;br /&gt;
* [http://www.mozilla.org/en-US/thunderbird/ Thunderbird] ~ Email software ~ LxP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Maintenance &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://security.baidu.co.th/en/  Baidu PC Faster] ~ Advanced Optimization &amp;amp; Security Software ~ wakillon&lt;br /&gt;
* [http://www.piriform.com/ccleaner  CCleaner] ~ PC Cleanup Tool ~ Valuater&lt;br /&gt;
* [http://eraser.heidi.ie/  Eraser] ~ Stubborn File Removal ~ maqleod&lt;br /&gt;
* [http://www.free-codecs.com/download/K_Lite_Codec_Pack.htm  K-Lite Codec Pack] ~ Codecs ~ maqleod&lt;br /&gt;
* [http://www.bleepingcomputer.com/files/killbox.php  Pocket Killbox] ~ Stubborn File Removal Tool ~ jefhal&lt;br /&gt;
* [http://www.steffengerlach.de/freeware/ Scanner] ~ Hard disk usage monitor ~ LxP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Media Players &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.foobar2000.org/ foobar2000] ~ Advanced audio player~ LxP&lt;br /&gt;
* [http://www.jetaudio.com/download/ JetAudio Basic] ~  Media Player  ~ wakillon&lt;br /&gt;
* [http://sourceforge.net/projects/guliverkli/ Media Player Classic] ~ Media player~ LxP &lt;br /&gt;
* [http://mpc-hc.sourceforge.net/ Media Player Classic ( Home Cinema Edition )] ~ HD Video player ~ Chimaera&lt;br /&gt;
* [http://www.videolan.org/vlc/  VLC ] ~ Media Player ~ MSLx Fanboy&lt;br /&gt;
* [http://www.winamp.com/ WinAmp] ~ Media player ~ killaz219&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Network &amp;amp; Internet &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://keir.net/neutron.html Neutron] ~ Accurate time ~ LxP&lt;br /&gt;
* [http://www.uvnc.com/index.php UltraVNC] ~ Visual remote computing ~ LxP&lt;br /&gt;
* [http://www.poweradmin.com/paexec PAExec] ~ Launch Remote Windows Apps (PSEXEC &#039;&#039;&#039;Free&#039;&#039;&#039; alternative) ~ Pincopanco&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Passwords &amp;amp; Encryption &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.essentialpim.com/?r=products&amp;amp;pr=essentialpim&amp;amp;prr=features  EssentialPIM] ~ Personal Information Manager ~ Josbe&lt;br /&gt;
* [http://keepass.info/  Keepass] ~ Password Manager ~ /dev/null&lt;br /&gt;
* [http://passwordsafe.sourceforge.net/  Password Safe] ~ Password Management ~ maqleod&lt;br /&gt;
* [http://www.truecrypt.org/  TrueCrypt] ~ Encryption ~ photonbuddy&lt;br /&gt;
* [https://lastpass.com/ LastPass] ~ Password Management ~ BrewManNH&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; PDF &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://get.adobe.com/reader/ Adobe Reader] ~ PDF Reader ~ LxP&lt;br /&gt;
* [http://www.cutepdf.com/Products/CutePDF/writer.asp  Cute PDF] ~ Convert To PDF ~ CyberSlug&lt;br /&gt;
* [http://www.foxitsoftware.com/Secure_PDF_Reader/  Foxit Reader] ~ PDF Reader ~ ReFran&lt;br /&gt;
* [http://www.pdfforge.org/ PDF Creator] ~ PDF writer ~ LxP &lt;br /&gt;
* [http://www.acropdf.com/products.html PDF Speedup] ~ Speed up Adobe ~ LxP&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Privacy * &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;* &#039;&#039;&#039;Using some of the software in this section will prevent normal access to the AutoIt site as proxies are not allowed. Discussions on automating these types of products is not permitted.&#039;&#039;&#039;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.privoxy.org/ Privoxy] ~ To filter incoming web pages ~ LxP &lt;br /&gt;
* [https://www.torproject.org/index.html Tor] ~ Anonymity software ~ killaz219&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Resource Management &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.angusj.com/resourcehacker/ Resource Hacker] ~ Extract exe resources ~ LxP&lt;br /&gt;
* [http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm#new XVI32] ~ Hex Editor ~ /dev/null&lt;br /&gt;
* [http://www.httrack.com/index.php  HTTTrack] ~ Website Copier ~ gcriaco&lt;br /&gt;
* [http://www.cthing.com/Meazure.asp  Meazure] ~ Window Info Tool ~ MHz&lt;br /&gt;
----&lt;br /&gt;
* [http://www.nliteos.com/index.html  nLite] ~ Win XP Deployment Tool ~ beerman&lt;br /&gt;
* [http://www.vlite.net/  vLite] ~ Win Vista Deployment Tool ~ Chimaera&lt;br /&gt;
* [http://www.rt7lite.com/  RT 7 Lite] ~ Win 7 Deployment Tool ~ Chimaera&lt;br /&gt;
* [http://www.2kr2.rt7lite.com/  RT Server Customizer] ~ Win Server 2008 R2 Deployment Tool ~ Chimaera&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Searches and Comparison &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.mythicsoft.com/page.aspx?type=agentransack&amp;amp;page=home  Agent Ransack] ~ File Finder With Regex ~ OldGuyWalking&lt;br /&gt;
* [http://tools.tortoisesvn.net/grepWin.html  grepWin] ~ File Finder With Regex ~ mlipok&lt;br /&gt;
* [http://www.wingrep.com/index.htm  WinGrep] ~ File Finder With Regex ~ mlipok&lt;br /&gt;
* [http://winmerge.org  WinMerge] ~ File Finder With Regex ~ mlipok&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Startup Applications Management &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://codestuff.obninsk.ru/products_starter.html Starter] ~  Manage Windows startup applications  ~ wakillon&lt;br /&gt;
* [http://www.windowsstartup.com/ Startup Inspector] ~  Manage Windows startup applications  ~ wakillon&lt;br /&gt;
* [http://download.cnet.com/StartupMonitor/3000-2084_4-10637539.html Startup Monitor] ~  Startup applications Monitoring  ~ wakillon&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Task Scheduling &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.codeproject.com/Articles/5371/ToDoList-6-4-6-An-effective-and-flexible-way-to-ke  ToDoList] ~ Task Scheduler ~ Valik&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Video Editing &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.erightsoft.com/SUPER.html SUPER] ~  Audio &amp;amp; Video Converter, Recorder  ~ wakillon&lt;br /&gt;
* [http://www.virtualdub.org/  Virtualdub ] ~ Video Capture / Processing Utility ~ HardCopy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;blockquote style=&amp;quot;background-color:white; padding:1em; border:2px solid #8FBC8F&amp;quot;&amp;gt;&#039;&#039;&#039; Learning &#039;&#039;&#039;&amp;lt;/blockquote&amp;gt; =====&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
* [http://www.greatis.com/utilities/justtype/ Just Type] ~  Just Type  ~ mLipok&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Documentation&amp;diff=12682</id>
		<title>Documentation</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Documentation&amp;diff=12682"/>
		<updated>2014-10-27T20:24:14Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Online */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There is extensive AutoIt documentation available and this documentation is your recommended reference. Many developers keep the documentation or &#039;&#039;AutoIt Help File&#039;&#039;, as it is better known, constantly open to look up functions and keywords.&lt;br /&gt;
&lt;br /&gt;
= Using the help file =&lt;br /&gt;
&lt;br /&gt;
[[File:Using-helpfile.png|300x226px|frame|Help file showing index]]&lt;br /&gt;
If you have AutoIt installed then you can find it in the SciTE editor if you press [F1], or in the start menu under AutoIt &amp;gt; AutoIt Help File.&lt;br /&gt;
&lt;br /&gt;
There are three common methods of using the help file. You can use the Contents tab to browse the help file by category, which allows you to quickly find the resource you&#039;re after based on the type of script you&#039;re writing. Alternatively, you can use the Index tab to search for a resource page by title; this is practical if you know the name of the function you&#039;re after. Finally, by using the Search tab you can search all documents for a word or phrase. This is helpful when looking for words that may appear in multiple resource pages.&lt;br /&gt;
&lt;br /&gt;
As another alternative, if you are not finding the resource you&#039;re after, you can use Google to search in the online documentation.&lt;br /&gt;
&lt;br /&gt;
When in doubt, if you cannot find the answer to your problem, use the [[forums]].&lt;br /&gt;
&lt;br /&gt;
= Offline =&lt;br /&gt;
&lt;br /&gt;
An offline copy of the help file is available for download on the official AutoIt home page. You download the [[AutoIt Full Installation]] or the [[AutoIt Self Extracting Archive]] which both contain the AutoIt help file.&lt;br /&gt;
&lt;br /&gt;
== Source ==&lt;br /&gt;
&lt;br /&gt;
The source code for the help file is available to anyone so that they can expand, modify or translate the original. After editing, the help file source code can be submitted to the development team.&lt;br /&gt;
&lt;br /&gt;
= Online =&lt;br /&gt;
&lt;br /&gt;
There is also online documentation available if you do not have or want to download the offline version. This is less convenient to use for regular development since some features that the offline help file offers are not supported.&lt;br /&gt;
&lt;br /&gt;
The online copy can be found here: [http://www.autoitscript.com/autoit3/docs/ Online documentation]&lt;br /&gt;
&lt;br /&gt;
If you&#039;d like to try AutoIt Online in your Webbrowser you can use [http://www.script-example.com/themen/AutoIT-Online-Compiler.php script-example.com free AutoIt Web Compiler]&lt;br /&gt;
&lt;br /&gt;
== Searching ==&lt;br /&gt;
&lt;br /&gt;
Similar to the forums, you can use Google or your search engine of choice as a valuable searching tool. You start your query with &#039;&#039;site:http://www.autoitscript.com/autoit3/docs/&#039;&#039; and then your search query.&lt;br /&gt;
&lt;br /&gt;
A finished query may look like:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
site:http://www.autoitscript.com/autoit3/docs/ GUICtrlCreateButton&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Other languages =&lt;br /&gt;
&lt;br /&gt;
The AutoIt help file is available in a few other languages beside English.&lt;br /&gt;
&lt;br /&gt;
You can find these help files here: &lt;br /&gt;
[http://www.autoitscript.com/autoit3/docs.shtml Non-english documentation]&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=FAQ&amp;diff=12136</id>
		<title>FAQ</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=FAQ&amp;diff=12136"/>
		<updated>2014-01-08T19:44:42Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: clarified some text in regards to decompiling and obfuscation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a list of frequently asked questions asked on the forums.&lt;br /&gt;
&lt;br /&gt;
Other FAQs include:&lt;br /&gt;
* The one found in the [http://www.autoitscript.com/autoit3/docs/faq.htm AutoIt HelpFile].  Much of it is about the transition from V2 to V3, but most is still relevant and should be a port of call, as well as this one.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I debug my script?==&lt;br /&gt;
&lt;br /&gt;
=== In SciTE ===&lt;br /&gt;
This one has a myriad of answers, but the most effective is to begin by using the [http://www.autoitscript.com/autoit3/scite/ SciTE4AutoIt3 Editor] to create or edit scripts. This program is useful in debugging for the following reasons:&lt;br /&gt;
&lt;br /&gt;
* Syntax highlighting allows for immediate viewing of any mistakes from unended script tags or quotes. This allows the scripter to visibly see the difference between the following portions of code.&lt;br /&gt;
[[File:FAQ_Q1_2.jpg|center|Incorrect code]]&lt;br /&gt;
And the correct version: &lt;br /&gt;
[[File:FAQ_Q1_3.jpg|center||Correct Code]]&lt;br /&gt;
* Global syntax check built directly into the tools menu allows you to check an entire script for problems all at once.&lt;br /&gt;
* Built-in code tidying program that correctly indents untidy code and repairs messy scripts to allow them to be more readable. It also corrects problems with incorrectly capitalised function names and variables.&lt;br /&gt;
* Per-line trace insertion allows you to log every line of code executed to debug errors.&lt;br /&gt;
* Debug MsgBoxes or ConsoleWrites are able to be added anywhere in the script directly from SciTE. ConsoleWrite lines are less intrusive and prevent the added annoyance to the user of MsgBoxes.&lt;br /&gt;
&lt;br /&gt;
[[File:FAQ_Q1_4.jpg|center|Picture of SciTE4AutoIt3]]&lt;br /&gt;
&lt;br /&gt;
=== Using more code to check @error value ===&lt;br /&gt;
Nearly all functions will return something.  Most of the time when a function fails, it returns 0 and sets @error.  You can use this information not only to create scripts that handle for different errors but to debug and find out exactly why you are having problems.  Check the help file for specific functions and their return values.&lt;br /&gt;
&lt;br /&gt;
=== Via the Tray icon===&lt;br /&gt;
You can add this line at the top of your script (1 is on, 0 is off) to enable debugging from the tray icon.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;AutoItSetOption (&amp;quot;TrayIconDebug&amp;quot;, 1);0-off&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Then if you run the script (uncompiled as an AU3 file), you can mouse over the AutoIt icon in the system tray (down by the clock) to display debugging information.&lt;br /&gt;
&lt;br /&gt;
[[File:FAQ_Q1_1.jpg|center|Example output for TrayIconDebug]]&lt;br /&gt;
&lt;br /&gt;
=== OutputDebugString native call ===&lt;br /&gt;
You can also debug a script on any computer by adding the following code to your script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;Func dbg($msg)&lt;br /&gt;
	 DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;none&amp;quot;, &amp;quot;OutputDebugString&amp;quot;, &amp;quot;str&amp;quot;, $msg)&lt;br /&gt;
 EndFunc&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Then, when you need to add a debug line, call it as necessary. Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;dbg(&amp;quot;The value of Variable 1 at this time is &amp;quot; &amp;amp; $var1)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
This debugging is completely transparent to the user, and is only viewable with a program such as DebugView from SysInternals. This method of debugging has the added advantage of being available to the developer in situations where is not acceptable or feasable to install SciTE on a client&#039;s unit.&lt;br /&gt;
&lt;br /&gt;
=== Graphical debugger ===&lt;br /&gt;
Stumpii created a [http://www.autoitscript.com/forum/index.php?showtopic=21834 Graphical AutoIt Debugger], similar to Dev-C++&#039;s debugging style.&lt;br /&gt;
&lt;br /&gt;
[[File:FAQ_Q1_5.jpg|center|Stumpii&#039;s Graphical AutoIt Debugger]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I run something that is not an exe file [.txt, .msi, .pdf,.jpg etc.] [or] How can I open a webpage in the default browser?==&lt;br /&gt;
It was for this reason that the ShellExecute function was created. Here is one example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;ShellExecute(&amp;quot;C:\autoitscripts\test.au3&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;edit&amp;quot;, @SW_MAXIMIZE)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also specify a web address this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;ShellExecute(&amp;quot;http://www.autoitscript.com/forum&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;open&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you normally are able to right-click the file and select print, then you can also print the file from AutoIt using this function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;ShellExecute(&amp;quot;C:\boot.ini&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;print&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you wish to open the file with the default program, you can do as follows (BETA ONLY):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;ShellExecute(&amp;quot;C:\autoitscripts\test.au3&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you wish your script to wait until the process is finished, you can use the ShellExecuteWait function with the same parameters.&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
The default verb is the verb configured in the registry. If no verb is set as default in the registry then the &amp;quot;open&amp;quot; verb is used. If the &amp;quot;open&amp;quot; verb is not present then the first verb listed in the registry is used (except on Windows 2000).&lt;br /&gt;
&lt;br /&gt;
==How can I prevent more than one copy of my script from running at once / detect another copy of my script running?==&lt;br /&gt;
&lt;br /&gt;
=== _Singleton function ===&lt;br /&gt;
There are a few different ways to go about this. You can use a function called _Singleton to detect multiple instances of your script. An example of how to use this code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include &amp;lt;Misc.au3&amp;gt;&lt;br /&gt;
_Singleton(&amp;quot;TheNameOfMyScript&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this instance, the script will bring up some messages explaining to the user of the occurring events. &lt;br /&gt;
This example will show you how the above function can be used in a real world application.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include &amp;lt;Misc.au3&amp;gt;&lt;br /&gt;
If _Singleton(&amp;quot;MyScriptName&amp;quot;, 1) = 0 Then&lt;br /&gt;
    ; If successful, running our script a second time should cause us to fall through here&lt;br /&gt;
    MsgBox(16, &amp;quot;User Generated Error Message&amp;quot;, &amp;quot;Error: This script is already running!&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
    ; We have detected that we are the only instance running, now we will run a second instance to display _Singleton&#039;s function!&lt;br /&gt;
    MsgBox(64, &amp;quot;Information!&amp;quot;, &amp;quot;We are the first instance of this script, press OK to run another instance and trigger the error message!&amp;quot;)&lt;br /&gt;
    Switch @Compiled&lt;br /&gt;
        Case 1&lt;br /&gt;
            Run(FileGetShortName(@ScriptFullPath));when running an app, it&#039;s usually better to use its short name&lt;br /&gt;
        Case 0&lt;br /&gt;
            Run(FileGetShortName(@AutoItExe) &amp;amp; &#039; /AutoIt3ExecuteScript &#039; &amp;amp; FileGetShortName(@ScriptFullPath))&lt;br /&gt;
    EndSwitch&lt;br /&gt;
    Sleep(1000)&lt;br /&gt;
    MsgBox(64, &amp;quot;Information!&amp;quot;, &amp;quot;We ran a second instance, you should have recieved an error message!&amp;quot;, 5)&lt;br /&gt;
EndIf&lt;br /&gt;
Exit&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===_MutexExists function ===&lt;br /&gt;
Another method is to use _MutexExists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
If _MutexExists(&amp;quot;MydeswswScriptName&amp;quot;) Then&lt;br /&gt;
	; We know the script is already running. Let the user know.&lt;br /&gt;
	MsgBox(0, &amp;quot;Script Name&amp;quot;, &amp;quot;This script is already running. Using multiple copies of this script at the same time is unsupported!&amp;quot;)&lt;br /&gt;
	Exit&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
;Function Author- Martin&lt;br /&gt;
Func _MutexExists($sOccurenceName)&lt;br /&gt;
	Local $ERROR_ALREADY_EXISTS = 183, $handle, $lastError&lt;br /&gt;
	$sOccurenceName = StringReplace($sOccurenceName, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;); to avoid error&lt;br /&gt;
	$handle = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;CreateMutex&amp;quot;, &amp;quot;int&amp;quot;, 0, &amp;quot;long&amp;quot;, 1, &amp;quot;str&amp;quot;, $sOccurenceName)&lt;br /&gt;
	$lastError = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;GetLastError&amp;quot;)&lt;br /&gt;
	Return $lastError[0] = $ERROR_ALREADY_EXISTS&lt;br /&gt;
EndFunc;==&amp;gt;_MutexExists&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I run my script as a service?==&lt;br /&gt;
This is also a question with multiple answers, and none of them are the only way to do it. The first question to ask yourself is whether or not you wish to install the service on other computers besides your own.&lt;br /&gt;
&lt;br /&gt;
=== On your own computer - One time only ===&lt;br /&gt;
The easiest way to do this is to use Pirmasoft RunAsSvc. This program makes services easy to install and easy to remove when necessary.&lt;br /&gt;
&lt;br /&gt;
=== On all computers that run your script===&lt;br /&gt;
To do this you can use SRVANY.EXE and [http://www.autoitscript.com/forum/index.php?showtopic=6487 ServiceControl.au3]. You can then use this code to install your script as a service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;quot;ServiceControl.au3&amp;quot;&lt;br /&gt;
$servicename = &amp;quot;MyServiceName&amp;quot;&lt;br /&gt;
_CreateService(&amp;quot;&amp;quot;, $servicename, &amp;quot;My AutoIt Script&amp;quot;, &amp;quot;C:\Path_to_\srvany.exe&amp;quot;, &amp;quot;LocalSystem&amp;quot;, &amp;quot;&amp;quot;, 0x110)&lt;br /&gt;
RegWrite(&amp;quot;HKLM\SYSTEM\CurrentControlSet\Services\&amp;quot; &amp;amp; $servicename &amp;amp; &amp;quot;\Parameters&amp;quot;, &amp;quot;Application&amp;quot;, &amp;quot;REG_SZ&amp;quot;, @ScriptFullPath)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or use the following code to delete this service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;quot;ServiceControl.au3&amp;quot;&lt;br /&gt;
$servicename = &amp;quot;MyServiceName&amp;quot;&lt;br /&gt;
_DeleteService(&amp;quot;&amp;quot;, $servicename)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is one caveat to setting up AutoIt as a service. If the service is not installed using the above code, it must have the &amp;quot;allow service to interact with the desktop&amp;quot; setting or else automation functions such as Control* or Win* functions will not function. To assure the service does indeed have this setting, use the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;RegWrite(&amp;quot;HKLM\SYSTEM\CurrentControlSet\Services\[ServiceName]&amp;quot;, &amp;quot;Type&amp;quot;, &amp;quot;REG_DWORD&amp;quot;, 0x110)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I create/start/stop or otherwise control a service?==&lt;br /&gt;
There are two include libraries that are designed specifically to interact with services. These are the following:&lt;br /&gt;
&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=6487 ServiceControl.au3] made by SumTingWong. Functionality:&lt;br /&gt;
** _StartService()&lt;br /&gt;
** _StopService()&lt;br /&gt;
** _ServiceExists()&lt;br /&gt;
** _ServiceRunning()&lt;br /&gt;
** _CreateService()&lt;br /&gt;
** _DeleteService()&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=22165 _NTServices.au3] made by CatchFish. Functionality:&lt;br /&gt;
** _ServiceStart()&lt;br /&gt;
** _ServiceStop()&lt;br /&gt;
** _ServiceStatus()&lt;br /&gt;
** _ServicePause()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I display a progress bar while copying files or directories?==&lt;br /&gt;
There are a many different topics on how to do this.  For more, just search the forums for [http://www.autoitscript.com/forum/index.php?act=Search&amp;amp;CODE=show&amp;amp;searchid=22030d4d4effe5e32da23fdb69ed772f&amp;amp;search_in=posts&amp;amp;result_type=topics&amp;amp;highlite=%2BCopy%2B Progress Copy + Progress].&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=11313 Copy with progress dialog]... By ezztabi&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=11888 Yet another copy with progress]... By SumTingWong&lt;br /&gt;
* [http://www.autoit.de/index.php?page=Thread&amp;amp;postID=58875 _MultiFileCopy]... By Oscar (German Forums)&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=19370&amp;amp;st=45&amp;amp;p=186198&amp;amp;#entry186198 _FileCopy]... By Jos&lt;br /&gt;
&lt;br /&gt;
[[File:FAQ_Q6_1.jpg|center|Copy progress dialog by ezztabi]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I make a hotkey that only works in my GUI?==&lt;br /&gt;
It used to be quite tedious setting hotkeys to only work in your GUI.  Now there is an easier way with the function GUISetAccelerators.&lt;br /&gt;
&lt;br /&gt;
(From Helpfile example)&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; A simple custom messagebox that uses the MessageLoop mode&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
GUICreate(&amp;quot;Custom Msgbox&amp;quot;, 210, 80)&lt;br /&gt;
&lt;br /&gt;
GUICtrlCreateLabel(&amp;quot;Please click a button!&amp;quot;, 10, 10)&lt;br /&gt;
$YesID = GUICtrlCreateButton(&amp;quot;Yes&amp;quot;, 10, 50, 50, 20)&lt;br /&gt;
$NoID = GUICtrlCreateButton(&amp;quot;No&amp;quot;, 80, 50, 50, 20)&lt;br /&gt;
$ExitID = GUICtrlCreateButton(&amp;quot;Exit&amp;quot;, 150, 50, 50, 20)&lt;br /&gt;
&lt;br /&gt;
; Set accelerators for Ctrl+y and Ctrl+n&lt;br /&gt;
Dim $AccelKeys[2][2]=[[&amp;quot;^y&amp;quot;, $YesID], [&amp;quot;^n&amp;quot;, $NoID]]&lt;br /&gt;
GUISetAccelerators($AccelKeys)&lt;br /&gt;
&lt;br /&gt;
GUISetState(); display the GUI&lt;br /&gt;
&lt;br /&gt;
Do&lt;br /&gt;
	$msg = GUIGetMsg()&lt;br /&gt;
&lt;br /&gt;
	Select&lt;br /&gt;
		Case $msg = $YesID&lt;br /&gt;
			MsgBox(0, &amp;quot;You clicked on&amp;quot;, &amp;quot;Yes&amp;quot;)&lt;br /&gt;
		Case $msg = $NoID&lt;br /&gt;
			MsgBox(0, &amp;quot;You clicked on&amp;quot;, &amp;quot;No&amp;quot;)&lt;br /&gt;
		Case $msg = $ExitID&lt;br /&gt;
			MsgBox(0, &amp;quot;You clicked on&amp;quot;, &amp;quot;Exit&amp;quot;)&lt;br /&gt;
		Case $msg = $GUI_EVENT_CLOSE&lt;br /&gt;
			MsgBox(0, &amp;quot;You clicked on&amp;quot;, &amp;quot;Close&amp;quot;)&lt;br /&gt;
	EndSelect&lt;br /&gt;
Until $msg = $GUI_EVENT_CLOSE Or $msg = $ExitID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I perform an action while a key is held down?==&lt;br /&gt;
You can use the _IsPressed() function to determine when a key is held down. The values that can be specified in this function are listed in the AutoIt Help File under User Defined Functions -&amp;gt; Misc Management -&amp;gt; _IsPressed. The following example will press the left mouse button while the k key is held down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include &amp;lt;Misc.au3&amp;gt;&lt;br /&gt;
$pressed = 0&lt;br /&gt;
While 1&lt;br /&gt;
	If _IsPressed(&amp;quot;4B&amp;quot;) Then&lt;br /&gt;
		If Not $pressed Then&lt;br /&gt;
			ToolTip(&amp;quot;K Key being held down&amp;quot;)&lt;br /&gt;
			MouseDown(&amp;quot;left&amp;quot;)&lt;br /&gt;
			$pressed = 1&lt;br /&gt;
		EndIf&lt;br /&gt;
	Else&lt;br /&gt;
		If $pressed Then&lt;br /&gt;
			ToolTip(&amp;quot;&amp;quot;)&lt;br /&gt;
			MouseUp(&amp;quot;left&amp;quot;)&lt;br /&gt;
			$pressed = 0&lt;br /&gt;
		EndIf&lt;br /&gt;
	EndIf&lt;br /&gt;
	Sleep(250)&lt;br /&gt;
WEnd&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I run my script on a remote computer over the network?==&lt;br /&gt;
The answer to this question depends on how much experience you have in networking. If the target system is a Windows 2000 or Windows XP Pro system to which you have administrator access then you may use one of the following programs:&lt;br /&gt;
&lt;br /&gt;
* PsExec from SysInternals&lt;br /&gt;
* BeyondExec from BeyondLogic&lt;br /&gt;
&lt;br /&gt;
With either of these programs it is possible to launch any process on a remote system and even copy your script to the target computer before starting it. Neither these programs nor any others will work with Windows XP Home Edition unless you create a custom &amp;quot;command listener&amp;quot; that you manually install on the target system.&lt;br /&gt;
&lt;br /&gt;
NOTE: Those of you with more advanced programming skills and a little imagination can figure out how to use the service control libraries and srvany.exe to do this same thing without either of the above mentioned programs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I make a User Defined Function with optional parameters like the ones I see in the Help File?==&lt;br /&gt;
You can specify optional parameters by giving them a default value in the Func declaration. An example of how this is &lt;br /&gt;
&lt;br /&gt;
done:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Func testme($param1, $param2 = &amp;quot;nothing&amp;quot;, $param3 = 5)&lt;br /&gt;
	MsgBox(0, &amp;quot;&amp;quot;, &amp;quot;Parameter one is required. The value of Parameter 1 is &amp;quot; &amp;amp; $param1 &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
		&amp;quot;Parameter 2 is optional. The value of Parameter 2 is &amp;quot; &amp;amp; $param2 &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
		&amp;quot;Parameter 3 is optional. The value of Parameter 3 is &amp;quot; &amp;amp; $param3)&lt;br /&gt;
EndFunc&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If testme() is called with only one parameter [I.E. testme(&amp;quot;test&amp;quot;)] then the output is:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Parameter one is required. The value of Parameter 1 is test&amp;lt;br /&amp;gt;&lt;br /&gt;
Parameter 2 is optional. The value of Parameter 2 is nothing&amp;lt;br /&amp;gt;&lt;br /&gt;
Parameter 3 is optional. The value of Parameter 3 is 5&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
However, if the function is called with more than one parameter like this testme(&amp;quot;test&amp;quot;, &amp;quot;something&amp;quot;), then the output is&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Parameter one is required. The value of Parameter 1 is test&amp;lt;br /&amp;gt;&lt;br /&gt;
Parameter 2 is optional. The value of Parameter 2 is something&amp;lt;br /&amp;gt;&lt;br /&gt;
Parameter 3 is optional. The value of Parameter 3 is 5&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I make my script start every time windows starts?==&lt;br /&gt;
You can use one of the following codes to allow your script to start with Windows:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;RegWrite(&amp;quot;HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run&amp;quot;, &amp;quot;MyProgramName&amp;quot;, &amp;quot;REG_SZ&amp;quot;, @ScriptFullPath)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;FileCreateShortcut(@ScriptFullPath, @StartupCommonDir &amp;amp; &amp;quot;\MyProgramName.lnk&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I have the script delete itself?==&lt;br /&gt;
The following function will delete the running script or .exe once it has finished execution.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;WARNING: Make a copy of your script before calling this function!!!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Func _SelfDelete($iDelay = 0)&lt;br /&gt;
	Local $sCmdFile&lt;br /&gt;
	FileDelete(@TempDir &amp;amp; &amp;quot;\scratch.bat&amp;quot;)&lt;br /&gt;
	$sCmdFile = &#039;ping -n &#039; &amp;amp; $iDelay &amp;amp; &#039; 127.0.0.1 &amp;gt; nul&#039; &amp;amp; @CRLF _&lt;br /&gt;
			 &amp;amp; &#039;:loop&#039; &amp;amp; @CRLF _&lt;br /&gt;
			 &amp;amp; &#039;del &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF _&lt;br /&gt;
			 &amp;amp; &#039;if exist &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot; goto loop&#039; &amp;amp; @CRLF _&lt;br /&gt;
			 &amp;amp; &#039;del %0&#039;&lt;br /&gt;
	FileWrite(@TempDir &amp;amp; &amp;quot;\scratch.bat&amp;quot;, $sCmdFile)&lt;br /&gt;
	Run(@TempDir &amp;amp; &amp;quot;\scratch.bat&amp;quot;, @TempDir, @SW_HIDE)&lt;br /&gt;
EndFunc;==&amp;gt;_SelfDelete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==How can I create a clickable website hyperlink in my gui?==&lt;br /&gt;
[[File:FAQ_Q13_1.jpg|center|Example GUI using Gary&#039;s UDF.]]&lt;br /&gt;
&lt;br /&gt;
Gary Frost has made great advances in this area and has provided a [http://www.autoitscript.com/forum/index.php?showtopic=23111&amp;amp;st=0 UDF here] to help with doing this.&lt;br /&gt;
&lt;br /&gt;
==How can I change the screen resolution / refresh rate / color depth?==&lt;br /&gt;
[http://www.autoitscript.com/forum/index.php?showtopic=20121 ChangeResolution.au3] is a library function created to make changes to these settings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How can I get the screen resolution in multiple monitor setups?==&lt;br /&gt;
The following code was worked out by Larry to determine the total screen resolution of multiple monitors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
$aTSR = _GetTotalScreenResolution()&lt;br /&gt;
MsgBox(0, &amp;quot;Total Screen Resolution&amp;quot;, &amp;quot;Width = &amp;quot; &amp;amp; $aTSR[0] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
		&amp;quot;Height = &amp;quot; &amp;amp; $aTSR[1])&lt;br /&gt;
&lt;br /&gt;
;Original code by Larry.&lt;br /&gt;
;Edited by BrettF&lt;br /&gt;
Func _GetTotalScreenResolution()&lt;br /&gt;
	Local $aRet[2]&lt;br /&gt;
	Global Const $SM_VIRTUALWIDTH = 78&lt;br /&gt;
	Global Const $SM_VIRTUALHEIGHT = 79&lt;br /&gt;
	$VirtualDesktopWidth = DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;GetSystemMetrics&amp;quot;, &amp;quot;int&amp;quot;, $SM_VIRTUALWIDTH)&lt;br /&gt;
	$aRet[0] = $VirtualDesktopWidth[0]&lt;br /&gt;
	$VirtualDesktopHeight = DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;GetSystemMetrics&amp;quot;, &amp;quot;int&amp;quot;, $SM_VIRTUALHEIGHT)&lt;br /&gt;
	$aRet[1] = $VirtualDesktopHeight[0]&lt;br /&gt;
	Return $aRet&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  How can I register a file type with my program [or] How can I make files with a certain extension open in my program?==&lt;br /&gt;
[[File:FAQ_Q16_1.jpg|center|Example of how a file type can be registered.]]&lt;br /&gt;
File registration can be a tricky business for those who have not done it before. The first thing to be done is to modify your script to allow it to accept files from the command line. Here is one example of how to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;$cmdline[0] is the number of parameters passed&lt;br /&gt;
If $cmdline[0] &amp;lt;&amp;gt; 0 Then&lt;br /&gt;
	$filename = $cmdline[1]&lt;br /&gt;
;Do something with the file here&lt;br /&gt;
	MsgBox(0, &amp;quot;UXYFixer&amp;quot;, &#039;The file name passed to the command line is &amp;quot;&#039; &amp;amp; $filename &amp;amp; &#039;&amp;quot;&#039;)&lt;br /&gt;
Else&lt;br /&gt;
; We did not get any command line parameters.&lt;br /&gt;
; If this is a command line only program, you would want to&lt;br /&gt;
; alert the user that the command line parameters were incorrect.&lt;br /&gt;
; If this is a GUI program (like a notepad program), you would&lt;br /&gt;
; want to simply continue from here without opening a file.&lt;br /&gt;
	MsgBox(0, &amp;quot;UXYFixer&amp;quot;, &#039;Command line parameters incorrect.&#039; &amp;amp; @CRLF &amp;amp; &#039;Command line usage: &amp;quot;&#039; &amp;amp; @ScriptName &amp;amp; &#039;&amp;quot; &amp;quot;file to process&amp;quot;&#039;)&lt;br /&gt;
 EndIf&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
After your script is ready to accept files, you can begin to register the file type you need with your program. To prevent errors, this-is-me has created a UDF that will allow you to do this easily:&lt;br /&gt;
&lt;br /&gt;
Here is an example of how to register and unregister a file extension using this UDF:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include &amp;quot;FileRegister.au3&amp;quot;&lt;br /&gt;
;================================================&lt;br /&gt;
;&lt;br /&gt;
; Description:	FileRegister($ext, $cmd, $verb [, $def [, $icon = &amp;quot;&amp;quot; [, $desc = &amp;quot;&amp;quot; ]]])&lt;br /&gt;
;			   Registers a file type in Explorer&lt;br /&gt;
;&lt;br /&gt;
; Parameter(s): $ext -  File Extension without period eg. &amp;quot;zip&amp;quot;&lt;br /&gt;
;		$cmd -  Program path with arguments eg. &#039;&amp;quot;C:\test\testprog.exe&amp;quot; &amp;quot;%1&amp;quot;&#039;&lt;br /&gt;
;			 (%1 is 1st argument, %2 is 2nd, etc.)&lt;br /&gt;
;		$verb - Name of action to perform on file&lt;br /&gt;
;			 eg. &amp;quot;Open with ProgramName&amp;quot; or &amp;quot;Extract Files&amp;quot;&lt;br /&gt;
;		$def -  Action is the default action for this filetype&lt;br /&gt;
;			 (1 for true 0 for false)&lt;br /&gt;
;			 If the file is not already associated, this will be the default.&lt;br /&gt;
;		$icon - Default icon for filetype including resource # if needed&lt;br /&gt;
;			 eg. &amp;quot;C:\test\testprog.exe,0&amp;quot; or &amp;quot;C:\test\filetype.ico&amp;quot;&lt;br /&gt;
;		$desc - File Description eg. &amp;quot;Zip File&amp;quot; or &amp;quot;ProgramName Document&amp;quot;&lt;br /&gt;
;&lt;br /&gt;
;================================================&lt;br /&gt;
&lt;br /&gt;
 FileRegister(&amp;quot;uxy&amp;quot;, &#039;&amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot; &amp;quot;%1&amp;quot;&#039;, &amp;quot;Open in UXYFixer&amp;quot;, 1, @ScriptFullPath &amp;amp; &#039;,0&#039;, &amp;quot;UXYFixer Document&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
;========================================&lt;br /&gt;
;&lt;br /&gt;
; Description:	FileUnRegister($ext, $verb)&lt;br /&gt;
;			   UnRegisters a verb for a file type in Explorer&lt;br /&gt;
; Parameter(s):  $ext - File Extension without period eg. &amp;quot;zip&amp;quot;&lt;br /&gt;
;			   $verb - Name of file action to remove&lt;br /&gt;
;					 eg. &amp;quot;Open with ProgramName&amp;quot; or &amp;quot;Extract Files&amp;quot;&lt;br /&gt;
;&lt;br /&gt;
;========================================&lt;br /&gt;
&lt;br /&gt;
 FileUnRegister(&amp;quot;uxy&amp;quot;, &amp;quot;Open in UXYFixer&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download here:&#039;&#039;&#039;&lt;br /&gt;
[http://www.autoitscript.com/forum/index.php?app=core&amp;amp;module=attach&amp;amp;section=attach&amp;amp;attach_id=26378 FileRegister.au3]&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t my combobox (GUICtrlCreateCombo) show a dropdown list when clicked?==&lt;br /&gt;
When using GUICtrlCreateCombo be sure to enter the desired height for your combobox list in the &amp;quot;height&amp;quot; parameter. Windows XP automatically selects an appropriate height for combo boxes, but other versions of Windows usually do not.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;$combo = GUICtrlCreateCombo(&amp;quot;&amp;quot;,10,10,200,20)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Would correctly be changed to:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;$combo = GUICtrlCreateCombo(&amp;quot;&amp;quot;,10,10,200,200)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my thread getting any replies?==&lt;br /&gt;
&lt;br /&gt;
=== Asking the right question right ===&lt;br /&gt;
Did you give a good description of the problem? If your title or explanation of the issue is not descriptive, users are likely to bypass your issue instead of helping. Post titles such as &amp;quot;Help Me&amp;quot;, &amp;quot;I Have A Problem&amp;quot;, &amp;quot;Question&amp;quot;, &amp;quot;Help me fix my code&amp;quot;, &amp;quot;This code doesn&#039;t work&amp;quot; or similarly worded titles will not readily draw forum users to your post. Experienced users (which are your best hope of resolving the issue) will often skip your post altogether in cases like this. An example of a post title descriptive enough to attract users to assist you is &amp;quot;Problem with WinWaitClose&amp;quot; or &amp;quot;Loop never ends&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Example for reproduction ===&lt;br /&gt;
Did you post example code? If you have not posted an example of the code you are having an issue with, then you will not recieve support. When posting a non-working script, please do so in the smallest amount of stand-alone code possible. If the code you post cannot run by itself on another person&#039;s computer, they will not be able to recreate the issue.&lt;br /&gt;
&lt;br /&gt;
=== Speak English and speak it right ===&lt;br /&gt;
Did you use proper English? Here are guidelines for posting properly in the english language:&lt;br /&gt;
* Use proper case.  THIS IS CONSIDERED YELLING. If you post in ALL UPPERCASE or all lowercase then you will look like a doofus.&lt;br /&gt;
* Use proper punctuation. Complete sentences need only one trailing punctuation mark -- not three!!! Writing a sentance without simple punctuation such as commas or other punctuation is considered lazy, which is considered a good judge of the poster&#039;s coding style. If you cannot summon the strength to write a sentence with correct punctuation, you will most likely miss simple coding mistakes such as unterminated quotes.&lt;br /&gt;
&lt;br /&gt;
=== Breaking forum rules, law, modesty, or common Sense ===&lt;br /&gt;
Make sure you are not giving the impression of breaking forum rules, http://www.autoitscript.com/forum/forum-2/announcement-15-forum-rules-7-nov-2012/. Make sure you are not doing anything that can be perceived as breaking the law.&lt;br /&gt;
&lt;br /&gt;
==Why does the Ctrl key get stuck down after I run my script?==&lt;br /&gt;
&lt;br /&gt;
=== Keys virtually stuck ===&lt;br /&gt;
It could equally be the Shift Or the Alt key.&lt;br /&gt;
&lt;br /&gt;
If you use Send In a script And you have a problem With keys being stuck down Then Send is the most likely culprit. A similar problem can occur With BlockInput. The solution is generally quite simple. If there is a key like Shift Or Alt held down at the start of the Send sequence, but that key is released by the time the Send sequence finishes Then the key will get &#039;stuck&#039; down. As an example of a solution, you could replace the Send function in your script with the _SendEx function below.&lt;br /&gt;
&lt;br /&gt;
The _SendEx function waits for the Shift, Alt And Ctrl keys to be released or pops up a warning if the $warn parameter is not an empty string. Therefore it is not intended to be used when one of these modifier keys has been set to be down using any combination of {ALTDOWN}, {SHIFTDOWN} and {ALTDOWN}.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt; Misc.au3 &amp;gt;&lt;br /&gt;
;Send the string $ss after the Shift Alt and Ctrl keys are released. Optionally give a warning after 1 sec if any of those keys are still down.&lt;br /&gt;
;Requires misc.au3 to be included in the script for the _IsPressed function.&lt;br /&gt;
Func _SendEx($ss, $warn = &amp;quot;&amp;quot;)&lt;br /&gt;
	Local $iT = TimerInit()&lt;br /&gt;
&lt;br /&gt;
	While _IsPressed(&amp;quot;10&amp;quot;) Or _IsPressed(&amp;quot;11&amp;quot;) Or _IsPressed(&amp;quot;12&amp;quot;)&lt;br /&gt;
		If $warn &amp;lt;&amp;gt; &amp;quot;&amp;quot; And TimerDiff($iT) &amp;gt; 1000 Then&lt;br /&gt;
			MsgBox(262144, &amp;quot;Warning&amp;quot;, $warn)&lt;br /&gt;
		EndIf&lt;br /&gt;
		Sleep(50)&lt;br /&gt;
	WEnd&lt;br /&gt;
	Send($ss)&lt;br /&gt;
EndFunc;==&amp;gt;_SendEx&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General unstuck method ===&lt;br /&gt;
Shilbiz also discovered that the following can &#039;clear&#039; locked down keys.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt; ControlSend(&amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;text&amp;quot;, 0)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I use Pixel functions?==&lt;br /&gt;
&lt;br /&gt;
=== Using a color change as an event ===&lt;br /&gt;
The following is an example of using the pixel to check if the colour has changed in a specific region.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Local $PixelCheck = 0, $NewCheck&lt;br /&gt;
$PixelCheck = PixelCheckSum(40, 50, 60, 70); Get the checksum for this area.&lt;br /&gt;
While 1; Keep going&lt;br /&gt;
	$NewCheck = PixelCheckSum(40, 50, 60, 70)&lt;br /&gt;
	If $PixelCheck &amp;lt;&amp;gt; $NewCheck Then&lt;br /&gt;
		; The old pixel checksum and the new one are different.&lt;br /&gt;
		$PixelCheck = $NewCheck; Update the $PixelCheck to the new value&lt;br /&gt;
		; Let us know it has changed.  Change this to what you want to happen when the colour in the region changes.&lt;br /&gt;
		Msgbox(48,&amp;quot;PixelChecksum&amp;quot;,&amp;quot;Pixel region has changed !&amp;quot;)&lt;br /&gt;
	EndIf&lt;br /&gt;
	Sleep(50); Just to give the CPU a bit of a break.&lt;br /&gt;
Wend&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Searching for a specific pixel color ===&lt;br /&gt;
This is an example of searching for a specific pixel (red), both pure red (0xFF0000) and red in a few different shades.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; Find a pure red pixel in the range 0,0-20,300&lt;br /&gt;
$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000 )&lt;br /&gt;
If Not @error Then&lt;br /&gt;
	MsgBox(0, &amp;quot;X and Y are:&amp;quot;, $coord[0] &amp;amp; &amp;quot;,&amp;quot; &amp;amp; $coord[1])&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
; Find a pure red pixel or a red pixel within 10 shades variations of pure red&lt;br /&gt;
$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000, 10 )&lt;br /&gt;
If Not @error Then&lt;br /&gt;
	MsgBox(0, &amp;quot;X and Y are:&amp;quot;, $coord[0] &amp;amp; &amp;quot;,&amp;quot; &amp;amp; $coord[1])&lt;br /&gt;
EndIf&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t my script work on a locked workstation?==&lt;br /&gt;
On a locked station any window will never be active (active is only dialog with text &amp;quot;Press Ctrl+Alt+Del&amp;quot;).  In Windows locked state applications run hidden (behind that visible dialog) and do not have focus and active status.  So generally don&#039;t use Send() MouseClick() WinActivate() WinWaitActive() WinActive() etc.  Instead use ControlSend() ControlSetText() ControlClick() WinWait() WinExists() WinMenuSelectItem() etc.  This way you may have your script resistive against another active windows.  It&#039;s possible to run such a script from scheduler on locked Windows stations.&lt;br /&gt;
&lt;br /&gt;
==Where can I learn AutoIt? Are there any tutorials?==&lt;br /&gt;
To learn AutoIt you have two main options available to you:&lt;br /&gt;
&lt;br /&gt;
AutoIt 1-2-3, an interactive classroom by Valuater. You may find it here:&lt;br /&gt;
[http://www.autoitscript.com/forum/index.php?showtopic=21048 http://www.autoitscript.com/forum/index.php?showtopic=21048]&lt;br /&gt;
&lt;br /&gt;
There is also updated LxP&#039;s AutoIt tutorial by BrettF. You can find it here:&lt;br /&gt;
[http://www.autoitscript.com/forum/index.php?showtopic=84960 http://www.autoitscript.com/forum/index.php?showtopic=84960]&lt;br /&gt;
&lt;br /&gt;
There is also a book; AutoIt v3: Your Quick Guide by Andy Flessner.&lt;br /&gt;
You can buy the book from here:&lt;br /&gt;
[http://oreilly.com/catalog/9780596515126/ http://oreilly.com/catalog/9780596515126/]&lt;br /&gt;
&lt;br /&gt;
On YouTube there are many videos available:&lt;br /&gt;
[http://www.youtube.com/results?search_query=autoit+tutorial&amp;amp;search_type=&amp;amp;aq=0&amp;amp;oq=AutoIt http://www.youtube.com/results?search_query=autoit+tutorial&amp;amp;search_type=&amp;amp;aq=0&amp;amp;oq=AutoIt]&lt;br /&gt;
&lt;br /&gt;
==Why does my script no longer decompile?==&lt;br /&gt;
Decompilation is no longer supported, and is only available for the older versions of AutoIt (Version 3.2.5.1 and earlier compiled scripts).&lt;br /&gt;
&lt;br /&gt;
Please &#039;&#039;&#039;do not&#039;&#039;&#039; post on this topic, but search the forums for more information.  Posting topics like this will usually get the topic locked.&lt;br /&gt;
&lt;br /&gt;
Also posting the source (if a hacked decompiler was used) of other compiled scripts, or otherwise mentioning these hacked decompilers will probably get you banned.  It is also in violation of the AutoIt EULA (End-User-License-Agreement).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;You may not reverse engineer or disassemble the SOFTWARE PRODUCT or compiled scripts that were created with the SOFTWARE PRODUCT.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please see the [[Decompiling FAQ]] for more information.&lt;br /&gt;
&lt;br /&gt;
==How can I get a window handle when all I have is a PID?==&lt;br /&gt;
Refer to the following example showing converting and use when manipulating the window. The function is based on work by Smoke_N/Hubertus and Helge.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;;Run process&lt;br /&gt;
$iPID = Run(&amp;quot;Notepad.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
;Allow window to initialize...&lt;br /&gt;
Sleep (500)&lt;br /&gt;
&lt;br /&gt;
;Get HWND.&lt;br /&gt;
$hWnd = _GetHwndFromPID($iPID)&lt;br /&gt;
&lt;br /&gt;
;Maximize&lt;br /&gt;
WinSetState($hWnd, &amp;quot;&amp;quot;, @SW_MAXIMIZE)&lt;br /&gt;
&lt;br /&gt;
;Wait 2 seconds&lt;br /&gt;
Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
;Minimize&lt;br /&gt;
WinSetState($hWnd, &amp;quot;&amp;quot;, @SW_MINIMIZE)&lt;br /&gt;
&lt;br /&gt;
;Wait 2 seconds&lt;br /&gt;
Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
;Restore window&lt;br /&gt;
WinSetState($hWnd, &amp;quot;&amp;quot;, @SW_RESTORE)&lt;br /&gt;
&lt;br /&gt;
;Wait 2 seconds&lt;br /&gt;
Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
;Move top left corner of screen, and resize to 800x600&lt;br /&gt;
WinMove($hWnd, &amp;quot;&amp;quot;, 0, 0, 800, 600)&lt;br /&gt;
&lt;br /&gt;
;Wait 2 seconds&lt;br /&gt;
Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
;Calculate Center of screen.&lt;br /&gt;
$x = (@DesktopWidth / 2) - 400; Desktop width divided by 2, then minus half the width of the window&lt;br /&gt;
$y = (@DesktopHeight / 2) - 300; Desktop height divided by 2, then minus half the height of the window&lt;br /&gt;
&lt;br /&gt;
;Move to center of screen&lt;br /&gt;
WinMove($hWnd, &amp;quot;&amp;quot;, $x, $y)&lt;br /&gt;
&lt;br /&gt;
;Wait 2 seconds&lt;br /&gt;
Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
;Close notepad&lt;br /&gt;
WinClose($hWnd)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;Function for getting HWND from PID&lt;br /&gt;
Func _GetHwndFromPID($PID)&lt;br /&gt;
	$hWnd = 0&lt;br /&gt;
	$winlist = WinList()&lt;br /&gt;
	Do&lt;br /&gt;
		For $i = 1 To $winlist[0][0]&lt;br /&gt;
			If $winlist[$i][0] &amp;lt;&amp;gt; &amp;quot;&amp;quot; Then&lt;br /&gt;
				$iPID2 = WinGetProcess($winlist[$i][1])&lt;br /&gt;
				If $iPID2 = $PID Then&lt;br /&gt;
					$hWnd = $winlist[$i][1]&lt;br /&gt;
					ExitLoop&lt;br /&gt;
				EndIf&lt;br /&gt;
			EndIf&lt;br /&gt;
		Next&lt;br /&gt;
	Until $hWnd &amp;lt;&amp;gt; 0&lt;br /&gt;
	Return $hWnd&lt;br /&gt;
EndFunc;==&amp;gt;_GetHwndFromPID&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I use single or double quotes in strings?==&lt;br /&gt;
It is a fairly simple concept once you get the basics down.  Basically there are a few different ways to go about mixing quotes in strings.&lt;br /&gt;
&lt;br /&gt;
A string in AutoIt can be encased in either single(&#039;) or double (&amp;quot;) quotes.  So if you want to add only one type of quote into your string, your first port of call is to use the other type of quote to encase the string.  Like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;$var = &amp;quot;I am a &#039;quote&#039; inside the string&amp;quot;&lt;br /&gt;
MsgBox (0, &amp;quot;Test 1&amp;quot;, $var)&lt;br /&gt;
$var = &#039;I wish I could be a &amp;quot;quote&amp;quot; inside the string!&#039;&lt;br /&gt;
MsgBox (0, &amp;quot;Test 1&amp;quot;, $var)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have to have both types of quotes in the string, the easiest way is to escape the quote ending the string as so to speak.  To do this, use two quotes instead of one.  Like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;$var = &#039;I am a single &#039;&#039;quote&#039;&#039; inside the string made using &amp;quot;single quote!&amp;quot;&#039;&lt;br /&gt;
MsgBox (0, &amp;quot;Test 1&amp;quot;, $var)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==When should I bump my threads?==&lt;br /&gt;
As a courtesy to other users you should only bump your post once in a 24 hour period.  Doing this allows all users the chance to get helped equally.  Also refer to [http://www.autoitscript.com/forum/index.php?showtopic=95704&amp;amp;view=findpost&amp;amp;p=688050 Why isn&#039;t my thread getting any replies?], as this will help you get replies.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I protect my code from decompilation?==&lt;br /&gt;
The fact of the matter is &#039;&#039;&#039;you can&#039;t fully protect your code&#039;&#039;&#039;.  AutoIt is an  interpreted language, so all scripts are interpreted, and that script has to get stored somewhere.  There is still hope though.  You can take certain measures to make the decompiled code less usable to the person that decompiled it.  The first step is to obfuscate your code.  This causes the code to become less readable.  Basically variables and functions are renamed, making it very hard to make head or tail of what is what.&lt;br /&gt;
&lt;br /&gt;
Please see the [[Decompiling FAQ]] for more information.&lt;br /&gt;
&lt;br /&gt;
==How can I decompile my AutoIt EXEs?==&lt;br /&gt;
You cannot decompile your AutoIt compiled scripts unless it was compiled with AutoIt 3.2.5.1 or earlier.&lt;br /&gt;
&lt;br /&gt;
If you wish to simulate decompilation for your script, you can do this using the following simple example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;;Original Author SmokeN&lt;br /&gt;
If $CMDLINE[0] Then&lt;br /&gt;
	If $CMDLINE[1] == &amp;quot;/SOURCE&amp;quot; AND $CMDLINE[2] == &amp;quot;MYPASSWORD&amp;quot; Then&lt;br /&gt;
		FileInstall(&amp;quot;ThisSCript.au3&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\DecompiledScript.au3&amp;quot;)&lt;br /&gt;
	EndIf&lt;br /&gt;
EndIf&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then if you run the exe with the following command line parameters your source will be installed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;myscript.exe /SOURCE MYPASSWORD&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What is proper forum etiquette?  What rules are there for the forum?==&lt;br /&gt;
Proper forum etiquette will ensure you will stay a member of these forums.  So try to follow these rules.  Also see this [http://www.autoitscript.com/forum/index.php?showtopic=95704&amp;amp;st=15&amp;amp;p=688050&amp;amp;#entry688050 FAQ post], as you should follow what is outlined there as well.&lt;br /&gt;
&lt;br /&gt;
* Use proper English.  MSN speak and the like makes it very hard to understand what you want.  Keep posts in proper case because UPPERCASE is considered yelling and lowercase makes you look stupid.  Don&#039;t use more punctuation marks than necessary. For example ?!!!? and ????? is completely unnecessary.&lt;br /&gt;
* Before posting help with a script, make sure you follow these steps:&lt;br /&gt;
*# Search for your issue.&lt;br /&gt;
*#* There are many thousands of posts on this forum, and chances are your question has been asked before.  Make sure to use a variety of terms to maximize your results.&lt;br /&gt;
*# Read the helpfile&lt;br /&gt;
*#* Most if not all things in the help file will have an example (native functions) or two.  Give them a go to try see how the functions work.  Most of the time it helps!&lt;br /&gt;
*# Give it a go&lt;br /&gt;
*#* Seriously, if you can&#039;t be bothered to give it a go, then why should we be bothered to help you?  If you feel you can&#039;t do it and you don&#039;t try then how will you ever know?  We always prefer that you give it a go because you can learn from your mistakes and hopefully understand it better.&lt;br /&gt;
*# Post your problem&lt;br /&gt;
*#* Make sure you post in the correct forum.&lt;br /&gt;
*#** AutoIt Specific&lt;br /&gt;
*#*** General Help and Support (Most support questions)&lt;br /&gt;
*#*** GUI Support (Support for the Graphical User Interface)&lt;br /&gt;
*#** Non-AutoIT&lt;br /&gt;
*#*** Chat&lt;br /&gt;
*#*** Developer Chat (Usually for C++ questions.)&lt;br /&gt;
*#* Include a detailed description in the content of the post, and a detailed title&lt;br /&gt;
*#** Titles such as &#039;Help&#039; and &#039;What&#039;s wrong?&#039; are not acceptable.  To get the most help with your problem, be as descriptive as you can in the title, but keep in mind your title cannot be too long.&lt;br /&gt;
*#** Make sure you also include a descriptive question.  Just saying &#039;what is wrong with the following&#039; is also not acceptable, as we will have no idea what the problem is.  Describe what you think is wrong and what is not working.  It makes our job easier.&lt;br /&gt;
*#* Always include your code&lt;br /&gt;
*#** It shows us that you have tried and gives us a head start with something to play with.&lt;br /&gt;
* Usually asking for a script is not taken too well, within reason.  Keep in mind that this is a support forum, so please acknowledge that.   Most of us would rather that you learn rather than just having a script written for you.  If you do need something written for you, maybe try  [http://www.rentacoder.com/ RentACoder], as they are more suited to requests.&lt;br /&gt;
* Don&#039;t PM other members asking for them to look at threads of to help you unless they request it.  It is actually quite rude and annoying to receive PMs of that nature.&lt;br /&gt;
* Lurk a little before you dive right in. Read a number of posts, or check out the group&#039;s archives. Get a feel for the tone of the forum so you can participate accordingly.&lt;br /&gt;
* Say online exactly what you would say in person. In other words, if you wouldn&#039;t say it to the person&#039;s face in front of your Grandmother, you shouldn&#039;t type it here.&lt;br /&gt;
* Remember your face doesn&#039;t show. Words alone can convey sentiment, but without benefit of inflection or facial expression, they can be misconstrued. Use descriptive wording, emoticons or .gifs to ensure your meaning is clear. By the same token, don&#039;t jump to conclusions about another person&#039;s intent in posting an unclear comment. When in doubt, ask for clarification.&lt;br /&gt;
* Be respectful. Internet etiquette is similar to standard etiquette in this area. Appreciate that your opinion is one of many. You can disagree with another person without being disrespectful or rude to other people.&lt;br /&gt;
* Ignore Trolls. If you engage in conversation with one, you&#039;ll raise your blood pressure and empower the troll. You can&#039;t win a flame war, and you can&#039;t sway a troll&#039;s opinion. Often, they don&#039;t even care about the subject.  They live for the conflict and nothing more. Trolls are common and not worthy of your time. Ignore their posts no matter how inflammatory and eventually they&#039;ll get bored and move on.&lt;br /&gt;
* When you have found an answer for your question:&lt;br /&gt;
*# Do not edit your post to be blank or to have worthless information.  People may be searching for the same issue you have, so be courteous to them by leaving your question there.&lt;br /&gt;
*# It is also optional to add the likes of [SOLVED] into the title, and redirecting people to the answer that helped you.  It can make the lives of people searching easier.&lt;br /&gt;
* Finally follow the rules:&lt;br /&gt;
** [http://www.autoitscript.com/forum/forum-6/announcement-13-forum-rules/ Forum rules]&lt;br /&gt;
** [http://www.autoitscript.com/forum/index.php?showtopic=54168 Rules for the Chat forum]&lt;br /&gt;
** [http://www.autoitscript.com/forum/index.php?showtopic=65889 Rules for asking for source code]&lt;br /&gt;
** [http://www.autoitscript.com/forum/index.php?showtopic=37739 General policies and forum settings]&lt;br /&gt;
&lt;br /&gt;
Some general points taken from [http://www.ehow.com/how_2106033_use-proper-forum-etiquette.html here].&lt;br /&gt;
&lt;br /&gt;
==Are there forums available in my local language?==&lt;br /&gt;
Yes there are some available.  Some forum members here participate in multiple forums.&lt;br /&gt;
* [http://www.autoit.de/ German Forums]&lt;br /&gt;
* [http://www.autoit.fr/  French Forums]&lt;br /&gt;
* [http://www.autoit.es/ Spanish Forums]&lt;br /&gt;
* [http://autoit-script.ru/ Russian Forums]&lt;br /&gt;
&lt;br /&gt;
Please note that these are independent, community-run message boards and not just a translation of this board.&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Forums&amp;diff=11659</id>
		<title>Forums</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Forums&amp;diff=11659"/>
		<updated>2013-05-24T16:05:05Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Yahoo group */ edited the information as the page is closed.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In order to receive support and share your own scripts you may sign up for one of either forums.&lt;br /&gt;
&lt;br /&gt;
= Official forums =&lt;br /&gt;
The official forums are a very good place to get help and share scripts. It has a lot of members and is often praised for its quick and professional help and support. One of the advantages of AutoIt over other, more global, languages - is the concentrated community. There you are posting alongside the developers of the code, so chances are they know what they&#039;re talking about!&lt;br /&gt;
&lt;br /&gt;
[http://www.autoitscript.com/forum/index.php AutoIt Forums]&lt;br /&gt;
&lt;br /&gt;
== Searching the forums ==&lt;br /&gt;
Before you post a question it is always better to search the forums first to see if your question has been answered before.&lt;br /&gt;
There are two ways to search the forum:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Internal search engine&#039;&#039;&#039;&lt;br /&gt;
[http://www.autoitscript.com/forum/index.php?act=Search Search]&lt;br /&gt;
* &#039;&#039;&#039;Google&#039;&#039;&#039;&lt;br /&gt;
Enter into Google: site:www.autoitscript.com/forum/ your search query.&lt;br /&gt;
&lt;br /&gt;
Google search cannot be used to search the Chat forum.&lt;br /&gt;
&lt;br /&gt;
Example: [http://www.google.com/search?hl=en&amp;amp;q=site:www.autoitscript.com/forum/+script Search for &amp;quot;script&amp;quot; on the forums using Google.]&lt;br /&gt;
&lt;br /&gt;
See also: [[Searching_autoitscript_forum | Searching the Forum]]&lt;br /&gt;
&lt;br /&gt;
== Code of conduct ==&lt;br /&gt;
Before you post a question or start a new script, it is always better to search the forums first if your question has been answered before or see if you can find a similar script made by someone else and shared.&lt;br /&gt;
&lt;br /&gt;
Please think about asking &#039;&#039;&#039;the right question&#039;&#039;&#039; and asking &#039;&#039;&#039;the question right!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
These are must read topics before posting anything:&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=54168 Chat forum rules]&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=14632 Keylogger rules]&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=65889 Asking for source code]&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=37289 FAQ1] [http://www.autoitscript.com/forum/index.php?showtopic=23822 FAQ2]&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=34658 Are my AutoIt EXEs really infected?]&lt;br /&gt;
&lt;br /&gt;
= Unofficial forums =&lt;br /&gt;
These are the other unofficial forums, often in other languages than English.&lt;br /&gt;
&lt;br /&gt;
* French forums: http://www.autoit.fr/&lt;br /&gt;
* German forums: http://www.autoit.de/&lt;br /&gt;
* Polish forums: http://www.autoit.xaa.pl/&lt;br /&gt;
* Portuguese forums: http://www.autoitbrasil.com/&lt;br /&gt;
* Spanish forums: http://www.autoit.es/&lt;br /&gt;
&lt;br /&gt;
= Yahoo group =&lt;br /&gt;
&amp;lt;strike&amp;gt;As an alternative to the official forums, or if you just like Yahoo groups more, you can use the available Yahoo group to ask questions and share scripts.&amp;lt;/strike&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Yahoo group page has been closed to new messages. &lt;br /&gt;
&lt;br /&gt;
[http://groups.yahoo.com/group/AutoItList/ AutoIt Yahoo group]&lt;br /&gt;
&lt;br /&gt;
= Useful links =&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=94713 General Tips for using AutoIt] - Some tips that a lot of people will find useful.&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=FAQ&amp;diff=11658</id>
		<title>FAQ</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=FAQ&amp;diff=11658"/>
		<updated>2013-05-22T19:43:07Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Using a color change as an event */ fixed typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a list of frequently asked questions asked on the forums.&lt;br /&gt;
&lt;br /&gt;
Other FAQs include:&lt;br /&gt;
* The one found in the [http://www.autoitscript.com/autoit3/docs/faq.htm AutoIt HelpFile].  Much of it is about the transition from V2 to V3, but most is still relevant and should be a port of call, as well as this one.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I debug my script?==&lt;br /&gt;
&lt;br /&gt;
=== In SciTE ===&lt;br /&gt;
This one has a myriad of answers, but the most effective is to begin by using the [http://www.autoitscript.com/autoit3/scite/ SciTE4AutoIt3 Editor] to create or edit scripts. This program is useful in debugging for the following reasons:&lt;br /&gt;
&lt;br /&gt;
* Syntax highlighting allows for immediate viewing of any mistakes from unended script tags or quotes. This allows the scripter to visibly see the difference between the following portions of code.&lt;br /&gt;
[[File:FAQ_Q1_2.jpg|center|Incorrect code]]&lt;br /&gt;
And the correct version: &lt;br /&gt;
[[File:FAQ_Q1_3.jpg|center||Correct Code]]&lt;br /&gt;
* Global syntax check built directly into the tools menu allows you to check an entire script for problems all at once.&lt;br /&gt;
* Built-in code tidying program that correctly indents untidy code and repairs messy scripts to allow them to be more readable. It also corrects problems with incorrectly capitalised function names and variables.&lt;br /&gt;
* Per-line trace insertion allows you to log every line of code executed to debug errors.&lt;br /&gt;
* Debug MsgBoxes or ConsoleWrites are able to be added anywhere in the script directly from SciTE. ConsoleWrite lines are less intrusive and prevent the added annoyance to the user of MsgBoxes.&lt;br /&gt;
&lt;br /&gt;
[[File:FAQ_Q1_4.jpg|center|Picture of SciTE4AutoIt3]]&lt;br /&gt;
&lt;br /&gt;
=== Using more code to check @error value ===&lt;br /&gt;
Nearly all functions will return something.  Most of the time when a function fails, it returns 0 and sets @error.  You can use this information not only to create scripts that handle for different errors but to debug and find out exactly why you are having problems.  Check the help file for specific functions and their return values.&lt;br /&gt;
&lt;br /&gt;
=== Via the Tray icon===&lt;br /&gt;
You can add this line at the top of your script (1 is on, 0 is off) to enable debugging from the tray icon.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;AutoItSetOption (&amp;quot;TrayIconDebug&amp;quot;, 1);0-off&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Then if you run the script (uncompiled as an AU3 file), you can mouse over the AutoIt icon in the system tray (down by the clock) to display debugging information.&lt;br /&gt;
&lt;br /&gt;
[[File:FAQ_Q1_1.jpg|center|Example output for TrayIconDebug]]&lt;br /&gt;
&lt;br /&gt;
=== OutputDebugString native call ===&lt;br /&gt;
You can also debug a script on any computer by adding the following code to your script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;Func dbg($msg)&lt;br /&gt;
	 DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;none&amp;quot;, &amp;quot;OutputDebugString&amp;quot;, &amp;quot;str&amp;quot;, $msg)&lt;br /&gt;
 EndFunc&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Then, when you need to add a debug line, call it as necessary. Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;dbg(&amp;quot;The value of Variable 1 at this time is &amp;quot; &amp;amp; $var1)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
This debugging is completely transparent to the user, and is only viewable with a program such as DebugView from SysInternals. This method of debugging has the added advantage of being available to the developer in situations where is not acceptable or feasable to install SciTE on a client&#039;s unit.&lt;br /&gt;
&lt;br /&gt;
=== Graphical debugger ===&lt;br /&gt;
Stumpii created a [http://www.autoitscript.com/forum/index.php?showtopic=21834 Graphical AutoIt Debugger], similar to Dev-C++&#039;s debugging style.&lt;br /&gt;
&lt;br /&gt;
[[File:FAQ_Q1_5.jpg|center|Stumpii&#039;s Graphical AutoIt Debugger]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I run something that is not an exe file [.txt, .msi, .pdf,.jpg etc.] [or] How can I open a webpage in the default browser?==&lt;br /&gt;
It was for this reason that the ShellExecute function was created. Here is one example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;ShellExecute(&amp;quot;C:\autoitscripts\test.au3&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;edit&amp;quot;, @SW_MAXIMIZE)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also specify a web address this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;ShellExecute(&amp;quot;http://www.autoitscript.com/forum&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;open&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you normally are able to right-click the file and select print, then you can also print the file from AutoIt using this function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;ShellExecute(&amp;quot;C:\boot.ini&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;print&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you wish to open the file with the default program, you can do as follows (BETA ONLY):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;ShellExecute(&amp;quot;C:\autoitscripts\test.au3&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you wish your script to wait until the process is finished, you can use the ShellExecuteWait function with the same parameters.&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
The default verb is the verb configured in the registry. If no verb is set as default in the registry then the &amp;quot;open&amp;quot; verb is used. If the &amp;quot;open&amp;quot; verb is not present then the first verb listed in the registry is used (except on Windows 2000).&lt;br /&gt;
&lt;br /&gt;
==How can I prevent more than one copy of my script from running at once / detect another copy of my script running?==&lt;br /&gt;
&lt;br /&gt;
=== _Singleton function ===&lt;br /&gt;
There are a few different ways to go about this. You can use a function called _Singleton to detect multiple instances of your script. An example of how to use this code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include &amp;lt;Misc.au3&amp;gt;&lt;br /&gt;
_Singleton(&amp;quot;TheNameOfMyScript&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this instance, the script will bring up some messages explaining to the user of the occurring events. &lt;br /&gt;
This example will show you how the above function can be used in a real world application.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include &amp;lt;Misc.au3&amp;gt;&lt;br /&gt;
If _Singleton(&amp;quot;MyScriptName&amp;quot;, 1) = 0 Then&lt;br /&gt;
    ; If successful, running our script a second time should cause us to fall through here&lt;br /&gt;
    MsgBox(16, &amp;quot;User Generated Error Message&amp;quot;, &amp;quot;Error: This script is already running!&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
    ; We have detected that we are the only instance running, now we will run a second instance to display _Singleton&#039;s function!&lt;br /&gt;
    MsgBox(64, &amp;quot;Information!&amp;quot;, &amp;quot;We are the first instance of this script, press OK to run another instance and trigger the error message!&amp;quot;)&lt;br /&gt;
    Switch @Compiled&lt;br /&gt;
        Case 1&lt;br /&gt;
            Run(FileGetShortName(@ScriptFullPath));when running an app, it&#039;s usually better to use its short name&lt;br /&gt;
        Case 0&lt;br /&gt;
            Run(FileGetShortName(@AutoItExe) &amp;amp; &#039; /AutoIt3ExecuteScript &#039; &amp;amp; FileGetShortName(@ScriptFullPath))&lt;br /&gt;
    EndSwitch&lt;br /&gt;
    Sleep(1000)&lt;br /&gt;
    MsgBox(64, &amp;quot;Information!&amp;quot;, &amp;quot;We ran a second instance, you should have recieved an error message!&amp;quot;, 5)&lt;br /&gt;
EndIf&lt;br /&gt;
Exit&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===_MutexExists function ===&lt;br /&gt;
Another method is to use _MutexExists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
If _MutexExists(&amp;quot;MydeswswScriptName&amp;quot;) Then&lt;br /&gt;
	; We know the script is already running. Let the user know.&lt;br /&gt;
	MsgBox(0, &amp;quot;Script Name&amp;quot;, &amp;quot;This script is already running. Using multiple copies of this script at the same time is unsupported!&amp;quot;)&lt;br /&gt;
	Exit&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
;Function Author- Martin&lt;br /&gt;
Func _MutexExists($sOccurenceName)&lt;br /&gt;
	Local $ERROR_ALREADY_EXISTS = 183, $handle, $lastError&lt;br /&gt;
	$sOccurenceName = StringReplace($sOccurenceName, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;); to avoid error&lt;br /&gt;
	$handle = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;CreateMutex&amp;quot;, &amp;quot;int&amp;quot;, 0, &amp;quot;long&amp;quot;, 1, &amp;quot;str&amp;quot;, $sOccurenceName)&lt;br /&gt;
	$lastError = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;GetLastError&amp;quot;)&lt;br /&gt;
	Return $lastError[0] = $ERROR_ALREADY_EXISTS&lt;br /&gt;
EndFunc;==&amp;gt;_MutexExists&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I run my script as a service?==&lt;br /&gt;
This is also a question with multiple answers, and none of them are the only way to do it. The first question to ask yourself is whether or not you wish to install the service on other computers besides your own.&lt;br /&gt;
&lt;br /&gt;
=== On your own computer - One time only ===&lt;br /&gt;
The easiest way to do this is to use Pirmasoft RunAsSvc. This program makes services easy to install and easy to remove when necessary.&lt;br /&gt;
&lt;br /&gt;
=== On all computers that run your script===&lt;br /&gt;
To do this you can use SRVANY.EXE and [http://www.autoitscript.com/forum/index.php?showtopic=6487 ServiceControl.au3]. You can then use this code to install your script as a service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;quot;ServiceControl.au3&amp;quot;&lt;br /&gt;
$servicename = &amp;quot;MyServiceName&amp;quot;&lt;br /&gt;
_CreateService(&amp;quot;&amp;quot;, $servicename, &amp;quot;My AutoIt Script&amp;quot;, &amp;quot;C:\Path_to_\srvany.exe&amp;quot;, &amp;quot;LocalSystem&amp;quot;, &amp;quot;&amp;quot;, 0x110)&lt;br /&gt;
RegWrite(&amp;quot;HKLM\SYSTEM\CurrentControlSet\Services\&amp;quot; &amp;amp; $servicename &amp;amp; &amp;quot;\Parameters&amp;quot;, &amp;quot;Application&amp;quot;, &amp;quot;REG_SZ&amp;quot;, @ScriptFullPath)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or use the following code to delete this service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;quot;ServiceControl.au3&amp;quot;&lt;br /&gt;
$servicename = &amp;quot;MyServiceName&amp;quot;&lt;br /&gt;
_DeleteService(&amp;quot;&amp;quot;, $servicename)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is one caveat to setting up AutoIt as a service. If the service is not installed using the above code, it must have the &amp;quot;allow service to interact with the desktop&amp;quot; setting or else automation functions such as Control* or Win* functions will not function. To assure the service does indeed have this setting, use the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;RegWrite(&amp;quot;HKLM\SYSTEM\CurrentControlSet\Services\[ServiceName]&amp;quot;, &amp;quot;Type&amp;quot;, &amp;quot;REG_DWORD&amp;quot;, 0x110)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I create/start/stop or otherwise control a service?==&lt;br /&gt;
There are two include libraries that are designed specifically to interact with services. These are the following:&lt;br /&gt;
&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=6487 ServiceControl.au3] made by SumTingWong. Functionality:&lt;br /&gt;
** _StartService()&lt;br /&gt;
** _StopService()&lt;br /&gt;
** _ServiceExists()&lt;br /&gt;
** _ServiceRunning()&lt;br /&gt;
** _CreateService()&lt;br /&gt;
** _DeleteService()&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=22165 _NTServices.au3] made by CatchFish. Functionality:&lt;br /&gt;
** _ServiceStart()&lt;br /&gt;
** _ServiceStop()&lt;br /&gt;
** _ServiceStatus()&lt;br /&gt;
** _ServicePause()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I display a progress bar while copying files or directories?==&lt;br /&gt;
There are a many different topics on how to do this.  For more, just search the forums for [http://www.autoitscript.com/forum/index.php?act=Search&amp;amp;CODE=show&amp;amp;searchid=22030d4d4effe5e32da23fdb69ed772f&amp;amp;search_in=posts&amp;amp;result_type=topics&amp;amp;highlite=%2BCopy%2B Progress Copy + Progress].&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=11313 Copy with progress dialog]... By ezztabi&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=11888 Yet another copy with progress]... By SumTingWong&lt;br /&gt;
* [http://www.autoit.de/index.php?page=Thread&amp;amp;postID=58875 _MultiFileCopy]... By Oscar (German Forums)&lt;br /&gt;
* [http://www.autoitscript.com/forum/index.php?showtopic=19370&amp;amp;st=45&amp;amp;p=186198&amp;amp;#entry186198 _FileCopy]... By Jos&lt;br /&gt;
&lt;br /&gt;
[[File:FAQ_Q6_1.jpg|center|Copy progress dialog by ezztabi]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I make a hotkey that only works in my GUI?==&lt;br /&gt;
It used to be quite tedious setting hotkeys to only work in your GUI.  Now there is an easier way with the function GUISetAccelerators.&lt;br /&gt;
&lt;br /&gt;
(From Helpfile example)&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; A simple custom messagebox that uses the MessageLoop mode&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
GUICreate(&amp;quot;Custom Msgbox&amp;quot;, 210, 80)&lt;br /&gt;
&lt;br /&gt;
GUICtrlCreateLabel(&amp;quot;Please click a button!&amp;quot;, 10, 10)&lt;br /&gt;
$YesID = GUICtrlCreateButton(&amp;quot;Yes&amp;quot;, 10, 50, 50, 20)&lt;br /&gt;
$NoID = GUICtrlCreateButton(&amp;quot;No&amp;quot;, 80, 50, 50, 20)&lt;br /&gt;
$ExitID = GUICtrlCreateButton(&amp;quot;Exit&amp;quot;, 150, 50, 50, 20)&lt;br /&gt;
&lt;br /&gt;
; Set accelerators for Ctrl+y and Ctrl+n&lt;br /&gt;
Dim $AccelKeys[2][2]=[[&amp;quot;^y&amp;quot;, $YesID], [&amp;quot;^n&amp;quot;, $NoID]]&lt;br /&gt;
GUISetAccelerators($AccelKeys)&lt;br /&gt;
&lt;br /&gt;
GUISetState(); display the GUI&lt;br /&gt;
&lt;br /&gt;
Do&lt;br /&gt;
	$msg = GUIGetMsg()&lt;br /&gt;
&lt;br /&gt;
	Select&lt;br /&gt;
		Case $msg = $YesID&lt;br /&gt;
			MsgBox(0, &amp;quot;You clicked on&amp;quot;, &amp;quot;Yes&amp;quot;)&lt;br /&gt;
		Case $msg = $NoID&lt;br /&gt;
			MsgBox(0, &amp;quot;You clicked on&amp;quot;, &amp;quot;No&amp;quot;)&lt;br /&gt;
		Case $msg = $ExitID&lt;br /&gt;
			MsgBox(0, &amp;quot;You clicked on&amp;quot;, &amp;quot;Exit&amp;quot;)&lt;br /&gt;
		Case $msg = $GUI_EVENT_CLOSE&lt;br /&gt;
			MsgBox(0, &amp;quot;You clicked on&amp;quot;, &amp;quot;Close&amp;quot;)&lt;br /&gt;
	EndSelect&lt;br /&gt;
Until $msg = $GUI_EVENT_CLOSE Or $msg = $ExitID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I perform an action while a key is held down?==&lt;br /&gt;
You can use the _IsPressed() function to determine when a key is held down. The values that can be specified in this function are listed in the AutoIt Help File under User Defined Functions -&amp;gt; Misc Management -&amp;gt; _IsPressed. The following example will press the left mouse button while the k key is held down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include &amp;lt;Misc.au3&amp;gt;&lt;br /&gt;
$pressed = 0&lt;br /&gt;
While 1&lt;br /&gt;
	If _IsPressed(&amp;quot;4B&amp;quot;) Then&lt;br /&gt;
		If Not $pressed Then&lt;br /&gt;
			ToolTip(&amp;quot;K Key being held down&amp;quot;)&lt;br /&gt;
			MouseDown(&amp;quot;left&amp;quot;)&lt;br /&gt;
			$pressed = 1&lt;br /&gt;
		EndIf&lt;br /&gt;
	Else&lt;br /&gt;
		If $pressed Then&lt;br /&gt;
			ToolTip(&amp;quot;&amp;quot;)&lt;br /&gt;
			MouseUp(&amp;quot;left&amp;quot;)&lt;br /&gt;
			$pressed = 0&lt;br /&gt;
		EndIf&lt;br /&gt;
	EndIf&lt;br /&gt;
	Sleep(250)&lt;br /&gt;
WEnd&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I run my script on a remote computer over the network?==&lt;br /&gt;
The answer to this question depends on how much experience you have in networking. If the target system is a Windows 2000 or Windows XP Pro system to which you have administrator access then you may use one of the following programs:&lt;br /&gt;
&lt;br /&gt;
* PsExec from SysInternals&lt;br /&gt;
* BeyondExec from BeyondLogic&lt;br /&gt;
&lt;br /&gt;
With either of these programs it is possible to launch any process on a remote system and even copy your script to the target computer before starting it. Neither these programs nor any others will work with Windows XP Home Edition unless you create a custom &amp;quot;command listener&amp;quot; that you manually install on the target system.&lt;br /&gt;
&lt;br /&gt;
NOTE: Those of you with more advanced programming skills and a little imagination can figure out how to use the service control libraries and srvany.exe to do this same thing without either of the above mentioned programs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I make a User Defined Function with optional parameters like the ones I see in the Help File?==&lt;br /&gt;
You can specify optional parameters by giving them a default value in the Func declaration. An example of how this is &lt;br /&gt;
&lt;br /&gt;
done:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Func testme($param1, $param2 = &amp;quot;nothing&amp;quot;, $param3 = 5)&lt;br /&gt;
	MsgBox(0, &amp;quot;&amp;quot;, &amp;quot;Parameter one is required. The value of Parameter 1 is &amp;quot; &amp;amp; $param1 &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
		&amp;quot;Parameter 2 is optional. The value of Parameter 2 is &amp;quot; &amp;amp; $param2 &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
		&amp;quot;Parameter 3 is optional. The value of Parameter 3 is &amp;quot; &amp;amp; $param3)&lt;br /&gt;
EndFunc&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If testme() is called with only one parameter [I.E. testme(&amp;quot;test&amp;quot;)] then the output is:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Parameter one is required. The value of Parameter 1 is test&amp;lt;br /&amp;gt;&lt;br /&gt;
Parameter 2 is optional. The value of Parameter 2 is nothing&amp;lt;br /&amp;gt;&lt;br /&gt;
Parameter 3 is optional. The value of Parameter 3 is 5&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
However, if the function is called with more than one parameter like this testme(&amp;quot;test&amp;quot;, &amp;quot;something&amp;quot;), then the output is&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Parameter one is required. The value of Parameter 1 is test&amp;lt;br /&amp;gt;&lt;br /&gt;
Parameter 2 is optional. The value of Parameter 2 is something&amp;lt;br /&amp;gt;&lt;br /&gt;
Parameter 3 is optional. The value of Parameter 3 is 5&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I make my script start every time windows starts?==&lt;br /&gt;
You can use one of the following codes to allow your script to start with Windows:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;RegWrite(&amp;quot;HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run&amp;quot;, &amp;quot;MyProgramName&amp;quot;, &amp;quot;REG_SZ&amp;quot;, @ScriptFullPath)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;FileCreateShortcut(@ScriptFullPath, @StartupCommonDir &amp;amp; &amp;quot;\MyProgramName.lnk&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I have the script delete itself?==&lt;br /&gt;
The following function will delete the running script or .exe once it has finished execution.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;WARNING: Make a copy of your script before calling this function!!!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Func _SelfDelete($iDelay = 0)&lt;br /&gt;
	Local $sCmdFile&lt;br /&gt;
	FileDelete(@TempDir &amp;amp; &amp;quot;\scratch.bat&amp;quot;)&lt;br /&gt;
	$sCmdFile = &#039;ping -n &#039; &amp;amp; $iDelay &amp;amp; &#039; 127.0.0.1 &amp;gt; nul&#039; &amp;amp; @CRLF _&lt;br /&gt;
			 &amp;amp; &#039;:loop&#039; &amp;amp; @CRLF _&lt;br /&gt;
			 &amp;amp; &#039;del &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF _&lt;br /&gt;
			 &amp;amp; &#039;if exist &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot; goto loop&#039; &amp;amp; @CRLF _&lt;br /&gt;
			 &amp;amp; &#039;del %0&#039;&lt;br /&gt;
	FileWrite(@TempDir &amp;amp; &amp;quot;\scratch.bat&amp;quot;, $sCmdFile)&lt;br /&gt;
	Run(@TempDir &amp;amp; &amp;quot;\scratch.bat&amp;quot;, @TempDir, @SW_HIDE)&lt;br /&gt;
EndFunc;==&amp;gt;_SelfDelete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==How can I create a clickable website hyperlink in my gui?==&lt;br /&gt;
[[File:FAQ_Q13_1.jpg|center|Example GUI using Gary&#039;s UDF.]]&lt;br /&gt;
&lt;br /&gt;
Gary Frost has made great advances in this area and has provided a [http://www.autoitscript.com/forum/index.php?showtopic=23111&amp;amp;st=0 UDF here] to help with doing this.&lt;br /&gt;
&lt;br /&gt;
==How can I change the screen resolution / refresh rate / color depth?==&lt;br /&gt;
[http://www.autoitscript.com/forum/index.php?showtopic=20121 ChangeResolution.au3] is a library function created to make changes to these settings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How can I get the screen resolution in multiple monitor setups?==&lt;br /&gt;
The following code was worked out by Larry to determine the total screen resolution of multiple monitors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
$aTSR = _GetTotalScreenResolution()&lt;br /&gt;
MsgBox(0, &amp;quot;Total Screen Resolution&amp;quot;, &amp;quot;Width = &amp;quot; &amp;amp; $aTSR[0] &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
		&amp;quot;Height = &amp;quot; &amp;amp; $aTSR[1])&lt;br /&gt;
&lt;br /&gt;
;Original code by Larry.&lt;br /&gt;
;Edited by BrettF&lt;br /&gt;
Func _GetTotalScreenResolution()&lt;br /&gt;
	Local $aRet[2]&lt;br /&gt;
	Global Const $SM_VIRTUALWIDTH = 78&lt;br /&gt;
	Global Const $SM_VIRTUALHEIGHT = 79&lt;br /&gt;
	$VirtualDesktopWidth = DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;GetSystemMetrics&amp;quot;, &amp;quot;int&amp;quot;, $SM_VIRTUALWIDTH)&lt;br /&gt;
	$aRet[0] = $VirtualDesktopWidth[0]&lt;br /&gt;
	$VirtualDesktopHeight = DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;GetSystemMetrics&amp;quot;, &amp;quot;int&amp;quot;, $SM_VIRTUALHEIGHT)&lt;br /&gt;
	$aRet[1] = $VirtualDesktopHeight[0]&lt;br /&gt;
	Return $aRet&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  How can I register a file type with my program [or] How can I make files with a certain extension open in my program?==&lt;br /&gt;
[[File:FAQ_Q16_1.jpg|center|Example of how a file type can be registered.]]&lt;br /&gt;
File registration can be a tricky business for those who have not done it before. The first thing to be done is to modify your script to allow it to accept files from the command line. Here is one example of how to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;$cmdline[0] is the number of parameters passed&lt;br /&gt;
If $cmdline[0] &amp;lt;&amp;gt; 0 Then&lt;br /&gt;
	$filename = $cmdline[1]&lt;br /&gt;
;Do something with the file here&lt;br /&gt;
	MsgBox(0, &amp;quot;UXYFixer&amp;quot;, &#039;The file name passed to the command line is &amp;quot;&#039; &amp;amp; $filename &amp;amp; &#039;&amp;quot;&#039;)&lt;br /&gt;
Else&lt;br /&gt;
; We did not get any command line parameters.&lt;br /&gt;
; If this is a command line only program, you would want to&lt;br /&gt;
; alert the user that the command line parameters were incorrect.&lt;br /&gt;
; If this is a GUI program (like a notepad program), you would&lt;br /&gt;
; want to simply continue from here without opening a file.&lt;br /&gt;
	MsgBox(0, &amp;quot;UXYFixer&amp;quot;, &#039;Command line parameters incorrect.&#039; &amp;amp; @CRLF &amp;amp; &#039;Command line usage: &amp;quot;&#039; &amp;amp; @ScriptName &amp;amp; &#039;&amp;quot; &amp;quot;file to process&amp;quot;&#039;)&lt;br /&gt;
 EndIf&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
After your script is ready to accept files, you can begin to register the file type you need with your program. To prevent errors, this-is-me has created a UDF that will allow you to do this easily:&lt;br /&gt;
&lt;br /&gt;
Here is an example of how to register and unregister a file extension using this UDF:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include &amp;quot;FileRegister.au3&amp;quot;&lt;br /&gt;
;================================================&lt;br /&gt;
;&lt;br /&gt;
; Description:	FileRegister($ext, $cmd, $verb [, $def [, $icon = &amp;quot;&amp;quot; [, $desc = &amp;quot;&amp;quot; ]]])&lt;br /&gt;
;			   Registers a file type in Explorer&lt;br /&gt;
;&lt;br /&gt;
; Parameter(s): $ext -  File Extension without period eg. &amp;quot;zip&amp;quot;&lt;br /&gt;
;		$cmd -  Program path with arguments eg. &#039;&amp;quot;C:\test\testprog.exe&amp;quot; &amp;quot;%1&amp;quot;&#039;&lt;br /&gt;
;			 (%1 is 1st argument, %2 is 2nd, etc.)&lt;br /&gt;
;		$verb - Name of action to perform on file&lt;br /&gt;
;			 eg. &amp;quot;Open with ProgramName&amp;quot; or &amp;quot;Extract Files&amp;quot;&lt;br /&gt;
;		$def -  Action is the default action for this filetype&lt;br /&gt;
;			 (1 for true 0 for false)&lt;br /&gt;
;			 If the file is not already associated, this will be the default.&lt;br /&gt;
;		$icon - Default icon for filetype including resource # if needed&lt;br /&gt;
;			 eg. &amp;quot;C:\test\testprog.exe,0&amp;quot; or &amp;quot;C:\test\filetype.ico&amp;quot;&lt;br /&gt;
;		$desc - File Description eg. &amp;quot;Zip File&amp;quot; or &amp;quot;ProgramName Document&amp;quot;&lt;br /&gt;
;&lt;br /&gt;
;================================================&lt;br /&gt;
&lt;br /&gt;
 FileRegister(&amp;quot;uxy&amp;quot;, &#039;&amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot; &amp;quot;%1&amp;quot;&#039;, &amp;quot;Open in UXYFixer&amp;quot;, 1, @ScriptFullPath &amp;amp; &#039;,0&#039;, &amp;quot;UXYFixer Document&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
;========================================&lt;br /&gt;
;&lt;br /&gt;
; Description:	FileUnRegister($ext, $verb)&lt;br /&gt;
;			   UnRegisters a verb for a file type in Explorer&lt;br /&gt;
; Parameter(s):  $ext - File Extension without period eg. &amp;quot;zip&amp;quot;&lt;br /&gt;
;			   $verb - Name of file action to remove&lt;br /&gt;
;					 eg. &amp;quot;Open with ProgramName&amp;quot; or &amp;quot;Extract Files&amp;quot;&lt;br /&gt;
;&lt;br /&gt;
;========================================&lt;br /&gt;
&lt;br /&gt;
 FileUnRegister(&amp;quot;uxy&amp;quot;, &amp;quot;Open in UXYFixer&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download here:&#039;&#039;&#039;&lt;br /&gt;
[http://www.autoitscript.com/forum/index.php?app=core&amp;amp;module=attach&amp;amp;section=attach&amp;amp;attach_id=26378 FileRegister.au3]&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t my combobox (GUICtrlCreateCombo) show a dropdown list when clicked?==&lt;br /&gt;
When using GUICtrlCreateCombo be sure to enter the desired height for your combobox list in the &amp;quot;height&amp;quot; parameter. Windows XP automatically selects an appropriate height for combo boxes, but other versions of Windows usually do not.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;$combo = GUICtrlCreateCombo(&amp;quot;&amp;quot;,10,10,200,20)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Would correctly be changed to:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;$combo = GUICtrlCreateCombo(&amp;quot;&amp;quot;,10,10,200,200)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my thread getting any replies?==&lt;br /&gt;
&lt;br /&gt;
=== Asking the right question right ===&lt;br /&gt;
Did you give a good description of the problem? If your title or explanation of the issue is not descriptive, users are likely to bypass your issue instead of helping. Post titles such as &amp;quot;Help Me&amp;quot;, &amp;quot;I Have A Problem&amp;quot;, &amp;quot;Question&amp;quot;, &amp;quot;Help me fix my code&amp;quot;, &amp;quot;This code doesn&#039;t work&amp;quot; or similarly worded titles will not readily draw forum users to your post. Experienced users (which are your best hope of resolving the issue) will often skip your post altogether in cases like this. An example of a post title descriptive enough to attract users to assist you is &amp;quot;Problem with WinWaitClose&amp;quot; or &amp;quot;Loop never ends&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Example for reproduction ===&lt;br /&gt;
Did you post example code? If you have not posted an example of the code you are having an issue with, then you will not recieve support. When posting a non-working script, please do so in the smallest amount of stand-alone code possible. If the code you post cannot run by itself on another person&#039;s computer, they will not be able to recreate the issue.&lt;br /&gt;
&lt;br /&gt;
=== Speak English and speak it right ===&lt;br /&gt;
Did you use proper English? Here are guidelines for posting properly in the english language:&lt;br /&gt;
* Use proper case.  THIS IS CONSIDERED YELLING. If you post in ALL UPPERCASE or all lowercase then you will look like a doofus.&lt;br /&gt;
* Use proper punctuation. Complete sentences need only one trailing punctuation mark -- not three!!! Writing a sentance without simple punctuation such as commas or other punctuation is considered lazy, which is considered a good judge of the poster&#039;s coding style. If you cannot summon the strength to write a sentence with correct punctuation, you will most likely miss simple coding mistakes such as unterminated quotes.&lt;br /&gt;
&lt;br /&gt;
=== Breaking forum rules, law, modesty, or common Sense ===&lt;br /&gt;
Make sure you are not giving the impression of breaking forum rules, http://www.autoitscript.com/forum/forum-2/announcement-15-forum-rules-7-nov-2012/. Make sure you are not doing anything that can be perceived as breaking the law.&lt;br /&gt;
&lt;br /&gt;
==Why does the Ctrl key get stuck down after I run my script?==&lt;br /&gt;
&lt;br /&gt;
=== Keys virtually stuck ===&lt;br /&gt;
It could equally be the Shift Or the Alt key.&lt;br /&gt;
&lt;br /&gt;
If you use Send In a script And you have a problem With keys being stuck down Then Send is the most likely culprit. A similar problem can occur With BlockInput. The solution is generally quite simple. If there is a key like Shift Or Alt held down at the start of the Send sequence, but that key is released by the time the Send sequence finishes Then the key will get &#039;stuck&#039; down. As an example of a solution, you could replace the Send function in your script with the _SendEx function below.&lt;br /&gt;
&lt;br /&gt;
The _SendEx function waits for the Shift, Alt And Ctrl keys to be released or pops up a warning if the $warn parameter is not an empty string. Therefore it is not intended to be used when one of these modifier keys has been set to be down using any combination of {ALTDOWN}, {SHIFTDOWN} and {ALTDOWN}.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt; Misc.au3 &amp;gt;&lt;br /&gt;
;Send the string $ss after the Shift Alt and Ctrl keys are released. Optionally give a warning after 1 sec if any of those keys are still down.&lt;br /&gt;
;Requires misc.au3 to be included in the script for the _IsPressed function.&lt;br /&gt;
Func _SendEx($ss, $warn = &amp;quot;&amp;quot;)&lt;br /&gt;
	Local $iT = TimerInit()&lt;br /&gt;
&lt;br /&gt;
	While _IsPressed(&amp;quot;10&amp;quot;) Or _IsPressed(&amp;quot;11&amp;quot;) Or _IsPressed(&amp;quot;12&amp;quot;)&lt;br /&gt;
		If $warn &amp;lt;&amp;gt; &amp;quot;&amp;quot; And TimerDiff($iT) &amp;gt; 1000 Then&lt;br /&gt;
			MsgBox(262144, &amp;quot;Warning&amp;quot;, $warn)&lt;br /&gt;
		EndIf&lt;br /&gt;
		Sleep(50)&lt;br /&gt;
	WEnd&lt;br /&gt;
	Send($ss)&lt;br /&gt;
EndFunc;==&amp;gt;_SendEx&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General unstuck method ===&lt;br /&gt;
Shilbiz also discovered that the following can &#039;clear&#039; locked down keys.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt; ControlSend(&amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;text&amp;quot;, 0)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I use Pixel functions?==&lt;br /&gt;
&lt;br /&gt;
=== Using a color change as an event ===&lt;br /&gt;
The following is an example of using the pixel to check if the colour has changed in a specific region.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Local $PixelCheck = 0, $NewCheck&lt;br /&gt;
$PixelCheck = PixelCheckSum(40, 50, 60, 70); Get the checksum for this area.&lt;br /&gt;
While 1; Keep going&lt;br /&gt;
	$NewCheck = PixelCheckSum(40, 50, 60, 70)&lt;br /&gt;
	If $PixelCheck &amp;lt;&amp;gt; $NewCheck Then&lt;br /&gt;
		; The old pixel checksum and the new one are different.&lt;br /&gt;
		$PixelCheck = $NewCheck; Update the $PixelCheck to the new value&lt;br /&gt;
		; Let us know it has changed.  Change this to what you want to happen when the colour in the region changes.&lt;br /&gt;
		Msgbox(48,&amp;quot;PixelChecksum&amp;quot;,&amp;quot;Pixel region has changed !&amp;quot;)&lt;br /&gt;
	EndIf&lt;br /&gt;
	Sleep(50); Just to give the CPU a bit of a break.&lt;br /&gt;
Wend&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Searching for a specific pixel color ===&lt;br /&gt;
This is an example of searching for a specific pixel (red), both pure red (0xFF0000) and red in a few different shades.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; Find a pure red pixel in the range 0,0-20,300&lt;br /&gt;
$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000 )&lt;br /&gt;
If Not @error Then&lt;br /&gt;
	MsgBox(0, &amp;quot;X and Y are:&amp;quot;, $coord[0] &amp;amp; &amp;quot;,&amp;quot; &amp;amp; $coord[1])&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
; Find a pure red pixel or a red pixel within 10 shades variations of pure red&lt;br /&gt;
$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000, 10 )&lt;br /&gt;
If Not @error Then&lt;br /&gt;
	MsgBox(0, &amp;quot;X and Y are:&amp;quot;, $coord[0] &amp;amp; &amp;quot;,&amp;quot; &amp;amp; $coord[1])&lt;br /&gt;
EndIf&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t my script work on a locked workstation?==&lt;br /&gt;
On a locked station any window will never be active (active is only dialog with text &amp;quot;Press Ctrl+Alt+Del&amp;quot;).  In Windows locked state applications run hidden (behind that visible dialog) and do not have focus and active status.  So generally don&#039;t use Send() MouseClick() WinActivate() WinWaitActive() WinActive() etc.  Instead use ControlSend() ControlSetText() ControlClick() WinWait() WinExists() WinMenuSelectItem() etc.  This way you may have your script resistive against another active windows.  It&#039;s possible to run such a script from scheduler on locked Windows stations.&lt;br /&gt;
&lt;br /&gt;
==Where can I learn AutoIt? Are there any tutorials?==&lt;br /&gt;
To learn AutoIt you have two main options available to you:&lt;br /&gt;
&lt;br /&gt;
AutoIt 1-2-3, an interactive classroom by Valuater. You may find it here:&lt;br /&gt;
[http://www.autoitscript.com/forum/index.php?showtopic=21048 http://www.autoitscript.com/forum/index.php?showtopic=21048]&lt;br /&gt;
&lt;br /&gt;
There is also updated LxP&#039;s AutoIt tutorial by BrettF. You can find it here:&lt;br /&gt;
[http://www.autoitscript.com/forum/index.php?showtopic=84960 http://www.autoitscript.com/forum/index.php?showtopic=84960]&lt;br /&gt;
&lt;br /&gt;
There is also a book; AutoIt v3: Your Quick Guide by Andy Flessner.&lt;br /&gt;
You can buy the book from here:&lt;br /&gt;
[http://oreilly.com/catalog/9780596515126/ http://oreilly.com/catalog/9780596515126/]&lt;br /&gt;
&lt;br /&gt;
On YouTube there are many videos available:&lt;br /&gt;
[http://www.youtube.com/results?search_query=autoit+tutorial&amp;amp;search_type=&amp;amp;aq=0&amp;amp;oq=AutoIt http://www.youtube.com/results?search_query=autoit+tutorial&amp;amp;search_type=&amp;amp;aq=0&amp;amp;oq=AutoIt]&lt;br /&gt;
&lt;br /&gt;
==Why does my script no longer decompile?==&lt;br /&gt;
Decompilation is no longer supported, and is only available for the older versions of AutoIt (Version 3.2.5.1 and earlier compiled scripts).&lt;br /&gt;
&lt;br /&gt;
Please &#039;&#039;&#039;do not&#039;&#039;&#039; post on this topic, but search the forums for more information.  Posting topics like this will usually get the topic locked.&lt;br /&gt;
&lt;br /&gt;
Also posting the source (if a hacked decompiler was used) of other compiled scripts, or otherwise mentioning these hacked decompilers will probably get you banned.  It is also in violation of the AutoIt EULA (End-User-License-Agreement).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;You may not reverse engineer or disassemble the SOFTWARE PRODUCT or compiled scripts that were created with the SOFTWARE PRODUCT.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please see the [[Decompiling FAQ]] for more information.&lt;br /&gt;
&lt;br /&gt;
==How can I get a window handle when all I have is a PID?==&lt;br /&gt;
Refer to the following example showing converting and use when manipulating the window. The function is based on work by Smoke_N/Hubertus and Helge.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;;Run process&lt;br /&gt;
$iPID = Run(&amp;quot;Notepad.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
;Allow window to initialize...&lt;br /&gt;
Sleep (500)&lt;br /&gt;
&lt;br /&gt;
;Get HWND.&lt;br /&gt;
$hWnd = _GetHwndFromPID($iPID)&lt;br /&gt;
&lt;br /&gt;
;Maximize&lt;br /&gt;
WinSetState($hWnd, &amp;quot;&amp;quot;, @SW_MAXIMIZE)&lt;br /&gt;
&lt;br /&gt;
;Wait 2 seconds&lt;br /&gt;
Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
;Minimize&lt;br /&gt;
WinSetState($hWnd, &amp;quot;&amp;quot;, @SW_MINIMIZE)&lt;br /&gt;
&lt;br /&gt;
;Wait 2 seconds&lt;br /&gt;
Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
;Restore window&lt;br /&gt;
WinSetState($hWnd, &amp;quot;&amp;quot;, @SW_RESTORE)&lt;br /&gt;
&lt;br /&gt;
;Wait 2 seconds&lt;br /&gt;
Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
;Move top left corner of screen, and resize to 800x600&lt;br /&gt;
WinMove($hWnd, &amp;quot;&amp;quot;, 0, 0, 800, 600)&lt;br /&gt;
&lt;br /&gt;
;Wait 2 seconds&lt;br /&gt;
Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
;Calculate Center of screen.&lt;br /&gt;
$x = (@DesktopWidth / 2) - 400; Desktop width divided by 2, then minus half the width of the window&lt;br /&gt;
$y = (@DesktopHeight / 2) - 300; Desktop height divided by 2, then minus half the height of the window&lt;br /&gt;
&lt;br /&gt;
;Move to center of screen&lt;br /&gt;
WinMove($hWnd, &amp;quot;&amp;quot;, $x, $y)&lt;br /&gt;
&lt;br /&gt;
;Wait 2 seconds&lt;br /&gt;
Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
;Close notepad&lt;br /&gt;
WinClose($hWnd)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;Function for getting HWND from PID&lt;br /&gt;
Func _GetHwndFromPID($PID)&lt;br /&gt;
	$hWnd = 0&lt;br /&gt;
	$winlist = WinList()&lt;br /&gt;
	Do&lt;br /&gt;
		For $i = 1 To $winlist[0][0]&lt;br /&gt;
			If $winlist[$i][0] &amp;lt;&amp;gt; &amp;quot;&amp;quot; Then&lt;br /&gt;
				$iPID2 = WinGetProcess($winlist[$i][1])&lt;br /&gt;
				If $iPID2 = $PID Then&lt;br /&gt;
					$hWnd = $winlist[$i][1]&lt;br /&gt;
					ExitLoop&lt;br /&gt;
				EndIf&lt;br /&gt;
			EndIf&lt;br /&gt;
		Next&lt;br /&gt;
	Until $hWnd &amp;lt;&amp;gt; 0&lt;br /&gt;
	Return $hWnd&lt;br /&gt;
EndFunc;==&amp;gt;_GetHwndFromPID&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I use single or double quotes in strings?==&lt;br /&gt;
It is a fairly simple concept once you get the basics down.  Basically there are a few different ways to go about mixing quotes in strings.&lt;br /&gt;
&lt;br /&gt;
A string in AutoIt can be encased in either single(&#039;) or double (&amp;quot;) quotes.  So if you want to add only one type of quote into your string, your first port of call is to use the other type of quote to encase the string.  Like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;$var = &amp;quot;I am a &#039;quote&#039; inside the string&amp;quot;&lt;br /&gt;
MsgBox (0, &amp;quot;Test 1&amp;quot;, $var)&lt;br /&gt;
$var = &#039;I wish I could be a &amp;quot;quote&amp;quot; inside the string!&#039;&lt;br /&gt;
MsgBox (0, &amp;quot;Test 1&amp;quot;, $var)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have to have both types of quotes in the string, the easiest way is to escape the quote ending the string as so to speak.  To do this, use two quotes instead of one.  Like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;$var = &#039;I am a single &#039;&#039;quote&#039;&#039; inside the string made using &amp;quot;single quote!&amp;quot;&#039;&lt;br /&gt;
MsgBox (0, &amp;quot;Test 1&amp;quot;, $var)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==When should I bump my threads?==&lt;br /&gt;
As a courtesy to other users you should only bump your post once in a 24 hour period.  Doing this allows all users the chance to get helped equally.  Also refer to [http://www.autoitscript.com/forum/index.php?showtopic=95704&amp;amp;view=findpost&amp;amp;p=688050 Why isn&#039;t my thread getting any replies?], as this will help you get replies.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How can I protect my code from decompilation?==&lt;br /&gt;
The fact of the matter is &#039;&#039;&#039;you can&#039;t fully protect your code&#039;&#039;&#039;.  AutoIt is an  interpreted language, so all scripts are interpreted, and that script has to get stored somewhere.  There is still hope though.  You can take certain measures to prevent decompiled code from being usable to the person that decompiled.  The first step is to obfuscate your code.  This causes the code to become unreadable.  Basically variables and functions are renamed, making it very hard to make head or tail of what is what.&lt;br /&gt;
&lt;br /&gt;
Please see the [[Decompiling FAQ]] for more information.&lt;br /&gt;
&lt;br /&gt;
==How can I decompile my AutoIt EXEs?==&lt;br /&gt;
You cannot decompile your AutoIt compiled scripts unless it was compiled with AutoIt 3.2.5.1 or earlier.&lt;br /&gt;
&lt;br /&gt;
If you wish to simulate decompilation for your script, you can do this using the following simple example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;;Original Author SmokeN&lt;br /&gt;
If $CMDLINE[0] Then&lt;br /&gt;
	If $CMDLINE[1] == &amp;quot;/SOURCE&amp;quot; AND $CMDLINE[2] == &amp;quot;MYPASSWORD&amp;quot; Then&lt;br /&gt;
		FileInstall(&amp;quot;ThisSCript.au3&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\DecompiledScript.au3&amp;quot;)&lt;br /&gt;
	EndIf&lt;br /&gt;
EndIf&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then if you run the exe with the following command line parameters your source will be installed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;myscript.exe /SOURCE MYPASSWORD&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What is proper forum etiquette?  What rules are there for the forum?==&lt;br /&gt;
Proper forum etiquette will ensure you will stay a member of these forums.  So try to follow these rules.  Also see this [http://www.autoitscript.com/forum/index.php?showtopic=95704&amp;amp;st=15&amp;amp;p=688050&amp;amp;#entry688050 FAQ post], as you should follow what is outlined there as well.&lt;br /&gt;
&lt;br /&gt;
* Use proper English.  MSN speak and the like makes it very hard to understand what you want.  Keep posts in proper case because UPPERCASE is considered yelling and lowercase makes you look stupid.  Don&#039;t use more punctuation marks than necessary. For example ?!!!? and ????? is completely unnecessary.&lt;br /&gt;
* Before posting help with a script, make sure you follow these steps:&lt;br /&gt;
*# Search for your issue.&lt;br /&gt;
*#* There are many thousands of posts on this forum, and chances are your question has been asked before.  Make sure to use a variety of terms to maximize your results.&lt;br /&gt;
*# Read the helpfile&lt;br /&gt;
*#* Most if not all things in the help file will have an example (native functions) or two.  Give them a go to try see how the functions work.  Most of the time it helps!&lt;br /&gt;
*# Give it a go&lt;br /&gt;
*#* Seriously, if you can&#039;t be bothered to give it a go, then why should we be bothered to help you?  If you feel you can&#039;t do it and you don&#039;t try then how will you ever know?  We always prefer that you give it a go because you can learn from your mistakes and hopefully understand it better.&lt;br /&gt;
*# Post your problem&lt;br /&gt;
*#* Make sure you post in the correct forum.&lt;br /&gt;
*#** AutoIt Specific&lt;br /&gt;
*#*** General Help and Support (Most support questions)&lt;br /&gt;
*#*** GUI Support (Support for the Graphical User Interface)&lt;br /&gt;
*#** Non-AutoIT&lt;br /&gt;
*#*** Chat&lt;br /&gt;
*#*** Developer Chat (Usually for C++ questions.)&lt;br /&gt;
*#* Include a detailed description in the content of the post, and a detailed title&lt;br /&gt;
*#** Titles such as &#039;Help&#039; and &#039;What&#039;s wrong?&#039; are not acceptable.  To get the most help with your problem, be as descriptive as you can in the title, but keep in mind your title cannot be too long.&lt;br /&gt;
*#** Make sure you also include a descriptive question.  Just saying &#039;what is wrong with the following&#039; is also not acceptable, as we will have no idea what the problem is.  Describe what you think is wrong and what is not working.  It makes our job easier.&lt;br /&gt;
*#* Always include your code&lt;br /&gt;
*#** It shows us that you have tried and gives us a head start with something to play with.&lt;br /&gt;
* Usually asking for a script is not taken too well, within reason.  Keep in mind that this is a support forum, so please acknowledge that.   Most of us would rather that you learn rather than just having a script written for you.  If you do need something written for you, maybe try  [http://www.rentacoder.com/ RentACoder], as they are more suited to requests.&lt;br /&gt;
* Don&#039;t PM other members asking for them to look at threads of to help you unless they request it.  It is actually quite rude and annoying to receive PMs of that nature.&lt;br /&gt;
* Lurk a little before you dive right in. Read a number of posts, or check out the group&#039;s archives. Get a feel for the tone of the forum so you can participate accordingly.&lt;br /&gt;
* Say online exactly what you would say in person. In other words, if you wouldn&#039;t say it to the person&#039;s face in front of your Grandmother, you shouldn&#039;t type it here.&lt;br /&gt;
* Remember your face doesn&#039;t show. Words alone can convey sentiment, but without benefit of inflection or facial expression, they can be misconstrued. Use descriptive wording, emoticons or .gifs to ensure your meaning is clear. By the same token, don&#039;t jump to conclusions about another person&#039;s intent in posting an unclear comment. When in doubt, ask for clarification.&lt;br /&gt;
* Be respectful. Internet etiquette is similar to standard etiquette in this area. Appreciate that your opinion is one of many. You can disagree with another person without being disrespectful or rude to other people.&lt;br /&gt;
* Ignore Trolls. If you engage in conversation with one, you&#039;ll raise your blood pressure and empower the troll. You can&#039;t win a flame war, and you can&#039;t sway a troll&#039;s opinion. Often, they don&#039;t even care about the subject.  They live for the conflict and nothing more. Trolls are common and not worthy of your time. Ignore their posts no matter how inflammatory and eventually they&#039;ll get bored and move on.&lt;br /&gt;
* When you have found an answer for your question:&lt;br /&gt;
*# Do not edit your post to be blank or to have worthless information.  People may be searching for the same issue you have, so be courteous to them by leaving your question there.&lt;br /&gt;
*# It is also optional to add the likes of [SOLVED] into the title, and redirecting people to the answer that helped you.  It can make the lives of people searching easier.&lt;br /&gt;
* Finally follow the rules:&lt;br /&gt;
** [http://www.autoitscript.com/forum/forum-6/announcement-13-forum-rules/ Forum rules]&lt;br /&gt;
** [http://www.autoitscript.com/forum/index.php?showtopic=54168 Rules for the Chat forum]&lt;br /&gt;
** [http://www.autoitscript.com/forum/index.php?showtopic=65889 Rules for asking for source code]&lt;br /&gt;
** [http://www.autoitscript.com/forum/index.php?showtopic=37739 General policies and forum settings]&lt;br /&gt;
&lt;br /&gt;
Some general points taken from [http://www.ehow.com/how_2106033_use-proper-forum-etiquette.html here].&lt;br /&gt;
&lt;br /&gt;
==Are there forums available in my local language?==&lt;br /&gt;
Yes there are some available.  Some forum members here participate in multiple forums.&lt;br /&gt;
* [http://www.autoit.de/ German Forums]&lt;br /&gt;
* [http://www.autoit.fr/  French Forums]&lt;br /&gt;
* [http://www.autoit.es/ Spanish Forums]&lt;br /&gt;
* [http://autoit-script.ru/ Russian Forums]&lt;br /&gt;
&lt;br /&gt;
Please note that these are independent, community-run message boards and not just a translation of this board.&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Label&amp;diff=11548</id>
		<title>Label</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Label&amp;diff=11548"/>
		<updated>2013-01-15T17:49:17Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A Label is a simple, plain piece of text appearing in a [[Graphical User Interface|GUI]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
A Label is a GUI control, which consists of a simple, plain piece of text. The function for creating a Label is {{Help File|GuiCtrlCreateLabel}}. You can change the text of the label using {{Help File|GuiCtrlSetData}} and read it using {{Help File|GuiCtrlRead}} functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
This example demonstrates the creation of a GUI label.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
 #include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Opt(&#039;MustDeclareVars&#039;, 1)&lt;br /&gt;
&lt;br /&gt;
 Example()&lt;br /&gt;
&lt;br /&gt;
 Func Example()&lt;br /&gt;
     GUICreate(&amp;quot;My GUI&amp;quot;) ; will create a dialog box that when displayed is centered&lt;br /&gt;
&lt;br /&gt;
     GUISetHelp(&amp;quot;notepad&amp;quot;) ; will run notepad if F1 is typed&lt;br /&gt;
&lt;br /&gt;
     Opt(&amp;quot;GUICoordMode&amp;quot;, 2)&lt;br /&gt;
&lt;br /&gt;
     Local Const $widthCell = 70&lt;br /&gt;
&lt;br /&gt;
     GUICtrlCreateLabel(&amp;quot;Line 1 Cell 1&amp;quot;, 10, 30, $widthCell) ; first cell 70 width&lt;br /&gt;
     GUICtrlCreateLabel(&amp;quot;Line 2 Cell 1&amp;quot;, -1, 0)              ; next line&lt;br /&gt;
     GUICtrlCreateLabel(&amp;quot;Line 3 Cell 2&amp;quot;, 0, 0)               ; next line and next cell&lt;br /&gt;
     GUICtrlCreateLabel(&amp;quot;Line 3 Cell 3&amp;quot;, 0, -1)              ; next cell same line&lt;br /&gt;
     GUICtrlCreateLabel(&amp;quot;Line 4 Cell 1&amp;quot;, -3 * $widthCell, 0) ; next line Cell1&lt;br /&gt;
&lt;br /&gt;
     GUISetState() ; will display an empty dialog box&lt;br /&gt;
&lt;br /&gt;
     ; Run the GUI until the dialog is closed&lt;br /&gt;
     Do&lt;br /&gt;
     Until GUIGetMsg() = $GUI_EVENT_CLOSE&lt;br /&gt;
&lt;br /&gt;
 EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_Internet_)&amp;diff=11521</id>
		<title>Snippets ( Internet )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_Internet_)&amp;diff=11521"/>
		<updated>2013-01-15T15:12:15Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* _ValidIP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
[[category:Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Snippet Credit Header}}&lt;br /&gt;
&lt;br /&gt;
== Auto-Check For User To Update ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 4920-valuater&lt;br /&gt;
 | AuthorName = Valuater&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Auto-Check For User To Update&lt;br /&gt;
&lt;br /&gt;
Global $Udif, $QT_web = &amp;quot;www.XPCleanMenu.HostRocket.com&amp;quot;&lt;br /&gt;
Call(&amp;quot;Set_Updater&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
;test&lt;br /&gt;
$Uask = MsgBox(68, &amp;quot;Update Notification&amp;quot;, &amp;quot; Your last update was more than &amp;quot; &amp;amp; $Udif &amp;amp; &amp;quot; days ago.&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Would you like to check for new updates now?&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
If $Uask = 6 Then MsgBox(0, &amp;quot;&amp;quot;, &amp;quot;Success.  The update was ran.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func Set_Updater()&lt;br /&gt;
	If Not FileExists(@SystemDir &amp;amp; &amp;quot;\UpDate.dat&amp;quot;) Then&lt;br /&gt;
		FileWrite(@SystemDir &amp;amp; &amp;quot;\UpDate.dat&amp;quot;, @YDAY)&lt;br /&gt;
	Else&lt;br /&gt;
		$Uold = FileReadLine(@SystemDir &amp;amp; &amp;quot;\UpDate.dat&amp;quot;, 1)&lt;br /&gt;
&lt;br /&gt;
		If $Uold &amp;gt;=320 Then&lt;br /&gt;
			FileDelete(@SystemDir &amp;amp; &amp;quot;\UpDate.dat&amp;quot;)&lt;br /&gt;
			Return&lt;br /&gt;
		EndIf&lt;br /&gt;
&lt;br /&gt;
		$Udif = @YDAY - $Uold&lt;br /&gt;
&lt;br /&gt;
		If $Udif &amp;gt;= 45 Then&lt;br /&gt;
			$Uask = MsgBox(68, &amp;quot;UpDate Notification&amp;quot;, &amp;quot; Your last UpDate was more than &amp;quot; &amp;amp; $Udif &amp;amp; &amp;quot; days ago  &amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Would you like to check for new updates now?        &amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
			If $Uask = 6 Then&lt;br /&gt;
				Run(@ProgramFilesDir &amp;amp; &amp;quot;\Internet Explorer\iexplore.exe &amp;quot; &amp;amp; $QT_web)&lt;br /&gt;
				WinWaitActive(&amp;quot;&amp;quot;)&lt;br /&gt;
			EndIf&lt;br /&gt;
&lt;br /&gt;
			FileDelete(@SystemDir &amp;amp; &amp;quot;\UpDate.dat&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
			FileWrite(@SystemDir &amp;amp; &amp;quot;\UpDate.dat&amp;quot;, @YDAY)&lt;br /&gt;
		EndIf&lt;br /&gt;
	EndIf&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _GetIEVersion ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 35302-guinness&lt;br /&gt;
 | AuthorName = guinness&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Check IE Version.&lt;br /&gt;
ConsoleWrite(_GetIEVersion() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetIEVersion()&lt;br /&gt;
    Return StringRegExpReplace(RegRead(&#039;HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\&#039;, &#039;Version&#039;), &#039;^(\d+\.\d+).*&#039;, &#039;$1&#039;)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetIEVersion&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _GetTimeOnline ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 35302-guinness&lt;br /&gt;
 | AuthorName = guinness&lt;br /&gt;
 | Desc = Retrieve the current time from TimeAPI.org.  Ideal if your Windows clock is out of sync.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Retrieve the current time from TimeAPI.org.  Ideal if your Windows clock is out of sync.&lt;br /&gt;
ConsoleWrite(_GetTimeOnline(0) &amp;amp; @CRLF) ; TimeZone UTC.&lt;br /&gt;
&lt;br /&gt;
; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name ..........: _GetTimeOnline&lt;br /&gt;
; Description ...: Retrieve the current date and time from TimeAPI.org.&lt;br /&gt;
; Syntax ........: _GetTimeOnline($iTimeZone)&lt;br /&gt;
; Parameters ....: $iTimeZone           - An integer value of the timezone .&lt;br /&gt;
;				   0 - UTC (Universal Time)&lt;br /&gt;
;				   1 - EST (Eastern Time)&lt;br /&gt;
;				   2 - CST (Central Time)&lt;br /&gt;
;				   3 - MST (Mountain Time)&lt;br /&gt;
;				   4 - PST (Pacific Time)&lt;br /&gt;
;				   5 - AKST (Alaska Time)&lt;br /&gt;
;				   6 - HAST (Hawaii-Aleutian Time)&lt;br /&gt;
; Return values .: Success: Returns the current Date and Time in the format YYYY/MM/DD HH:MM:SS&lt;br /&gt;
;				   Failure: Sets @error to non-zero and returns the same format as a successful return but using the system time.&lt;br /&gt;
; Author ........: guinness&lt;br /&gt;
; Link ..........: According to http://www.programmableweb.com/api/timeapi, this is for non-commercial use.&lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _GetTimeOnline($iTimeZone)&lt;br /&gt;
	Local $aTimeZone[7] = [&#039;utc&#039;, &#039;est&#039;, &#039;cst&#039;, &#039;mst&#039;, &#039;pst&#039;, &#039;akst&#039;, &#039;hast&#039;]&lt;br /&gt;
&lt;br /&gt;
	Local $sRead = BinaryToString(InetRead(&#039;http://www.timeapi.org/&#039; &amp;amp; $aTimeZone[$iTimeZone] &amp;amp; &#039;/now?format=\Y/\m/\d%20\H:\M:\S&#039;))&lt;br /&gt;
&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Return SetError(1, 0, @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/&#039; &amp;amp; @MDAY &amp;amp; &#039; &#039; &amp;amp; @HOUR &amp;amp; &#039;:&#039; &amp;amp; @MIN &amp;amp; &#039;:&#039; &amp;amp; @SEC)&lt;br /&gt;
	EndIf&lt;br /&gt;
&lt;br /&gt;
	Return $sRead&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetTimeOnline&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _HTML_StripTags ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 25246-robjong&lt;br /&gt;
 | AuthorName = Robjong&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox(4096, &amp;quot;&amp;quot;, _HTML_StripTags(&amp;quot;This should be # - (&amp;amp;#35;)&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
; Strip HTML tags from HTML syntax. By Robjong.&lt;br /&gt;
Func _HTML_StripTags($sHTMLData) ; http://www.autoitscript.com/forum/topic/...tml-data/page__view__findpost_&lt;br /&gt;
    If $sHTMLData = &amp;quot;&amp;quot; Then Return SetError(1, 0, $sHTMLData)&lt;br /&gt;
&lt;br /&gt;
    Local $oHTML = ObjCreate(&amp;quot;HTMLFILE&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    If @error Then Return SetError(1, 0, $sHTMLData)&lt;br /&gt;
&lt;br /&gt;
    $oHTML.Open()&lt;br /&gt;
    $oHTML.Write($sHTMLData)&lt;br /&gt;
&lt;br /&gt;
    Return SetError(0, 0, $oHTML.Body.InnerText)&lt;br /&gt;
EndFunc   ;==&amp;gt;_HTML_StripTags&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _InetGetOutOfProcess ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 35302-guinness&lt;br /&gt;
 | AuthorName = guinness&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
ConsoleWrite(_InetGetOutOfProcess(&#039;http://google.com&#039;, @TempDir &amp;amp; &#039;\Google.tmp&#039;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Download a file by spawning a new AutoIt process.&lt;br /&gt;
Func _InetGetOutOfProcess($sURL, $sFilePath, $iOptions = 0)&lt;br /&gt;
    Return RunWait(&#039;&amp;quot;&#039; &amp;amp; @AutoItExe &amp;amp; &#039;&amp;quot; /AutoIt3ExecuteLine &#039; &amp;amp; &#039;&amp;quot;Exit InetGet(&amp;quot;&amp;quot;&#039; &amp;amp; $sURL &amp;amp; &#039;&amp;quot;&amp;quot;, &amp;quot;&amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot;&amp;quot;, &#039; &amp;amp; $iOptions &amp;amp; &#039;, 0)&amp;quot;&#039;) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_InetGetOutOfProcess&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _IsInternetConnected ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 35302-guinness&lt;br /&gt;
 | AuthorName = guinness&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
ConsoleWrite(&amp;quot;Internet Is Connected&amp;quot; &amp;amp; &amp;quot; = &amp;quot; &amp;amp; _IsInternetConnected() &amp;amp; @CRLF) ; ( Returns &amp;quot;True&amp;quot; Or &amp;quot;False&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
Func _IsInternetConnected()&lt;br /&gt;
    Local $aReturn = DllCall(&#039;connect.dll&#039;, &#039;long&#039;, &#039;IsInternetConnected&#039;)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, False)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $aReturn[0] = 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsInternetConnected&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _IsIP ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 4813-smoke-n&lt;br /&gt;
 | AuthorName = SmOke_N&lt;br /&gt;
 | Desc = Checks to see if a string is a valid IP address.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Checks to see if a string is a valid IP address.&lt;br /&gt;
&lt;br /&gt;
If _IsIP(&amp;quot;127.0.0.1&amp;quot;) Then Msgbox(0, &amp;quot;&amp;quot;, &amp;quot;Valid IP address.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _IsIP($ip)&lt;br /&gt;
	Return StringRegExp ($ip, &amp;quot;^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$&amp;quot;)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _IsValidIP ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 20477-mrcreator&lt;br /&gt;
 | AuthorName = MrCreatoR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local Const $sString = @IPAddress2 &amp;amp; &amp;quot;:8080&amp;quot; ;8080 is port value (for example)&lt;br /&gt;
&lt;br /&gt;
Local Const $GetValidIp = _IsValidIP($sString, &amp;quot;:&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite($GetValidIp)&lt;br /&gt;
&lt;br /&gt;
Local $IPsArray = _StringToIPArray(&#039;99.77.88.255 567567567 text 155.99.66.6 some more text &#039; &amp;amp; @IPAddress1 &amp;amp; &#039;,&#039; &amp;amp; @IPAddress2)&lt;br /&gt;
&lt;br /&gt;
_ArrayDisplay($IPsArray)&lt;br /&gt;
&lt;br /&gt;
Func _IsValidIP($sString, Const $sDelim = &amp;quot;&amp;quot;)&lt;br /&gt;
    If Not StringInStr($sString, &amp;quot;.&amp;quot;) Then Return 0&lt;br /&gt;
&lt;br /&gt;
    If $sDelim &amp;lt;&amp;gt; &amp;quot;&amp;quot; Then $sString = StringLeft($sString, StringInStr($sString, $sDelim) - 1)&lt;br /&gt;
&lt;br /&gt;
    If StringLen($sString) &amp;gt; 15 Then Return 0&lt;br /&gt;
&lt;br /&gt;
    Local $Dot_Split = StringSplit($sString, &amp;quot;.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    Local $iUbound = UBound($Dot_Split) - 1&lt;br /&gt;
&lt;br /&gt;
    If $iUbound &amp;lt;&amp;gt; 4 Then Return 0&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To $iUbound&lt;br /&gt;
        If $Dot_Split[$i] = &amp;quot;&amp;quot; Then Return 0&lt;br /&gt;
        If StringRegExp($Dot_Split[$i], &#039;[^0-9]&#039;) Or Number($Dot_Split[$i]) &amp;gt; 255 Then Return 0&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    If $sDelim &amp;lt;&amp;gt; &amp;quot;&amp;quot; Then Return $sString&lt;br /&gt;
    Return 1&lt;br /&gt;
EndFunc&lt;br /&gt;
&lt;br /&gt;
Func _StringToIPArray($sString)&lt;br /&gt;
    Local $avArray = StringRegExp($sString, &#039;([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)&#039;, 3)&lt;br /&gt;
    Local $avRetArr[1], $iUbound&lt;br /&gt;
&lt;br /&gt;
    For $i = 0 To UBound($avArray)-1&lt;br /&gt;
        If _IsValidIP($avArray[$i]) Then&lt;br /&gt;
            $iUbound = UBound($avRetArr)&lt;br /&gt;
            ReDim $avRetArr[$iUbound+1]&lt;br /&gt;
            $avRetArr[$iUbound] = $avArray[$i]&lt;br /&gt;
        EndIf&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    If $iUbound = 0 Then Return SetError(1, 0, 0)&lt;br /&gt;
&lt;br /&gt;
    $avRetArr[0] = $iUbound&lt;br /&gt;
    Return $avRetArr&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _IsValidURL ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 44525-jscript&lt;br /&gt;
 | AuthorName = JScript&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Author: JScript - Snippet Version No. = 1.0&lt;br /&gt;
;Snippet was Created Using AutoIt Version = 3.3.8.1, Creation Date = 22/05/12.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&amp;quot;Is Valid URL? &amp;quot; &amp;amp; _IsValidURL(&amp;quot;http:www.autoitscript.com&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(&amp;quot;Is Valid URL? &amp;quot; &amp;amp; _IsValidURL(&amp;quot;www.autoitscript.com&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _IsValidURL($sPath)&lt;br /&gt;
    Local Const $sRet = DllCall(&amp;quot;Shlwapi.dll&amp;quot;, &amp;quot;BOOL&amp;quot;, &amp;quot;PathIsURL&amp;quot;, &amp;quot;str&amp;quot;, $sPath)&lt;br /&gt;
    Return $sRet[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsValidURL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _Toggle_Images ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 8730-big-daddy&lt;br /&gt;
 | AuthorName = big_daddy&lt;br /&gt;
 | Desc = Toggle Internet Images On/Off&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Toggle Internet Images On/Off&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;IE.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Opt(&amp;quot;WinTitleMatchMode&amp;quot;, 2)&lt;br /&gt;
&lt;br /&gt;
_Toggle_Images(1)&lt;br /&gt;
Global Const $oIE = _IECreate ()&lt;br /&gt;
&lt;br /&gt;
_IENavigate ($oIE, &amp;quot;http:\\www.google.com&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
While WinExists(&amp;quot;Internet Explorer&amp;quot;)&lt;br /&gt;
    Sleep(250)&lt;br /&gt;
WEnd&lt;br /&gt;
_Toggle_Images()&lt;br /&gt;
&lt;br /&gt;
Func _Toggle_Images($On_Off=0)&lt;br /&gt;
    If $On_Off == 0 Then&lt;br /&gt;
        RegWrite(&amp;quot;HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main&amp;quot;, &amp;quot;Display Inline Images&amp;quot;, &amp;quot;REG_SZ&amp;quot;, &amp;quot;yes&amp;quot;)&lt;br /&gt;
    Else&lt;br /&gt;
        RegWrite(&amp;quot;HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main&amp;quot;, &amp;quot;Display Inline Images&amp;quot;, &amp;quot;REG_SZ&amp;quot;, &amp;quot;no&amp;quot;)&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc ;==&amp;gt;_Toggle_Images()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _Tracert ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 35302-guinness&lt;br /&gt;
 | AuthorName = guinness&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;Constants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_Tracert(&amp;quot;www.duckduckgo.com&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _Tracert(Const $sURL)&lt;br /&gt;
	; -d = Do Not Resolve Host &amp;amp; -h Is The Number Of Hops.&lt;br /&gt;
	Local Const $sData = _RunStdOutRead(&#039;tracert -d -h 1 &#039; &amp;amp; $sURL, @SystemDir)&lt;br /&gt;
&lt;br /&gt;
	Local Const $aReturn = StringRegExp($sData, &#039;\[([\d.]{7,15})\]&#039;, 3)&lt;br /&gt;
&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Return SetError(1, 0, -1)&lt;br /&gt;
	EndIf&lt;br /&gt;
&lt;br /&gt;
	Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_Tracert&lt;br /&gt;
&lt;br /&gt;
Func _RunStdOutRead($sCommand, $sWorkingDirectory = @SystemDir)&lt;br /&gt;
	Local Const $iPID = Run(@ComSpec &amp;amp; &#039; /c &#039; &amp;amp; $sCommand, $sWorkingDirectory, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sOutput = &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
	While 1&lt;br /&gt;
		$sOutput &amp;amp;= StdoutRead($iPID)&lt;br /&gt;
&lt;br /&gt;
		If @error Then&lt;br /&gt;
			ExitLoop&lt;br /&gt;
		EndIf&lt;br /&gt;
	WEnd&lt;br /&gt;
&lt;br /&gt;
	Return $sOutput&lt;br /&gt;
EndFunc   ;==&amp;gt;_RunStdOutRead&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _ValidIP ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 58912-brewmannh&lt;br /&gt;
 | AuthorName = BrewManNH&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt; ; This is only needed for the _ArrayDisplay function used in the example below, and is not needed for the _ValidIP function&lt;br /&gt;
&lt;br /&gt;
; IPv4 validation script&lt;br /&gt;
Global Const $IPAddress = &amp;quot;192.168.2.1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Global Const $Return = _ValidIP($IPAddress)&lt;br /&gt;
&lt;br /&gt;
If $Return &amp;lt; 0 Then&lt;br /&gt;
    Switch @error&lt;br /&gt;
        Case 1&lt;br /&gt;
            MsgBox(64, &amp;quot;&amp;quot;, &amp;quot;Error in IP address: &amp;quot; &amp;amp; $IPAddress &amp;amp; @LF &amp;amp; &amp;quot;Error code is: 1 - IP address starts with an invalid number = 0, 127 , 169 or is &amp;gt; 239&amp;quot;)&lt;br /&gt;
        Case 2&lt;br /&gt;
            MsgBox(64, &amp;quot;&amp;quot;, &amp;quot;Error in IP address: &amp;quot; &amp;amp; $IPAddress &amp;amp; @LF &amp;amp; &amp;quot;Error code is: 2 - one of the octets of the IP address is out of the range 0-255 or contains invalid characters&amp;quot;)&lt;br /&gt;
        Case 3&lt;br /&gt;
            MsgBox(64, &amp;quot;&amp;quot;, &amp;quot;Error in IP address: &amp;quot; &amp;amp; $IPAddress &amp;amp; @LF &amp;amp; &amp;quot;Error code is: 3 - IP Address is not a valid dotted IP address (ex. valid address 190.40.100.20)&amp;quot;)&lt;br /&gt;
        Case 4&lt;br /&gt;
            MsgBox(64, &amp;quot;&amp;quot;, &amp;quot;Error in IP address: &amp;quot; &amp;amp; $IPAddress &amp;amp; @LF &amp;amp; &amp;quot;Error code is: 4 - Last octet is either 0 or 255&amp;quot;)&lt;br /&gt;
    EndSwitch&lt;br /&gt;
Else&lt;br /&gt;
    MsgBox(48, &amp;quot;&amp;quot;, $IPAddress &amp;amp; &amp;quot; is a valid Class &amp;quot; &amp;amp; $Return[5] &amp;amp; &amp;quot; IP address&amp;quot;)&lt;br /&gt;
    _ArrayDisplay($Return)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
; FUNCTION# ===========================================================================================================&lt;br /&gt;
; Name...........: _ValidIP&lt;br /&gt;
; Description ...: Verifies whether an IP address is a valid IPv4 address or not&lt;br /&gt;
; Syntax.........: _ValidIP($sIP)&lt;br /&gt;
; Parameters ....: $sIP - IP address to validate&lt;br /&gt;
;&lt;br /&gt;
; Return values .: Success - Array containing split IP Address, IP address in Hex, and the Class of the IP address&lt;br /&gt;
;                            array[0] - [3] = the IP address split into octets&lt;br /&gt;
;                            array[4]       = IP address in Hex&lt;br /&gt;
;                            array[5]       = Class of the IP address [A through D]&lt;br /&gt;
;                  Failure - -1, sets @error&lt;br /&gt;
;                  |1 - IP address starts with an invalid number = 0, 127 , 169 or is &amp;gt; 239&lt;br /&gt;
;                  |2 - one of the octets of the IP address is out of the range 0-255 or contains invalid characters&lt;br /&gt;
;                  |3 - IP Address is not a valid dotted IP address (ex. valid address 190.40.100.20)&lt;br /&gt;
;                  |4 - Last octet ends in 0 or 255 which are invalid for an IP address&lt;br /&gt;
; Author ........: BrewManNH&lt;br /&gt;
; Modified.......:&lt;br /&gt;
; Remarks .......: This will accept an IP address that is 4 octets long, and contains only numbers and falls within&lt;br /&gt;
;                  valid IP address values. Class A networks can&#039;t start with 0 or 127. 169.xx.xx.xx is reserved and is&lt;br /&gt;
;                  invalid and any address that starts above 239, ex. 240.xx.xx.xx is reserved. The address range&lt;br /&gt;
;                  224-239 1s reserved as well for Multicast groups but can be a valid IP address range if you&#039;re using&lt;br /&gt;
;                  it as such. Any IP address ending in 0 or 255 is also invalid for an IP&lt;br /&gt;
; Related .......:&lt;br /&gt;
; Link ..........:&lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; =====================================================================================================================&lt;br /&gt;
Func _ValidIP($sIP)&lt;br /&gt;
    Local $adIPAddressInfo[6]&lt;br /&gt;
&lt;br /&gt;
    Local $aArray = StringSplit($sIP, &amp;quot;.&amp;quot;, 2)&lt;br /&gt;
&lt;br /&gt;
    If Not IsArray($aArray) Or UBound($aArray) &amp;lt;&amp;gt; 4 Then Return SetError(3, 0, -1)&lt;br /&gt;
&lt;br /&gt;
    Local $dString = &amp;quot;0x&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    If $aArray[0] &amp;lt;= 0 Or $aArray[0] &amp;gt; 239 Or $aArray[0] = 127 Or $aArray[0] = 169 Then&lt;br /&gt;
        Return SetError(1, 0, -1)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    For $I = 0 To 3&lt;br /&gt;
        If $I &amp;lt; 3 Then&lt;br /&gt;
            If $aArray[$I] &amp;lt; 0 Or $aArray[$I] &amp;gt; 255 Or Not StringIsDigit($aArray[$I]) Then&lt;br /&gt;
                Return SetError(2, 0, -1)&lt;br /&gt;
            EndIf&lt;br /&gt;
        Else&lt;br /&gt;
            If Not StringIsDigit($aArray[$I]) Then&lt;br /&gt;
                Return SetError(2, 0, -1)&lt;br /&gt;
            EndIf&lt;br /&gt;
&lt;br /&gt;
            If $aArray[$I] &amp;lt; 1 Or $aArray[$I] &amp;gt; 254 Then&lt;br /&gt;
                Return SetError(4, 0, -1)&lt;br /&gt;
            EndIf&lt;br /&gt;
        EndIf&lt;br /&gt;
&lt;br /&gt;
        $dString &amp;amp;= StringRight(Hex($aArray[$I]), 2)&lt;br /&gt;
&lt;br /&gt;
        $adIPAddressInfo[$I] = $aArray[$I]&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    $adIPAddressInfo[4] = $dString&lt;br /&gt;
&lt;br /&gt;
    Switch $aArray[0]&lt;br /&gt;
        Case 1 To 126&lt;br /&gt;
            $adIPAddressInfo[5] = &amp;quot;A&amp;quot;&lt;br /&gt;
            Return $adIPAddressInfo&lt;br /&gt;
        Case 128 To 191&lt;br /&gt;
            $adIPAddressInfo[5] = &amp;quot;B&amp;quot;&lt;br /&gt;
            Return $adIPAddressInfo&lt;br /&gt;
        Case 192 To 223&lt;br /&gt;
            $adIPAddressInfo[5] = &amp;quot;C&amp;quot;&lt;br /&gt;
            Return $adIPAddressInfo&lt;br /&gt;
        Case 224 To 239&lt;br /&gt;
            $adIPAddressInfo[5] = &amp;quot;D&amp;quot;&lt;br /&gt;
            Return $adIPAddressInfo&lt;br /&gt;
    EndSwitch&lt;br /&gt;
EndFunc   ;==&amp;gt;_ValidIP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=UDF-spec&amp;diff=11499</id>
		<title>UDF-spec</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=UDF-spec&amp;diff=11499"/>
		<updated>2012-12-26T21:10:10Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Constants */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:UDF]]&lt;br /&gt;
{{WIP}}This page is still under construction.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A library is a collection of one or more User Defined Functions (UDFs). However, the term UDF is often used to describe the collection as a whole. If a UDF is to be considered for inclusion in the standard set distributed with AutoIt then it must meet all the criteria detailed here, but it&#039;s also good practice to always write in conformance with at least the majority of this document, as that is what will be expected by people reading your code later.&lt;br /&gt;
&lt;br /&gt;
== Basic Requirements ==&lt;br /&gt;
Firstly, the code itself should meet the following basic requirements:&lt;br /&gt;
&lt;br /&gt;
* Be tidied. Just hit &amp;lt;code&amp;gt;Ctrl+T&amp;lt;/code&amp;gt; from SciTE or run Tidy manually. The only flag needed is &amp;lt;code&amp;gt;/sf&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Pass Au3Check with no errors using the strictest settings: &amp;lt;code&amp;gt;-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&amp;lt;/code&amp;gt;&lt;br /&gt;
* Support everything AutoIt supports. In some cases features may not be able to support everything, in which case this should be checked for and return errors appropriately. This applies to: windows OS versions (AutoIt has support for all OS&#039; from windows 2000), unicode and ansi strings, 64 and 32 bit machines.&lt;br /&gt;
* Ideally it will be able to run cleanly when obfuscated. Although there will be some cases where this is not possible, please consider it when writing UDFs, and avoid the use of Execute and similar statements. If it does not, then document it as such.&lt;br /&gt;
&lt;br /&gt;
== UDF Outline ==&lt;br /&gt;
The library itself has a header that details important information such as the minimum OS and AutoIt versions, and what system dlls are required. There is also a number of other sections that are required that list what is present in the UDF.&lt;br /&gt;
&lt;br /&gt;
=== Includes ===&lt;br /&gt;
Since a UDF is designed to define functions, it should only be included once. As a result, the &amp;lt;code&amp;gt;#include-once&amp;lt;/code&amp;gt; directive should be used. This is typically the first line of the UDF, followed by the includes used by the UDF. Include statements should use the double quoted form, as the library is expected to work in the same directory as libraries it depends on. Non standard libraries can be used if necessary, but this should be documented and linked to so users can download it as well. It goes without saying that a UDF based on non-standard UDFs cannot itself become a standard.&lt;br /&gt;
&lt;br /&gt;
=== Index ===&lt;br /&gt;
The index follows the following template (taken from &amp;lt;code&amp;gt;WinAPI.au3&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #INDEX# =======================================================================================================================&lt;br /&gt;
; Title .........: Windows API&lt;br /&gt;
; AutoIt Version : 3.2&lt;br /&gt;
; Description ...: Windows API calls that have been translated to AutoIt functions.&lt;br /&gt;
; Author(s) .....: Paul Campbell (PaulIA), gafrost, Siao, Zedna, arcker, Prog@ndy, PsaltyDS, Raik, jpm&lt;br /&gt;
; Dll ...........: kernel32.dll, user32.dll, gdi32.dll, comdlg32.dll, shell32.dll, ole32.dll, winspool.drv&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only required element in the index header is &amp;lt;code&amp;gt;Title&amp;lt;/code&amp;gt;. All others are ignored by the processor, but should be included for reference&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Dll&amp;lt;/code&amp;gt; field can remain empty in many cases where no dlls are called directly. This header must be defined.&lt;br /&gt;
&lt;br /&gt;
=== Other Sections ===&lt;br /&gt;
Other sections, in order of appearance, are as follows.&lt;br /&gt;
&lt;br /&gt;
==== Variables ====&lt;br /&gt;
All global variables needed to be declared in the UDF are defined in this section. They should follow the variable rules for globals. Individual variables do not need to be documented, as it is assumed they are for internal use only. Any globals designed to be accessible for the user should instead be wrapped by a function (or multiple functions if globals must be retrieved and set). The template for this section is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #VARIABLES# ===================================================================================================================&lt;br /&gt;
Global $__gvMyGlobal = 0&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If no globals are needed then this section may be ommitted. Please consider the use of global variables carefully, and read through the section on global variables.&lt;br /&gt;
&lt;br /&gt;
==== Constants ====&lt;br /&gt;
Any global constant values are defined in this section. This should be constants only designated for use within the library itself. Constants that may be needed by the user should be defined in a separate file, named &amp;lt;code&amp;gt;UDFConstants.au3&amp;lt;/code&amp;gt; where &amp;lt;code&amp;gt;UDF&amp;lt;/code&amp;gt; is the name of the parent file. For example &amp;lt;code&amp;gt;File.au3&amp;lt;/code&amp;gt; uses constants defined in &amp;lt;code&amp;gt;FileConstants.au3&amp;lt;/code&amp;gt;. The exception to that rule is control UDFs which miss out the prepended &#039;GUI&#039; when naming constant files, so &amp;lt;code&amp;gt;GUIButton.au3&amp;lt;/code&amp;gt; uses constants from &amp;lt;code&amp;gt;ButtonConstants.au3&amp;lt;/code&amp;gt;. The template for this section is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #CONSTANTS# ===================================================================================================================&lt;br /&gt;
Global Const $__MYUDFCONSTANT_FOOBAR = 42&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If no constants are needed in this section, either because none are used or because they are stored in a separate file, then it may be ommitted. Please read the section on global constants for specific info on naming and definition of constants.&lt;br /&gt;
&lt;br /&gt;
==== Listing ====&lt;br /&gt;
This defines all functions and structures currently used functions in the library. It MUST be the second defined header item after [[#Index]]. It is a simple list with each function on a line where the functions and structures appear in the same order as they do in the code, which is alphabetical order and structures first. A simple way to generate this list is to create a small script that searches for function definitions and outputs them in the correct format, an example of which is [http://www.autoitscript.com/forum/topic/120820-function-name-lister/ here]. In addition there is a second section that lists functions and structures for internal use only, this does not need to appear if none are defined.&lt;br /&gt;
&lt;br /&gt;
The template for these sections are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #CURRENT# =====================================================================================================================&lt;br /&gt;
;$tagSTRUCT&lt;br /&gt;
;_MyUDF_Function&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
&lt;br /&gt;
; #INTERNAL_USE_ONLY# ===========================================================================================================&lt;br /&gt;
;$tagINTERNALSTRUCT&lt;br /&gt;
;__MyUDF_InternalFunction&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This section still needs to be defined for files that only define constants. It should also be noted that there MUST NOT be a space between the &amp;lt;code&amp;gt;;&amp;lt;/code&amp;gt; and the function/structure name.&lt;br /&gt;
&lt;br /&gt;
==== Undocumented Listing ====&lt;br /&gt;
There is a final kind of listing that lists functions for which no documentation exists, or they have been deprecated and are only included for backwards compatibility. These are listed in a section with the header &amp;lt;code&amp;gt;NO_DOC_FUNCTION&amp;lt;/code&amp;gt;. This is very rarely used, and is reserved only for functions that can be utilised by the user, or that would have been in the past, as opposed to those for internal use only.&lt;br /&gt;
&lt;br /&gt;
Template:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #NO_DOC_FUNCTION# =============================================================================================================&lt;br /&gt;
;_MyUDF_Function&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Renamed Functions ====&lt;br /&gt;
Although it should not be the case in new UDFs, many of the older ones (particularly to do with controls) have had script breaking name changes to functions. These are documented in the UDF to ensure updating old scripts is as easy as possible. The basic format for this is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #NO_DOC_FUNCTION# =============================================================================================================&lt;br /&gt;
;_MyUDF_OldFunction                        ; --&amp;gt; _MyUDF_NewFunction&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The space padding is optional. This section is ignored as far as the docs are concerned, and is usually omitted.&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
=== Naming ===&lt;br /&gt;
Function names must start with an underscore, and the first word is the library name. There is then usually another underscore before the rest of the function name. The library name should be consistent across all the functions in the library, and can be shortened if a logical abbreviation is available (e.g. &amp;lt;code&amp;gt;Window&amp;lt;/code&amp;gt; ==&amp;gt; &amp;lt;code&amp;gt;Win&amp;lt;/code&amp;gt;). Each word should be capitalized, but no underscores are placed in the rest of the name, for example &amp;lt;code&amp;gt;_WinAPI_GetWindowLong&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For control libraries, the first part of the function name is changed slightly. For example the UDF for listviews would use &amp;lt;code&amp;gt;_GUICtrlListview_*&amp;lt;/code&amp;gt;. When a function wraps a dll call, then the second part should closely resemble the function name as it appears in other languages. This also applies to functions acting as a wrapper to &amp;lt;code&amp;gt;SendMessage&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Functions are defined in alphabetical order by name, which is the same as using &amp;lt;code&amp;gt;Tidy&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;/sf&amp;lt;/code&amp;gt; flag set.&lt;br /&gt;
&lt;br /&gt;
=== Parameters ===&lt;br /&gt;
Parameters should follow the variable naming scheme ([[#Naming_2|here]]). All parameters must be checked to ensure they are valid, and return unique and documented error codes if they are not. For functions involving a specific type of control, this includes checking the class name using &amp;lt;code&amp;gt;_WinAPI_IsClassName&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Parameters that are optional or byref should be documented as such, and the effect these have explicitly stated. For example a byref parameter should detail exactly what the expected output is as well as the input.&lt;br /&gt;
&lt;br /&gt;
=== Headers ===&lt;br /&gt;
All functions have a documentation header that describes the function. This uses the following template:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name...........: _WinAPI_GetMousePos&lt;br /&gt;
; Description ...: Returns the current mouse position&lt;br /&gt;
; Syntax.........: _WinAPI_GetMousePos([$fToClient = False[, $hWnd = 0]])&lt;br /&gt;
; Parameters ....: $fToClient   - If True, the coordinates will be converted to client coordinates&lt;br /&gt;
;                  $hWnd        - Window handle used to convert coordinates if $fToClient is True&lt;br /&gt;
; Return values .: Success      - $tagPOINT structure with current mouse position&lt;br /&gt;
;                  Failure      - Zero&lt;br /&gt;
; Author ........: Paul Campbell (PaulIA)&lt;br /&gt;
; Modified.......:&lt;br /&gt;
; Remarks .......: This function takes into account the current MouseCoordMode setting when  obtaining  the  mouse  position.  It&lt;br /&gt;
;                  will also convert screen to client coordinates based on the parameters passed.&lt;br /&gt;
; Related .......: $tagPOINT, _WinAPI_GetMousePosX, _WinAPI_GetMousePosY&lt;br /&gt;
; Link ..........: &lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _WinAPI_GetMousePos($fToClient = False, $hWnd = 0)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The header is 129 characters wide, and any text within it should be wrapped to that length. For example the &amp;lt;code&amp;gt;Remarks&amp;lt;/code&amp;gt; in the above header has been extended to cover two lines. The exception to that rule is the &amp;lt;code&amp;gt;Syntax&amp;lt;/code&amp;gt; line, which should not be wrapped. Some of the parameters in the header are optional, in which case they should remain, but be left empty (for example the &amp;lt;code&amp;gt;Link&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Modified&amp;lt;/code&amp;gt; lines in the above header). In others, they are needed, but can be empty or not used such as &amp;lt;code&amp;gt;Parameters&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Return Values&amp;lt;/code&amp;gt;. In this case the value should be &#039;None&#039;, as they will still be present in the documentation.&lt;br /&gt;
&lt;br /&gt;
There are some flags that can be used within function headers: &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;+&#039;&#039;&#039; in column 20 is the continuation flag for the previous line (used in Parameters, Return Values)&lt;br /&gt;
* &#039;&#039;&#039;|&#039;&#039;&#039; in column 20 is a new line in the right side of the table when the help file is generated (used in Parameters, Return Values)&lt;br /&gt;
* &#039;&#039;&#039;-&#039;&#039;&#039; in column 20 will create new row in the table, used for things like Defaults for a style (used in Parameters, Return Values)&lt;br /&gt;
* &#039;&#039;&#039;+&#039;&#039;&#039; in column 2 of Remarks is a blank line&lt;br /&gt;
Name&lt;br /&gt;
:Specifies the name of the function. This will be identical to how it appeas in the Func statement in the code itself.&lt;br /&gt;
Description&lt;br /&gt;
:Gives a short summary of what the function does. This should only be a single line, as it is only designed to give a short impression of what is happening. For the standard set of includes distributed with AutoIt3, this value is also used in the SciTE calltips.&lt;br /&gt;
Syntax&lt;br /&gt;
:Describes the syntax of the function call. This differs slightly from what appears in the code itself for optional parameters, which are enclosed in square brackets (&amp;quot;[ ]&amp;quot;). Since subsequent parameters must also be optional, and cannot be defined unless all the previous ones have been given, these brackets are nested in the form: Function([param1[, param2[,param3]]]). Note that the opening bracket appears before the comma seperator.&lt;br /&gt;
Parameters&lt;br /&gt;
:This is a list of the arguments accepted by the function. Each is listed, followed by a dash (&amp;quot;-&amp;quot;) and a description of what it is. The dash can be padded for neatness, although the amount of padding depends on how long the parameter names are. If the parameter is optional then the meaning of the default value should be given, similarly if it&#039;s used to pass data back to the program in the form of byref then the changes made should also be detailed. For more information on parameters see Parameters.&lt;br /&gt;
Return values&lt;br /&gt;
:Details what is returned by the function. This often comes in the form of Success and Failure values, but this is not always the case. Any setting of the @error of @extended flags should be detailed, along with their meanings, in some cases it is enough to say that @error is set to non-zero in the event of an error, in most cases though a list of values for @error should be given.&lt;br /&gt;
Author&lt;br /&gt;
:This is the original writer of the function. It should contain the username, so that any queries about the code can be made through the forum, but you can give as much or little information as you feel appropriate.&lt;br /&gt;
Modified&lt;br /&gt;
:This is a list of modifications made. At it&#039;s most basic this is just a list of users who have made changes, but ideally it includes some information about what they did, in which cases it follows the same form as other multi-value lines, with the username and description of modifications seperated by a dash.&lt;br /&gt;
Remarks&lt;br /&gt;
:This is anything the user should know about a function in order to use it. For example exceptional cases and recommended ways to handle the function should all be detailed here, as well as additional info about possible reasons for failure and how to deal with them.&lt;br /&gt;
Related&lt;br /&gt;
:A comma seperated list of functions or structures related to the function.&lt;br /&gt;
Link&lt;br /&gt;
:A link to additional information about the function. For many system function wrappers, this will be &amp;lt;code&amp;gt;@@MsdnLink@@ FunctionName&amp;lt;/code&amp;gt;, which represents that the user should search MSDN for the function.&lt;br /&gt;
Example&lt;br /&gt;
:A simple yes or no value specifying whether the function has an example. If this is no then your UDF is not ready to be released. The [[#Examples]] section has more information on the format and location of examples.&lt;br /&gt;
&lt;br /&gt;
The easiest way to generate the header is to copy and paste the following blank template in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name...........: &lt;br /&gt;
; Description ...: &lt;br /&gt;
; Syntax.........: &lt;br /&gt;
; Parameters ....: &lt;br /&gt;
; Return values .: &lt;br /&gt;
; Author ........: &lt;br /&gt;
; Modified.......: &lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; Link ..........: &lt;br /&gt;
; Example .......: &lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also a number of plugins for SciTE that will generate a header and maybe fill in certain known values for you such as Name, Syntax and Parameters. The most complete one that conforms to these standards is [http://code.google.com/p/m-a-t/wiki/UDFHeaderGenerator here], but there are two others [http://www.autoitscript.com/forum/topic/28270-lua-script-for-udf-header/ here] and [http://www.autoitscript.com/forum/topic/28270-lua-script-for-udf-header/page__view__findpost__p__200823 here].&lt;br /&gt;
&lt;br /&gt;
=== Internal use only ===&lt;br /&gt;
Functions can also be marked for use only within the library and not to be documented for use by the user. These are named according to the same rules as normal functions but begin with a double underscore (&amp;quot;__&amp;quot;). The header is exactly the same except with the first line replaced, to make the blank template:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #INTERNAL_USE_ONLY# ===========================================================================================================&lt;br /&gt;
; Name...........: &lt;br /&gt;
; Description ...: &lt;br /&gt;
; Syntax.........: &lt;br /&gt;
; Parameters ....: &lt;br /&gt;
; Return values .: &lt;br /&gt;
; Author ........: &lt;br /&gt;
; Modified.......: &lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; Link ..........: &lt;br /&gt;
; Example .......: &lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Structures ==&lt;br /&gt;
Structures are defined as global constants, and follow the naming pattern &amp;lt;code&amp;gt;$tagSTRUCTNAME&amp;lt;/code&amp;gt;. The struct name should be as it appears on MSDN if it&#039;s used in the windows API, or follow a similar pattern if not. It should go without saying that they must work for both 32 and 64 bit machines, including resolving any alignment issues. Elements should also be named as they appear on MSDN if they are taken from there, which includes the hungarian notation prefix. Although many standard UDFs do not follow that rule, importantly &amp;lt;code&amp;gt;StructureConstants.au3&amp;lt;/code&amp;gt;, the rule still stands.&lt;br /&gt;
&lt;br /&gt;
=== Headers ===&lt;br /&gt;
Structures need a header similar to functions, but with some minor differences. The same rules apply in terms of wrapping and line length however. The header follow this standard template:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #STRUCTURE# ===================================================================================================================&lt;br /&gt;
; Name...........: $tagPOINT&lt;br /&gt;
; Description ...: Defines the x and y coordinates of a point&lt;br /&gt;
; Fields ........: X - Specifies the x-coordinate of the point&lt;br /&gt;
;                  Y - Specifies the y-coordinate of the point&lt;br /&gt;
; Author ........: Paul Campbell (PaulIA)&lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Global Const $tagPOINT = &amp;quot;long X;long Y&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is essentially a shortened header, with the only thing new is the Fields line, which effectively replaces the Parameters field in terms of usage. All the same rules apply as listed [[#Function Header Fields|here]].&lt;br /&gt;
&lt;br /&gt;
The blank template is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #STRUCTURE# ===================================================================================================================&lt;br /&gt;
; Name...........: &lt;br /&gt;
; Description ...: &lt;br /&gt;
; Fields ........: &lt;br /&gt;
; Author ........: &lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Structures may also be marked for internal use only. In this case the header ramains the same, but the sections first line changes. The blank template is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #INTERNAL_USE_ONLY# ===========================================================================================================&lt;br /&gt;
; Name...........: &lt;br /&gt;
; Description ...: &lt;br /&gt;
; Fields ........: &lt;br /&gt;
; Author ........: &lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variables ==&lt;br /&gt;
For code readability, there are special rules dealing with variables, particularly naming. All variables should be declared at the beginning of their scope, which usually means at the start of the function in which they are used, but could mean the top of the UDF itself in the [[#Variables|Variables section]].&lt;br /&gt;
&lt;br /&gt;
=== Naming ===&lt;br /&gt;
A variable&#039;s first letter signifies the expected type of the variable. This should be as follows:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;$a&amp;amp;lt;letter&amp;amp;gt;&amp;lt;/code&amp;gt; - Array (the following letter describes the data type taken from the rest of the data types below, if it varies then &amp;lt;code&amp;gt;v&amp;lt;/code&amp;gt; should be used. A counter as the first element is ignored, so the array returned by StringSplit (with default options) would actually be marked as $as despite the integer in the zeroeth element).&lt;br /&gt;
* &amp;lt;code&amp;gt;$d&amp;lt;/code&amp;gt; - Binary data.&lt;br /&gt;
* &amp;lt;code&amp;gt;$h&amp;lt;/code&amp;gt; - Handle, usually to a file or window. NB: AutoIt handled controls return IDs, and so use $id instead.&lt;br /&gt;
* &amp;lt;code&amp;gt;$id&amp;lt;/code&amp;gt; - An AutoIt control Id.&lt;br /&gt;
* &amp;lt;code&amp;gt;$i&amp;lt;/code&amp;gt; - Integer.&lt;br /&gt;
* &amp;lt;code&amp;gt;$b&amp;lt;/code&amp;gt; - Boolean.&lt;br /&gt;
* &amp;lt;code&amp;gt;$f&amp;lt;/code&amp;gt; - Floating point number.&lt;br /&gt;
* &amp;lt;code&amp;gt;$n&amp;lt;/code&amp;gt; - general number with no preference for floating point or integer.&lt;br /&gt;
* &amp;lt;code&amp;gt;$s&amp;lt;/code&amp;gt; - String.&lt;br /&gt;
* &amp;lt;code&amp;gt;$v&amp;lt;/code&amp;gt; - Variant (unknown/variable type of data) .&lt;br /&gt;
* &amp;lt;code&amp;gt;$p&amp;lt;/code&amp;gt; - Pointer. It is assumed that it points to a struct so no further letters are needed. The type of struct being pointed to should be inferrable from the variable name e.g. &amp;lt;code&amp;gt;$pWindowRect&amp;lt;/code&amp;gt; can be assumed to be a pointer to a &amp;lt;code&amp;gt;$tagRECT&amp;lt;/code&amp;gt; structure.&lt;br /&gt;
* &amp;lt;code&amp;gt;$t&amp;lt;/code&amp;gt; - Structure returned from DllStructCreate.&lt;br /&gt;
* &amp;lt;code&amp;gt;$tag&amp;lt;/code&amp;gt; - Struct definition string.Structure definitions should conform to the structure guidelines.&lt;br /&gt;
&lt;br /&gt;
=== Globals ===&lt;br /&gt;
The use of globals in a UDF is generally frowned upon, and byref parameters and static variables should be used where possible instead. However, in cases where this is not possible and a global must be used they should be defined using the following naming pattern: &amp;lt;code&amp;gt;$__g&amp;amp;lt;VARNAME&amp;amp;gt;_&amp;amp;lt;UDF&amp;amp;gt;&amp;lt;/code&amp;gt; where &amp;lt;code&amp;gt;&amp;amp;lt;VARNAME&amp;amp;gt;&amp;lt;/code&amp;gt; is the name as it would usually appear according to the variable naming rules above and &amp;lt;code&amp;gt;&amp;amp;lt;UDF&amp;amp;gt;&amp;lt;/code&amp;gt; is the name of the library in which it appears. This ensures there will never be a conflict with user variables of other UDF globals. They should be declared at the top of the UDF in the Variables section.&lt;br /&gt;
&lt;br /&gt;
Globals are always private. If they need to be accessed by the user then functions need to be written wrapping that operation and values should be checked. Notable exceptions are debug variables, which are designed for developer purposes and may be used by some users in extreme cases. These are named &amp;lt;code&amp;gt;$Debug_&amp;amp;lt;UDF&amp;amp;gt;&amp;lt;/code&amp;gt; although the &amp;lt;code&amp;gt;&amp;amp;lt;UDF&amp;amp;gt;&amp;lt;/code&amp;gt; part is often shortened so &amp;lt;code&amp;gt;GUIEdit.au3&amp;lt;/code&amp;gt; uses &amp;lt;code&amp;gt;$Debug_Ed&amp;lt;/code&amp;gt;. It is not required that a UDF has debugging symbols, but they are allowed to remain in releases.&lt;br /&gt;
&lt;br /&gt;
=== Constants ===&lt;br /&gt;
There are two types of constants, internal and public. Public constants are designed to be utilised by the user, and are referenced in functions that use them. They include styles and flags. Internal constants are designed for use only within the library, so that values used fairly often can be held in one place to allow for easy updating. Both kinds of constant are always typed in all upper case. Constants taken from the windows API should appear exactly as they are defined there, but internal constants follow the naming pattern: &amp;lt;code&amp;gt;$__&amp;amp;lt;UDF&amp;amp;gt;CONSTANT_&amp;amp;lt;NAME&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== The &amp;lt;code&amp;gt;Dim&amp;lt;/code&amp;gt; statement ===&lt;br /&gt;
Should not be used.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
All functions and structures that are made public to the user need to have a good quality example. This means that it should:&lt;br /&gt;
&lt;br /&gt;
* Be simple. Ideally the only functions used are basic functions like ConsoleWrite and MsgBox and the function that the example is written for. Writing a single example that covers a wide range of functions is not nearly as easy to use as writing an example per function that clearly demonstrates its use.&lt;br /&gt;
* Be readable. Everything should be explained step by step in comments.&lt;br /&gt;
* Be correct. In addition to passing the same Au3Check flags as the UDF itself (&amp;lt;code&amp;gt;-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&amp;lt;/code&amp;gt;) it should always be written with best practice being the main consideration. This takes preference over the first point, just because code is shorter and looks easier doesn&#039;t mean it&#039;s right.&lt;br /&gt;
* Examples should represent all the functionality. If there is more than one way of using a function then include more than one example of how to use it.&lt;br /&gt;
&lt;br /&gt;
Examples are stored in individual files called &amp;lt;code&amp;gt;&amp;amp;lt;FUNCTION&amp;amp;gt;.au3&amp;lt;/code&amp;gt;. The files should be kept in a folder called &amp;lt;code&amp;gt;Examples&amp;lt;/code&amp;gt;. To remain correct all examples should be wrapped in functions, such that the only code executed in the global scope is calling the function. This is usually named &amp;lt;code&amp;gt;Example&amp;lt;/code&amp;gt;, though where multiple examples exists they are named &amp;lt;code&amp;gt;Example1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Example2&amp;lt;/code&amp;gt;, ..., &amp;lt;code&amp;gt;ExampleN&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Opt(&amp;quot;MustDeclareVars&amp;quot;, 1)&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
	Local $idButton_1, $idButton_2, $iMsg, $hGUI&lt;br /&gt;
	&lt;br /&gt;
	$hGUI = GUICreate(&amp;quot;My GUI Button&amp;quot;) ; Will create a dialog box that when displayed is centered&lt;br /&gt;
&lt;br /&gt;
	$idButton_1 = GUICtrlCreateButton(&amp;quot;Run Notepad&amp;quot;, 4, 4, 80, 30)&lt;br /&gt;
	$idButton_2 = GUICtrlCreateButton(&amp;quot;Button Test&amp;quot;, 4, 38, 80, 30)&lt;br /&gt;
&lt;br /&gt;
	GUISetState() ; will display a dialog box with 2 button&lt;br /&gt;
&lt;br /&gt;
	; Run the GUI until the dialog is closed&lt;br /&gt;
	While 1&lt;br /&gt;
		$iMsg = GUIGetMsg()&lt;br /&gt;
		Select&lt;br /&gt;
			Case $iMsg = $GUI_EVENT_CLOSE&lt;br /&gt;
				ExitLoop&lt;br /&gt;
			Case $iMsg = $idButton_1&lt;br /&gt;
				Run(&amp;quot;Notepad.exe&amp;quot;) ; Will Run/Open Notepad&lt;br /&gt;
			Case $iMsg = $idButton_2&lt;br /&gt;
				MsgBox(0, &amp;quot;Testing&amp;quot;, &amp;quot;Button 2 was pressed&amp;quot;) ; Will demonstrate Button 2 being pressed&lt;br /&gt;
		EndSelect&lt;br /&gt;
	WEnd&lt;br /&gt;
	GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Template UDF ==&lt;br /&gt;
Here is an example of a UDF called &amp;lt;code&amp;gt;MyUDF.au3&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include-once&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;MyUDFConstants.au3&amp;quot;&lt;br /&gt;
#include &amp;quot;AnInclude.au3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; #INDEX# =======================================================================================================================&lt;br /&gt;
; Title .........: MyUDF&lt;br /&gt;
; AutoIt Version : 3.3.6.1&lt;br /&gt;
; Language ......: English&lt;br /&gt;
; Description ...: An example UDF that does very little.&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
&lt;br /&gt;
; #CURRENT# =====================================================================================================================&lt;br /&gt;
;$tagMYSTRUCT&lt;br /&gt;
;_MyUDF_Function&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
&lt;br /&gt;
; #STRUCTURE# ===================================================================================================================&lt;br /&gt;
; Name...........: $tagMYSTRUCT&lt;br /&gt;
; Description ...: An example of a structure.&lt;br /&gt;
; Fields ........: hFoo       - A handle to foo that does something.&lt;br /&gt;
;                  iBar       - An integer that does something.&lt;br /&gt;
; Author ........: Matt Diesel (Mat)&lt;br /&gt;
; Remarks .......:&lt;br /&gt;
; Related .......: _MyUDF_Function&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Global Const $tagMYSTRUCT = &amp;quot;ptr hFoo; int iBar&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name...........: _MyUDF_Function&lt;br /&gt;
; Description ...: A function that does something.&lt;br /&gt;
; Syntax.........: _MyUDF_Function(ByRef $avAnArray, $iAnInt[, $hAHandle = 0[, $nSomeNumber = 42]])&lt;br /&gt;
; Parameters ....: $avAnArray       - [byref] An array of anything. The value of anything is changed and passed out using this&lt;br /&gt;
;                                     parameter. The array should only have one dimension&lt;br /&gt;
;                  $iAnInt          - An integer that does very little.&lt;br /&gt;
;                  $hAHandle        - [optional] A handle. Default is zero.&lt;br /&gt;
;                  $nSomeNumber     - [optional] A number of some kind. Default is 42.&lt;br /&gt;
; Return values .: Success          - A MYSTRUCT structure.&lt;br /&gt;
;                  Failure          - Returns zero and sets the @error flag:&lt;br /&gt;
;                                   |1 - The $avAnArray is invalid.&lt;br /&gt;
; Author ........: Matt Diesel (Mat)&lt;br /&gt;
; Modified.......:&lt;br /&gt;
; Remarks .......:&lt;br /&gt;
; Related .......: $tagMYSTRUCT&lt;br /&gt;
; Link ..........:&lt;br /&gt;
; Example .......: No&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _MyUDF_Function(ByRef $avAnArray, $iAnInt, $hAHandle = 0, $nSomeNumber = 42)&lt;br /&gt;
	; 1 - Error Checking for parameters.&lt;br /&gt;
	If Not IsArray($avAnArray) Or UBound($avAnArray, 0) &amp;lt;&amp;gt; 1 Then Return SetError(1, 0, 0) ; The $avAnArray is invalid.&lt;br /&gt;
&lt;br /&gt;
	; 2 - Declaration of locals.&lt;br /&gt;
	Local $tMS = DllStructCreate($tagMYSTRUCT)&lt;br /&gt;
&lt;br /&gt;
	; 3 - Function code&lt;br /&gt;
	DllStructSetData($tMS, &amp;quot;hFoo&amp;quot;, $hAHandle)&lt;br /&gt;
	DllStructSetData($tMS, &amp;quot;iBar&amp;quot;, $iAnInt * $nSomeNumber)&lt;br /&gt;
&lt;br /&gt;
	Return $tMS&lt;br /&gt;
EndFunc   ;==&amp;gt;_MyUDF_Function&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=UDF-spec&amp;diff=11498</id>
		<title>UDF-spec</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=UDF-spec&amp;diff=11498"/>
		<updated>2012-12-26T21:05:38Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Naming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:UDF]]&lt;br /&gt;
{{WIP}}This page is still under construction.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A library is a collection of one or more User Defined Functions (UDFs). However, the term UDF is often used to describe the collection as a whole. If a UDF is to be considered for inclusion in the standard set distributed with AutoIt then it must meet all the criteria detailed here, but it&#039;s also good practice to always write in conformance with at least the majority of this document, as that is what will be expected by people reading your code later.&lt;br /&gt;
&lt;br /&gt;
== Basic Requirements ==&lt;br /&gt;
Firstly, the code itself should meet the following basic requirements:&lt;br /&gt;
&lt;br /&gt;
* Be tidied. Just hit &amp;lt;code&amp;gt;Ctrl+T&amp;lt;/code&amp;gt; from SciTE or run Tidy manually. The only flag needed is &amp;lt;code&amp;gt;/sf&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Pass Au3Check with no errors using the strictest settings: &amp;lt;code&amp;gt;-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&amp;lt;/code&amp;gt;&lt;br /&gt;
* Support everything AutoIt supports. In some cases features may not be able to support everything, in which case this should be checked for and return errors appropriately. This applies to: windows OS versions (AutoIt has support for all OS&#039; from windows 2000), unicode and ansi strings, 64 and 32 bit machines.&lt;br /&gt;
* Ideally it will be able to run cleanly when obfuscated. Although there will be some cases where this is not possible, please consider it when writing UDFs, and avoid the use of Execute and similar statements. If it does not, then document it as such.&lt;br /&gt;
&lt;br /&gt;
== UDF Outline ==&lt;br /&gt;
The library itself has a header that details important information such as the minimum OS and AutoIt versions, and what system dlls are required. There is also a number of other sections that are required that list what is present in the UDF.&lt;br /&gt;
&lt;br /&gt;
=== Includes ===&lt;br /&gt;
Since a UDF is designed to define functions, it should only be included once. As a result, the &amp;lt;code&amp;gt;#include-once&amp;lt;/code&amp;gt; directive should be used. This is typically the first line of the UDF, followed by the includes used by the UDF. Include statements should use the double quoted form, as the library is expected to work in the same directory as libraries it depends on. Non standard libraries can be used if necessary, but this should be documented and linked to so users can download it as well. It goes without saying that a UDF based on non-standard UDFs cannot itself become a standard.&lt;br /&gt;
&lt;br /&gt;
=== Index ===&lt;br /&gt;
The index follows the following template (taken from &amp;lt;code&amp;gt;WinAPI.au3&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #INDEX# =======================================================================================================================&lt;br /&gt;
; Title .........: Windows API&lt;br /&gt;
; AutoIt Version : 3.2&lt;br /&gt;
; Description ...: Windows API calls that have been translated to AutoIt functions.&lt;br /&gt;
; Author(s) .....: Paul Campbell (PaulIA), gafrost, Siao, Zedna, arcker, Prog@ndy, PsaltyDS, Raik, jpm&lt;br /&gt;
; Dll ...........: kernel32.dll, user32.dll, gdi32.dll, comdlg32.dll, shell32.dll, ole32.dll, winspool.drv&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only required element in the index header is &amp;lt;code&amp;gt;Title&amp;lt;/code&amp;gt;. All others are ignored by the processor, but should be included for reference&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Dll&amp;lt;/code&amp;gt; field can remain empty in many cases where no dlls are called directly. This header must be defined.&lt;br /&gt;
&lt;br /&gt;
=== Other Sections ===&lt;br /&gt;
Other sections, in order of appearance, are as follows.&lt;br /&gt;
&lt;br /&gt;
==== Variables ====&lt;br /&gt;
All global variables needed to be declared in the UDF are defined in this section. They should follow the variable rules for globals. Individual variables do not need to be documented, as it is assumed they are for internal use only. Any globals designed to be accessible for the user should instead be wrapped by a function (or multiple functions if globals must be retrieved and set). The template for this section is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #VARIABLES# ===================================================================================================================&lt;br /&gt;
Global $__gvMyGlobal = 0&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If no globals are needed then this section may be ommitted. Please consider the use of global variables carefully, and read through the section on global variables.&lt;br /&gt;
&lt;br /&gt;
==== Constants ====&lt;br /&gt;
Any global constant values are defined in this section. This should be constants only designated for use within the library itself. Constants that may be needed by the user should be defined in a seperate file, named &amp;lt;code&amp;gt;UDFConstants.au3&amp;lt;/code&amp;gt; where &amp;lt;code&amp;gt;UDF&amp;lt;/code&amp;gt; is the name of the parent file. For example &amp;lt;code&amp;gt;File.au3&amp;lt;/code&amp;gt; uses constants defined in &amp;lt;code&amp;gt;FileConstants.au3&amp;lt;/code&amp;gt;. The exception to that rule is control UDFs which miss out the prepended &#039;GUI&#039; when naming constant files, so &amp;lt;code&amp;gt;GUIButton.au3&amp;lt;/code&amp;gt; uses constants from &amp;lt;code&amp;gt;ButtonConstants.au3&amp;lt;/code&amp;gt;. The template for this section is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #CONSTANTS# ===================================================================================================================&lt;br /&gt;
Global Const $__MYUDFCONSTANT_FOOBAR = 42&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If no constants are needed in this section, either because non are used or because they are stored in a seperate file, then it may be ommitted. Please read the section on global constants for specific info on naming and definition of constants.&lt;br /&gt;
&lt;br /&gt;
==== Listing ====&lt;br /&gt;
This defines all functions and structures currently used functions in the library. It MUST be the second defined header item after [[#Index]]. It is a simple list with each function on a line where the functions and structures appear in the same order as they do in the code, which is alphabetical order and structures first. A simple way to generate this list is to create a small script that searches for function definitions and outputs them in the correct format, an example of which is [http://www.autoitscript.com/forum/topic/120820-function-name-lister/ here]. In addition there is a second section that lists functions and structures for internal use only, this does not need to appear if none are defined.&lt;br /&gt;
&lt;br /&gt;
The template for these sections are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #CURRENT# =====================================================================================================================&lt;br /&gt;
;$tagSTRUCT&lt;br /&gt;
;_MyUDF_Function&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
&lt;br /&gt;
; #INTERNAL_USE_ONLY# ===========================================================================================================&lt;br /&gt;
;$tagINTERNALSTRUCT&lt;br /&gt;
;__MyUDF_InternalFunction&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This section still needs to be defined for files that only define constants. It should also be noted that there MUST NOT be a space between the &amp;lt;code&amp;gt;;&amp;lt;/code&amp;gt; and the function/structure name.&lt;br /&gt;
&lt;br /&gt;
==== Undocumented Listing ====&lt;br /&gt;
There is a final kind of listing that lists functions for which no documentation exists, or they have been deprecated and are only included for backwards compatibility. These are listed in a section with the header &amp;lt;code&amp;gt;NO_DOC_FUNCTION&amp;lt;/code&amp;gt;. This is very rarely used, and is reserved only for functions that can be utilised by the user, or that would have been in the past, as opposed to those for internal use only.&lt;br /&gt;
&lt;br /&gt;
Template:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #NO_DOC_FUNCTION# =============================================================================================================&lt;br /&gt;
;_MyUDF_Function&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Renamed Functions ====&lt;br /&gt;
Although it should not be the case in new UDFs, many of the older ones (particularly to do with controls) have had script breaking name changes to functions. These are documented in the UDF to ensure updating old scripts is as easy as possible. The basic format for this is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #NO_DOC_FUNCTION# =============================================================================================================&lt;br /&gt;
;_MyUDF_OldFunction                        ; --&amp;gt; _MyUDF_NewFunction&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The space padding is optional. This section is ignored as far as the docs are concerned, and is usually omitted.&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
=== Naming ===&lt;br /&gt;
Function names must start with an underscore, and the first word is the library name. There is then usually another underscore before the rest of the function name. The library name should be consistent across all the functions in the library, and can be shortened if a logical abbreviation is available (e.g. &amp;lt;code&amp;gt;Window&amp;lt;/code&amp;gt; ==&amp;gt; &amp;lt;code&amp;gt;Win&amp;lt;/code&amp;gt;). Each word should be capitalized, but no underscores are placed in the rest of the name, for example &amp;lt;code&amp;gt;_WinAPI_GetWindowLong&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For control libraries, the first part of the function name is changed slightly. For example the UDF for listviews would use &amp;lt;code&amp;gt;_GUICtrlListview_*&amp;lt;/code&amp;gt;. When a function wraps a dll call, then the second part should closely resemble the function name as it appears in other languages. This also applies to functions acting as a wrapper to &amp;lt;code&amp;gt;SendMessage&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Functions are defined in alphabetical order by name, which is the same as using &amp;lt;code&amp;gt;Tidy&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;/sf&amp;lt;/code&amp;gt; flag set.&lt;br /&gt;
&lt;br /&gt;
=== Parameters ===&lt;br /&gt;
Parameters should follow the variable naming scheme ([[#Naming_2|here]]). All parameters must be checked to ensure they are valid, and return unique and documented error codes if they are not. For functions involving a specific type of control, this includes checking the class name using &amp;lt;code&amp;gt;_WinAPI_IsClassName&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Parameters that are optional or byref should be documented as such, and the effect these have explicitly stated. For example a byref parameter should detail exactly what the expected output is as well as the input.&lt;br /&gt;
&lt;br /&gt;
=== Headers ===&lt;br /&gt;
All functions have a documentation header that describes the function. This uses the following template:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name...........: _WinAPI_GetMousePos&lt;br /&gt;
; Description ...: Returns the current mouse position&lt;br /&gt;
; Syntax.........: _WinAPI_GetMousePos([$fToClient = False[, $hWnd = 0]])&lt;br /&gt;
; Parameters ....: $fToClient   - If True, the coordinates will be converted to client coordinates&lt;br /&gt;
;                  $hWnd        - Window handle used to convert coordinates if $fToClient is True&lt;br /&gt;
; Return values .: Success      - $tagPOINT structure with current mouse position&lt;br /&gt;
;                  Failure      - Zero&lt;br /&gt;
; Author ........: Paul Campbell (PaulIA)&lt;br /&gt;
; Modified.......:&lt;br /&gt;
; Remarks .......: This function takes into account the current MouseCoordMode setting when  obtaining  the  mouse  position.  It&lt;br /&gt;
;                  will also convert screen to client coordinates based on the parameters passed.&lt;br /&gt;
; Related .......: $tagPOINT, _WinAPI_GetMousePosX, _WinAPI_GetMousePosY&lt;br /&gt;
; Link ..........: &lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _WinAPI_GetMousePos($fToClient = False, $hWnd = 0)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The header is 129 characters wide, and any text within it should be wrapped to that length. For example the &amp;lt;code&amp;gt;Remarks&amp;lt;/code&amp;gt; in the above header has been extended to cover two lines. The exception to that rule is the &amp;lt;code&amp;gt;Syntax&amp;lt;/code&amp;gt; line, which should not be wrapped. Some of the parameters in the header are optional, in which case they should remain, but be left empty (for example the &amp;lt;code&amp;gt;Link&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Modified&amp;lt;/code&amp;gt; lines in the above header). In others, they are needed, but can be empty or not used such as &amp;lt;code&amp;gt;Parameters&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Return Values&amp;lt;/code&amp;gt;. In this case the value should be &#039;None&#039;, as they will still be present in the documentation.&lt;br /&gt;
&lt;br /&gt;
There are some flags that can be used within function headers: &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;+&#039;&#039;&#039; in column 20 is the continuation flag for the previous line (used in Parameters, Return Values)&lt;br /&gt;
* &#039;&#039;&#039;|&#039;&#039;&#039; in column 20 is a new line in the right side of the table when the help file is generated (used in Parameters, Return Values)&lt;br /&gt;
* &#039;&#039;&#039;-&#039;&#039;&#039; in column 20 will create new row in the table, used for things like Defaults for a style (used in Parameters, Return Values)&lt;br /&gt;
* &#039;&#039;&#039;+&#039;&#039;&#039; in column 2 of Remarks is a blank line&lt;br /&gt;
Name&lt;br /&gt;
:Specifies the name of the function. This will be identical to how it appeas in the Func statement in the code itself.&lt;br /&gt;
Description&lt;br /&gt;
:Gives a short summary of what the function does. This should only be a single line, as it is only designed to give a short impression of what is happening. For the standard set of includes distributed with AutoIt3, this value is also used in the SciTE calltips.&lt;br /&gt;
Syntax&lt;br /&gt;
:Describes the syntax of the function call. This differs slightly from what appears in the code itself for optional parameters, which are enclosed in square brackets (&amp;quot;[ ]&amp;quot;). Since subsequent parameters must also be optional, and cannot be defined unless all the previous ones have been given, these brackets are nested in the form: Function([param1[, param2[,param3]]]). Note that the opening bracket appears before the comma seperator.&lt;br /&gt;
Parameters&lt;br /&gt;
:This is a list of the arguments accepted by the function. Each is listed, followed by a dash (&amp;quot;-&amp;quot;) and a description of what it is. The dash can be padded for neatness, although the amount of padding depends on how long the parameter names are. If the parameter is optional then the meaning of the default value should be given, similarly if it&#039;s used to pass data back to the program in the form of byref then the changes made should also be detailed. For more information on parameters see Parameters.&lt;br /&gt;
Return values&lt;br /&gt;
:Details what is returned by the function. This often comes in the form of Success and Failure values, but this is not always the case. Any setting of the @error of @extended flags should be detailed, along with their meanings, in some cases it is enough to say that @error is set to non-zero in the event of an error, in most cases though a list of values for @error should be given.&lt;br /&gt;
Author&lt;br /&gt;
:This is the original writer of the function. It should contain the username, so that any queries about the code can be made through the forum, but you can give as much or little information as you feel appropriate.&lt;br /&gt;
Modified&lt;br /&gt;
:This is a list of modifications made. At it&#039;s most basic this is just a list of users who have made changes, but ideally it includes some information about what they did, in which cases it follows the same form as other multi-value lines, with the username and description of modifications seperated by a dash.&lt;br /&gt;
Remarks&lt;br /&gt;
:This is anything the user should know about a function in order to use it. For example exceptional cases and recommended ways to handle the function should all be detailed here, as well as additional info about possible reasons for failure and how to deal with them.&lt;br /&gt;
Related&lt;br /&gt;
:A comma seperated list of functions or structures related to the function.&lt;br /&gt;
Link&lt;br /&gt;
:A link to additional information about the function. For many system function wrappers, this will be &amp;lt;code&amp;gt;@@MsdnLink@@ FunctionName&amp;lt;/code&amp;gt;, which represents that the user should search MSDN for the function.&lt;br /&gt;
Example&lt;br /&gt;
:A simple yes or no value specifying whether the function has an example. If this is no then your UDF is not ready to be released. The [[#Examples]] section has more information on the format and location of examples.&lt;br /&gt;
&lt;br /&gt;
The easiest way to generate the header is to copy and paste the following blank template in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name...........: &lt;br /&gt;
; Description ...: &lt;br /&gt;
; Syntax.........: &lt;br /&gt;
; Parameters ....: &lt;br /&gt;
; Return values .: &lt;br /&gt;
; Author ........: &lt;br /&gt;
; Modified.......: &lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; Link ..........: &lt;br /&gt;
; Example .......: &lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also a number of plugins for SciTE that will generate a header and maybe fill in certain known values for you such as Name, Syntax and Parameters. The most complete one that conforms to these standards is [http://code.google.com/p/m-a-t/wiki/UDFHeaderGenerator here], but there are two others [http://www.autoitscript.com/forum/topic/28270-lua-script-for-udf-header/ here] and [http://www.autoitscript.com/forum/topic/28270-lua-script-for-udf-header/page__view__findpost__p__200823 here].&lt;br /&gt;
&lt;br /&gt;
=== Internal use only ===&lt;br /&gt;
Functions can also be marked for use only within the library and not to be documented for use by the user. These are named according to the same rules as normal functions but begin with a double underscore (&amp;quot;__&amp;quot;). The header is exactly the same except with the first line replaced, to make the blank template:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #INTERNAL_USE_ONLY# ===========================================================================================================&lt;br /&gt;
; Name...........: &lt;br /&gt;
; Description ...: &lt;br /&gt;
; Syntax.........: &lt;br /&gt;
; Parameters ....: &lt;br /&gt;
; Return values .: &lt;br /&gt;
; Author ........: &lt;br /&gt;
; Modified.......: &lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; Link ..........: &lt;br /&gt;
; Example .......: &lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Structures ==&lt;br /&gt;
Structures are defined as global constants, and follow the naming pattern &amp;lt;code&amp;gt;$tagSTRUCTNAME&amp;lt;/code&amp;gt;. The struct name should be as it appears on MSDN if it&#039;s used in the windows API, or follow a similar pattern if not. It should go without saying that they must work for both 32 and 64 bit machines, including resolving any alignment issues. Elements should also be named as they appear on MSDN if they are taken from there, which includes the hungarian notation prefix. Although many standard UDFs do not follow that rule, importantly &amp;lt;code&amp;gt;StructureConstants.au3&amp;lt;/code&amp;gt;, the rule still stands.&lt;br /&gt;
&lt;br /&gt;
=== Headers ===&lt;br /&gt;
Structures need a header similar to functions, but with some minor differences. The same rules apply in terms of wrapping and line length however. The header follow this standard template:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #STRUCTURE# ===================================================================================================================&lt;br /&gt;
; Name...........: $tagPOINT&lt;br /&gt;
; Description ...: Defines the x and y coordinates of a point&lt;br /&gt;
; Fields ........: X - Specifies the x-coordinate of the point&lt;br /&gt;
;                  Y - Specifies the y-coordinate of the point&lt;br /&gt;
; Author ........: Paul Campbell (PaulIA)&lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Global Const $tagPOINT = &amp;quot;long X;long Y&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is essentially a shortened header, with the only thing new is the Fields line, which effectively replaces the Parameters field in terms of usage. All the same rules apply as listed [[#Function Header Fields|here]].&lt;br /&gt;
&lt;br /&gt;
The blank template is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #STRUCTURE# ===================================================================================================================&lt;br /&gt;
; Name...........: &lt;br /&gt;
; Description ...: &lt;br /&gt;
; Fields ........: &lt;br /&gt;
; Author ........: &lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Structures may also be marked for internal use only. In this case the header ramains the same, but the sections first line changes. The blank template is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #INTERNAL_USE_ONLY# ===========================================================================================================&lt;br /&gt;
; Name...........: &lt;br /&gt;
; Description ...: &lt;br /&gt;
; Fields ........: &lt;br /&gt;
; Author ........: &lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variables ==&lt;br /&gt;
For code readability, there are special rules dealing with variables, particularly naming. All variables should be declared at the beginning of their scope, which usually means at the start of the function in which they are used, but could mean the top of the UDF itself in the [[#Variables|Variables section]].&lt;br /&gt;
&lt;br /&gt;
=== Naming ===&lt;br /&gt;
A variable&#039;s first letter signifies the expected type of the variable. This should be as follows:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;$a&amp;amp;lt;letter&amp;amp;gt;&amp;lt;/code&amp;gt; - Array (the following letter describes the data type taken from the rest of the data types below, if it varies then &amp;lt;code&amp;gt;v&amp;lt;/code&amp;gt; should be used. A counter as the first element is ignored, so the array returned by StringSplit (with default options) would actually be marked as $as despite the integer in the zeroeth element).&lt;br /&gt;
* &amp;lt;code&amp;gt;$d&amp;lt;/code&amp;gt; - Binary data.&lt;br /&gt;
* &amp;lt;code&amp;gt;$h&amp;lt;/code&amp;gt; - Handle, usually to a file or window. NB: AutoIt handled controls return IDs, and so use $id instead.&lt;br /&gt;
* &amp;lt;code&amp;gt;$id&amp;lt;/code&amp;gt; - An AutoIt control Id.&lt;br /&gt;
* &amp;lt;code&amp;gt;$i&amp;lt;/code&amp;gt; - Integer.&lt;br /&gt;
* &amp;lt;code&amp;gt;$b&amp;lt;/code&amp;gt; - Boolean.&lt;br /&gt;
* &amp;lt;code&amp;gt;$f&amp;lt;/code&amp;gt; - Floating point number.&lt;br /&gt;
* &amp;lt;code&amp;gt;$n&amp;lt;/code&amp;gt; - general number with no preference for floating point or integer.&lt;br /&gt;
* &amp;lt;code&amp;gt;$s&amp;lt;/code&amp;gt; - String.&lt;br /&gt;
* &amp;lt;code&amp;gt;$v&amp;lt;/code&amp;gt; - Variant (unknown/variable type of data) .&lt;br /&gt;
* &amp;lt;code&amp;gt;$p&amp;lt;/code&amp;gt; - Pointer. It is assumed that it points to a struct so no further letters are needed. The type of struct being pointed to should be inferrable from the variable name e.g. &amp;lt;code&amp;gt;$pWindowRect&amp;lt;/code&amp;gt; can be assumed to be a pointer to a &amp;lt;code&amp;gt;$tagRECT&amp;lt;/code&amp;gt; structure.&lt;br /&gt;
* &amp;lt;code&amp;gt;$t&amp;lt;/code&amp;gt; - Structure returned from DllStructCreate.&lt;br /&gt;
* &amp;lt;code&amp;gt;$tag&amp;lt;/code&amp;gt; - Struct definition string.Structure definitions should conform to the structure guidelines.&lt;br /&gt;
&lt;br /&gt;
=== Globals ===&lt;br /&gt;
The use of globals in a UDF is generally frowned upon, and byref parameters and static variables should be used where possible instead. However, in cases where this is not possible and a global must be used they should be defined using the following naming pattern: &amp;lt;code&amp;gt;$__g&amp;amp;lt;VARNAME&amp;amp;gt;_&amp;amp;lt;UDF&amp;amp;gt;&amp;lt;/code&amp;gt; where &amp;lt;code&amp;gt;&amp;amp;lt;VARNAME&amp;amp;gt;&amp;lt;/code&amp;gt; is the name as it would usually appear according to the variable naming rules above and &amp;lt;code&amp;gt;&amp;amp;lt;UDF&amp;amp;gt;&amp;lt;/code&amp;gt; is the name of the library in which it appears. This ensures there will never be a conflict with user variables of other UDF globals. They should be declared at the top of the UDF in the Variables section.&lt;br /&gt;
&lt;br /&gt;
Globals are always private. If they need to be accessed by the user then functions need to be written wrapping that operation and values should be checked. Notable exceptions are debug variables, which are designed for developer purposes and may be used by some users in extreme cases. These are named &amp;lt;code&amp;gt;$Debug_&amp;amp;lt;UDF&amp;amp;gt;&amp;lt;/code&amp;gt; although the &amp;lt;code&amp;gt;&amp;amp;lt;UDF&amp;amp;gt;&amp;lt;/code&amp;gt; part is often shortened so &amp;lt;code&amp;gt;GUIEdit.au3&amp;lt;/code&amp;gt; uses &amp;lt;code&amp;gt;$Debug_Ed&amp;lt;/code&amp;gt;. It is not required that a UDF has debugging symbols, but they are allowed to remain in releases.&lt;br /&gt;
&lt;br /&gt;
=== Constants ===&lt;br /&gt;
There are two types of constants, internal and public. Public constants are designed to be utilised by the user, and are referenced in functions that use them. They include styles and flags. Internal constants are designed for use only within the library, so that values used fairly often can be held in one place to allow for easy updating. Both kinds of constant are always typed in all upper case. Constants taken from the windows API should appear exactly as they are defined there, but internal constants follow the naming pattern: &amp;lt;code&amp;gt;$__&amp;amp;lt;UDF&amp;amp;gt;CONSTANT_&amp;amp;lt;NAME&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== The &amp;lt;code&amp;gt;Dim&amp;lt;/code&amp;gt; statement ===&lt;br /&gt;
Should not be used.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
All functions and structures that are made public to the user need to have a good quality example. This means that it should:&lt;br /&gt;
&lt;br /&gt;
* Be simple. Ideally the only functions used are basic functions like ConsoleWrite and MsgBox and the function that the example is written for. Writing a single example that covers a wide range of functions is not nearly as easy to use as writing an example per function that clearly demonstrates its use.&lt;br /&gt;
* Be readable. Everything should be explained step by step in comments.&lt;br /&gt;
* Be correct. In addition to passing the same Au3Check flags as the UDF itself (&amp;lt;code&amp;gt;-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&amp;lt;/code&amp;gt;) it should always be written with best practice being the main consideration. This takes preference over the first point, just because code is shorter and looks easier doesn&#039;t mean it&#039;s right.&lt;br /&gt;
* Examples should represent all the functionality. If there is more than one way of using a function then include more than one example of how to use it.&lt;br /&gt;
&lt;br /&gt;
Examples are stored in individual files called &amp;lt;code&amp;gt;&amp;amp;lt;FUNCTION&amp;amp;gt;.au3&amp;lt;/code&amp;gt;. The files should be kept in a folder called &amp;lt;code&amp;gt;Examples&amp;lt;/code&amp;gt;. To remain correct all examples should be wrapped in functions, such that the only code executed in the global scope is calling the function. This is usually named &amp;lt;code&amp;gt;Example&amp;lt;/code&amp;gt;, though where multiple examples exists they are named &amp;lt;code&amp;gt;Example1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Example2&amp;lt;/code&amp;gt;, ..., &amp;lt;code&amp;gt;ExampleN&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Opt(&amp;quot;MustDeclareVars&amp;quot;, 1)&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
	Local $idButton_1, $idButton_2, $iMsg, $hGUI&lt;br /&gt;
	&lt;br /&gt;
	$hGUI = GUICreate(&amp;quot;My GUI Button&amp;quot;) ; Will create a dialog box that when displayed is centered&lt;br /&gt;
&lt;br /&gt;
	$idButton_1 = GUICtrlCreateButton(&amp;quot;Run Notepad&amp;quot;, 4, 4, 80, 30)&lt;br /&gt;
	$idButton_2 = GUICtrlCreateButton(&amp;quot;Button Test&amp;quot;, 4, 38, 80, 30)&lt;br /&gt;
&lt;br /&gt;
	GUISetState() ; will display a dialog box with 2 button&lt;br /&gt;
&lt;br /&gt;
	; Run the GUI until the dialog is closed&lt;br /&gt;
	While 1&lt;br /&gt;
		$iMsg = GUIGetMsg()&lt;br /&gt;
		Select&lt;br /&gt;
			Case $iMsg = $GUI_EVENT_CLOSE&lt;br /&gt;
				ExitLoop&lt;br /&gt;
			Case $iMsg = $idButton_1&lt;br /&gt;
				Run(&amp;quot;Notepad.exe&amp;quot;) ; Will Run/Open Notepad&lt;br /&gt;
			Case $iMsg = $idButton_2&lt;br /&gt;
				MsgBox(0, &amp;quot;Testing&amp;quot;, &amp;quot;Button 2 was pressed&amp;quot;) ; Will demonstrate Button 2 being pressed&lt;br /&gt;
		EndSelect&lt;br /&gt;
	WEnd&lt;br /&gt;
	GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Template UDF ==&lt;br /&gt;
Here is an example of a UDF called &amp;lt;code&amp;gt;MyUDF.au3&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include-once&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;MyUDFConstants.au3&amp;quot;&lt;br /&gt;
#include &amp;quot;AnInclude.au3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; #INDEX# =======================================================================================================================&lt;br /&gt;
; Title .........: MyUDF&lt;br /&gt;
; AutoIt Version : 3.3.6.1&lt;br /&gt;
; Language ......: English&lt;br /&gt;
; Description ...: An example UDF that does very little.&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
&lt;br /&gt;
; #CURRENT# =====================================================================================================================&lt;br /&gt;
;$tagMYSTRUCT&lt;br /&gt;
;_MyUDF_Function&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
&lt;br /&gt;
; #STRUCTURE# ===================================================================================================================&lt;br /&gt;
; Name...........: $tagMYSTRUCT&lt;br /&gt;
; Description ...: An example of a structure.&lt;br /&gt;
; Fields ........: hFoo       - A handle to foo that does something.&lt;br /&gt;
;                  iBar       - An integer that does something.&lt;br /&gt;
; Author ........: Matt Diesel (Mat)&lt;br /&gt;
; Remarks .......:&lt;br /&gt;
; Related .......: _MyUDF_Function&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Global Const $tagMYSTRUCT = &amp;quot;ptr hFoo; int iBar&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name...........: _MyUDF_Function&lt;br /&gt;
; Description ...: A function that does something.&lt;br /&gt;
; Syntax.........: _MyUDF_Function(ByRef $avAnArray, $iAnInt[, $hAHandle = 0[, $nSomeNumber = 42]])&lt;br /&gt;
; Parameters ....: $avAnArray       - [byref] An array of anything. The value of anything is changed and passed out using this&lt;br /&gt;
;                                     parameter. The array should only have one dimension&lt;br /&gt;
;                  $iAnInt          - An integer that does very little.&lt;br /&gt;
;                  $hAHandle        - [optional] A handle. Default is zero.&lt;br /&gt;
;                  $nSomeNumber     - [optional] A number of some kind. Default is 42.&lt;br /&gt;
; Return values .: Success          - A MYSTRUCT structure.&lt;br /&gt;
;                  Failure          - Returns zero and sets the @error flag:&lt;br /&gt;
;                                   |1 - The $avAnArray is invalid.&lt;br /&gt;
; Author ........: Matt Diesel (Mat)&lt;br /&gt;
; Modified.......:&lt;br /&gt;
; Remarks .......:&lt;br /&gt;
; Related .......: $tagMYSTRUCT&lt;br /&gt;
; Link ..........:&lt;br /&gt;
; Example .......: No&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _MyUDF_Function(ByRef $avAnArray, $iAnInt, $hAHandle = 0, $nSomeNumber = 42)&lt;br /&gt;
	; 1 - Error Checking for parameters.&lt;br /&gt;
	If Not IsArray($avAnArray) Or UBound($avAnArray, 0) &amp;lt;&amp;gt; 1 Then Return SetError(1, 0, 0) ; The $avAnArray is invalid.&lt;br /&gt;
&lt;br /&gt;
	; 2 - Declaration of locals.&lt;br /&gt;
	Local $tMS = DllStructCreate($tagMYSTRUCT)&lt;br /&gt;
&lt;br /&gt;
	; 3 - Function code&lt;br /&gt;
	DllStructSetData($tMS, &amp;quot;hFoo&amp;quot;, $hAHandle)&lt;br /&gt;
	DllStructSetData($tMS, &amp;quot;iBar&amp;quot;, $iAnInt * $nSomeNumber)&lt;br /&gt;
&lt;br /&gt;
	Return $tMS&lt;br /&gt;
EndFunc   ;==&amp;gt;_MyUDF_Function&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=UDF-spec&amp;diff=11497</id>
		<title>UDF-spec</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=UDF-spec&amp;diff=11497"/>
		<updated>2012-12-26T21:02:19Z</updated>

		<summary type="html">&lt;p&gt;BrewManNH: /* Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:UDF]]&lt;br /&gt;
{{WIP}}This page is still under construction.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A library is a collection of one or more User Defined Functions (UDFs). However, the term UDF is often used to describe the collection as a whole. If a UDF is to be considered for inclusion in the standard set distributed with AutoIt then it must meet all the criteria detailed here, but it&#039;s also good practice to always write in conformance with at least the majority of this document, as that is what will be expected by people reading your code later.&lt;br /&gt;
&lt;br /&gt;
== Basic Requirements ==&lt;br /&gt;
Firstly, the code itself should meet the following basic requirements:&lt;br /&gt;
&lt;br /&gt;
* Be tidied. Just hit &amp;lt;code&amp;gt;Ctrl+T&amp;lt;/code&amp;gt; from SciTE or run Tidy manually. The only flag needed is &amp;lt;code&amp;gt;/sf&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Pass Au3Check with no errors using the strictest settings: &amp;lt;code&amp;gt;-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&amp;lt;/code&amp;gt;&lt;br /&gt;
* Support everything AutoIt supports. In some cases features may not be able to support everything, in which case this should be checked for and return errors appropriately. This applies to: windows OS versions (AutoIt has support for all OS&#039; from windows 2000), unicode and ansi strings, 64 and 32 bit machines.&lt;br /&gt;
* Ideally it will be able to run cleanly when obfuscated. Although there will be some cases where this is not possible, please consider it when writing UDFs, and avoid the use of Execute and similar statements. If it does not, then document it as such.&lt;br /&gt;
&lt;br /&gt;
== UDF Outline ==&lt;br /&gt;
The library itself has a header that details important information such as the minimum OS and AutoIt versions, and what system dlls are required. There is also a number of other sections that are required that list what is present in the UDF.&lt;br /&gt;
&lt;br /&gt;
=== Includes ===&lt;br /&gt;
Since a UDF is designed to define functions, it should only be included once. As a result, the &amp;lt;code&amp;gt;#include-once&amp;lt;/code&amp;gt; directive should be used. This is typically the first line of the UDF, followed by the includes used by the UDF. Include statements should use the double quoted form, as the library is expected to work in the same directory as libraries it depends on. Non standard libraries can be used if necessary, but this should be documented and linked to so users can download it as well. It goes without saying that a UDF based on non-standard UDFs cannot itself become a standard.&lt;br /&gt;
&lt;br /&gt;
=== Index ===&lt;br /&gt;
The index follows the following template (taken from &amp;lt;code&amp;gt;WinAPI.au3&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #INDEX# =======================================================================================================================&lt;br /&gt;
; Title .........: Windows API&lt;br /&gt;
; AutoIt Version : 3.2&lt;br /&gt;
; Description ...: Windows API calls that have been translated to AutoIt functions.&lt;br /&gt;
; Author(s) .....: Paul Campbell (PaulIA), gafrost, Siao, Zedna, arcker, Prog@ndy, PsaltyDS, Raik, jpm&lt;br /&gt;
; Dll ...........: kernel32.dll, user32.dll, gdi32.dll, comdlg32.dll, shell32.dll, ole32.dll, winspool.drv&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only required element in the index header is &amp;lt;code&amp;gt;Title&amp;lt;/code&amp;gt;. All others are ignored by the processor, but should be included for reference&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Dll&amp;lt;/code&amp;gt; field can remain empty in many cases where no dlls are called directly. This header must be defined.&lt;br /&gt;
&lt;br /&gt;
=== Other Sections ===&lt;br /&gt;
Other sections, in order of appearance, are as follows.&lt;br /&gt;
&lt;br /&gt;
==== Variables ====&lt;br /&gt;
All global variables needed to be declared in the UDF are defined in this section. They should follow the variable rules for globals. Individual variables do not need to be documented, as it is assumed they are for internal use only. Any globals designed to be accessible for the user should instead be wrapped by a function (or multiple functions if globals must be retrieved and set). The template for this section is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #VARIABLES# ===================================================================================================================&lt;br /&gt;
Global $__gvMyGlobal = 0&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If no globals are needed then this section may be ommitted. Please consider the use of global variables carefully, and read through the section on global variables.&lt;br /&gt;
&lt;br /&gt;
==== Constants ====&lt;br /&gt;
Any global constant values are defined in this section. This should be constants only designated for use within the library itself. Constants that may be needed by the user should be defined in a seperate file, named &amp;lt;code&amp;gt;UDFConstants.au3&amp;lt;/code&amp;gt; where &amp;lt;code&amp;gt;UDF&amp;lt;/code&amp;gt; is the name of the parent file. For example &amp;lt;code&amp;gt;File.au3&amp;lt;/code&amp;gt; uses constants defined in &amp;lt;code&amp;gt;FileConstants.au3&amp;lt;/code&amp;gt;. The exception to that rule is control UDFs which miss out the prepended &#039;GUI&#039; when naming constant files, so &amp;lt;code&amp;gt;GUIButton.au3&amp;lt;/code&amp;gt; uses constants from &amp;lt;code&amp;gt;ButtonConstants.au3&amp;lt;/code&amp;gt;. The template for this section is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #CONSTANTS# ===================================================================================================================&lt;br /&gt;
Global Const $__MYUDFCONSTANT_FOOBAR = 42&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If no constants are needed in this section, either because non are used or because they are stored in a seperate file, then it may be ommitted. Please read the section on global constants for specific info on naming and definition of constants.&lt;br /&gt;
&lt;br /&gt;
==== Listing ====&lt;br /&gt;
This defines all functions and structures currently used functions in the library. It MUST be the second defined header item after [[#Index]]. It is a simple list with each function on a line where the functions and structures appear in the same order as they do in the code, which is alphabetical order and structures first. A simple way to generate this list is to create a small script that searches for function definitions and outputs them in the correct format, an example of which is [http://www.autoitscript.com/forum/topic/120820-function-name-lister/ here]. In addition there is a second section that lists functions and structures for internal use only, this does not need to appear if none are defined.&lt;br /&gt;
&lt;br /&gt;
The template for these sections are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #CURRENT# =====================================================================================================================&lt;br /&gt;
;$tagSTRUCT&lt;br /&gt;
;_MyUDF_Function&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
&lt;br /&gt;
; #INTERNAL_USE_ONLY# ===========================================================================================================&lt;br /&gt;
;$tagINTERNALSTRUCT&lt;br /&gt;
;__MyUDF_InternalFunction&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This section still needs to be defined for files that only define constants. It should also be noted that there MUST NOT be a space between the &amp;lt;code&amp;gt;;&amp;lt;/code&amp;gt; and the function/structure name.&lt;br /&gt;
&lt;br /&gt;
==== Undocumented Listing ====&lt;br /&gt;
There is a final kind of listing that lists functions for which no documentation exists, or they have been deprecated and are only included for backwards compatibility. These are listed in a section with the header &amp;lt;code&amp;gt;NO_DOC_FUNCTION&amp;lt;/code&amp;gt;. This is very rarely used, and is reserved only for functions that can be utilised by the user, or that would have been in the past, as opposed to those for internal use only.&lt;br /&gt;
&lt;br /&gt;
Template:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #NO_DOC_FUNCTION# =============================================================================================================&lt;br /&gt;
;_MyUDF_Function&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Renamed Functions ====&lt;br /&gt;
Although it should not be the case in new UDFs, many of the older ones (particularly to do with controls) have had script breaking name changes to functions. These are documented in the UDF to ensure updating old scripts is as easy as possible. The basic format for this is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #NO_DOC_FUNCTION# =============================================================================================================&lt;br /&gt;
;_MyUDF_OldFunction                        ; --&amp;gt; _MyUDF_NewFunction&lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The space padding is optional. This section is ignored as far as the docs are concerned, and is usually omitted.&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
=== Naming ===&lt;br /&gt;
Function names must start with an underscore, and the first word is the library name. There is then usually another underscore before the rest of the function name. The library name should be consistent across all the functions in the library, and can be shortened if a logical abbreviation is available (e.g. &amp;lt;code&amp;gt;Window&amp;lt;/code&amp;gt; ==&amp;gt; &amp;lt;code&amp;gt;Win&amp;lt;/code&amp;gt;). Each word should be capitalized, but no underscores are placed in the rest of the name, for example &amp;lt;code&amp;gt;_WinAPI_GetWindowLong&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For control libraries, the first part of the function name is changed slightly. For example the UDF for listviews would use &amp;lt;code&amp;gt;_GUICtrlListview_*&amp;lt;/code&amp;gt;. When a function wraps a dll call, then the second part should closely resemble the function name as it appears in other languages. This also applies to functions acting as a wrapper to &amp;lt;code&amp;gt;SendMessage&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Functions are defined in alphabetical order by name, which is the same as using &amp;lt;code&amp;gt;Tidy&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;/sf&amp;lt;/code&amp;gt; flag set.&lt;br /&gt;
&lt;br /&gt;
=== Parameters ===&lt;br /&gt;
Parameters should follow the variable naming scheme ([[#Naming_2|here]]). All parameters must be checked to ensure they are valid, and return unique and documented error codes if they are not. For functions involving a specific type of control, this includes checking the class name using &amp;lt;code&amp;gt;_WinAPI_IsClassName&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Parameters that are optional or byref should be documented as such, and the effect these have explicitly stated. For example a byref parameter should detail exactly what the expected output is as well as the input.&lt;br /&gt;
&lt;br /&gt;
=== Headers ===&lt;br /&gt;
All functions have a documentation header that describes the function. This uses the following template:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name...........: _WinAPI_GetMousePos&lt;br /&gt;
; Description ...: Returns the current mouse position&lt;br /&gt;
; Syntax.........: _WinAPI_GetMousePos([$fToClient = False[, $hWnd = 0]])&lt;br /&gt;
; Parameters ....: $fToClient   - If True, the coordinates will be converted to client coordinates&lt;br /&gt;
;                  $hWnd        - Window handle used to convert coordinates if $fToClient is True&lt;br /&gt;
; Return values .: Success      - $tagPOINT structure with current mouse position&lt;br /&gt;
;                  Failure      - Zero&lt;br /&gt;
; Author ........: Paul Campbell (PaulIA)&lt;br /&gt;
; Modified.......:&lt;br /&gt;
; Remarks .......: This function takes into account the current MouseCoordMode setting when  obtaining  the  mouse  position.  It&lt;br /&gt;
;                  will also convert screen to client coordinates based on the parameters passed.&lt;br /&gt;
; Related .......: $tagPOINT, _WinAPI_GetMousePosX, _WinAPI_GetMousePosY&lt;br /&gt;
; Link ..........: &lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _WinAPI_GetMousePos($fToClient = False, $hWnd = 0)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The header is 129 characters wide, and any text within it should be wrapped to that length. For example the &amp;lt;code&amp;gt;Remarks&amp;lt;/code&amp;gt; in the above header has been extended to cover two lines. The exception to that rule is the &amp;lt;code&amp;gt;Syntax&amp;lt;/code&amp;gt; line, which should not be wrapped. Some of the parameters in the header are optional, in which case they should remain, but be left empty (for example the &amp;lt;code&amp;gt;Link&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Modified&amp;lt;/code&amp;gt; lines in the above header). In others, they are needed, but can be empty or not used such as &amp;lt;code&amp;gt;Parameters&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Return Values&amp;lt;/code&amp;gt;. In this case the value should be &#039;None&#039;, as they will still be present in the documentation.&lt;br /&gt;
&lt;br /&gt;
There are some flags that can be used within function headers: &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;+&#039;&#039;&#039; in column 20 is the continuation flag for the previous line (used in Parameters, Return Values)&lt;br /&gt;
* &#039;&#039;&#039;|&#039;&#039;&#039; in column 20 is a new line in the right side of the table when the help file is generated (used in Parameters, Return Values)&lt;br /&gt;
* &#039;&#039;&#039;-&#039;&#039;&#039; in column 20 will create new row in the table, used for things like Defaults for a style (used in Parameters, Return Values)&lt;br /&gt;
* &#039;&#039;&#039;+&#039;&#039;&#039; in column 2 of Remarks is a blank line&lt;br /&gt;
Name&lt;br /&gt;
:Specifies the name of the function. This will be identical to how it appeas in the Func statement in the code itself.&lt;br /&gt;
Description&lt;br /&gt;
:Gives a short summary of what the function does. This should only be a single line, as it is only designed to give a short impression of what is happening. For the standard set of includes distributed with AutoIt3, this value is also used in the SciTE calltips.&lt;br /&gt;
Syntax&lt;br /&gt;
:Describes the syntax of the function call. This differs slightly from what appears in the code itself for optional parameters, which are enclosed in square brackets (&amp;quot;[ ]&amp;quot;). Since subsequent parameters must also be optional, and cannot be defined unless all the previous ones have been given, these brackets are nested in the form: Function([param1[, param2[,param3]]]). Note that the opening bracket appears before the comma seperator.&lt;br /&gt;
Parameters&lt;br /&gt;
:This is a list of the arguments accepted by the function. Each is listed, followed by a dash (&amp;quot;-&amp;quot;) and a description of what it is. The dash can be padded for neatness, although the amount of padding depends on how long the parameter names are. If the parameter is optional then the meaning of the default value should be given, similarly if it&#039;s used to pass data back to the program in the form of byref then the changes made should also be detailed. For more information on parameters see Parameters.&lt;br /&gt;
Return values&lt;br /&gt;
:Details what is returned by the function. This often comes in the form of Success and Failure values, but this is not always the case. Any setting of the @error of @extended flags should be detailed, along with their meanings, in some cases it is enough to say that @error is set to non-zero in the event of an error, in most cases though a list of values for @error should be given.&lt;br /&gt;
Author&lt;br /&gt;
:This is the original writer of the function. It should contain the username, so that any queries about the code can be made through the forum, but you can give as much or little information as you feel appropriate.&lt;br /&gt;
Modified&lt;br /&gt;
:This is a list of modifications made. At it&#039;s most basic this is just a list of users who have made changes, but ideally it includes some information about what they did, in which cases it follows the same form as other multi-value lines, with the username and description of modifications seperated by a dash.&lt;br /&gt;
Remarks&lt;br /&gt;
:This is anything the user should know about a function in order to use it. For example exceptional cases and recommended ways to handle the function should all be detailed here, as well as additional info about possible reasons for failure and how to deal with them.&lt;br /&gt;
Related&lt;br /&gt;
:A comma seperated list of functions or structures related to the function.&lt;br /&gt;
Link&lt;br /&gt;
:A link to additional information about the function. For many system function wrappers, this will be &amp;lt;code&amp;gt;@@MsdnLink@@ FunctionName&amp;lt;/code&amp;gt;, which represents that the user should search MSDN for the function.&lt;br /&gt;
Example&lt;br /&gt;
:A simple yes or no value specifying whether the function has an example. If this is no then your UDF is not ready to be released. The [[#Examples]] section has more information on the format and location of examples.&lt;br /&gt;
&lt;br /&gt;
The easiest way to generate the header is to copy and paste the following blank template in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name...........: &lt;br /&gt;
; Description ...: &lt;br /&gt;
; Syntax.........: &lt;br /&gt;
; Parameters ....: &lt;br /&gt;
; Return values .: &lt;br /&gt;
; Author ........: &lt;br /&gt;
; Modified.......: &lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; Link ..........: &lt;br /&gt;
; Example .......: &lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also a number of plugins for SciTE that will generate a header and maybe fill in certain known values for you such as Name, Syntax and Parameters. The most complete one that conforms to these standards is [http://code.google.com/p/m-a-t/wiki/UDFHeaderGenerator here], but there are two others [http://www.autoitscript.com/forum/topic/28270-lua-script-for-udf-header/ here] and [http://www.autoitscript.com/forum/topic/28270-lua-script-for-udf-header/page__view__findpost__p__200823 here].&lt;br /&gt;
&lt;br /&gt;
=== Internal use only ===&lt;br /&gt;
Functions can also be marked for use only within the library and not to be documented for use by the user. These are named according to the same rules as normal functions but begin with a double underscore (&amp;quot;__&amp;quot;). The header is exactly the same except with the first line replaced, to make the blank template:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #INTERNAL_USE_ONLY# ===========================================================================================================&lt;br /&gt;
; Name...........: &lt;br /&gt;
; Description ...: &lt;br /&gt;
; Syntax.........: &lt;br /&gt;
; Parameters ....: &lt;br /&gt;
; Return values .: &lt;br /&gt;
; Author ........: &lt;br /&gt;
; Modified.......: &lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; Link ..........: &lt;br /&gt;
; Example .......: &lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Structures ==&lt;br /&gt;
Structures are defined as global constants, and follow the naming pattern &amp;lt;code&amp;gt;$tagSTRUCTNAME&amp;lt;/code&amp;gt;. The struct name should be as it appears on MSDN if it&#039;s used in the windows API, or follow a similar pattern if not. It should go without saying that they must work for both 32 and 64 bit machines, including resolving any alignment issues. Elements should also be named as they appear on MSDN if they are taken from there, which includes the hungarian notation prefix. Although many standard UDFs do not follow that rule, importantly &amp;lt;code&amp;gt;StructureConstants.au3&amp;lt;/code&amp;gt;, the rule still stands.&lt;br /&gt;
&lt;br /&gt;
=== Headers ===&lt;br /&gt;
Structures need a header similar to functions, but with some minor differences. The same rules apply in terms of wrapping and line length however. The header follow this standard template:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #STRUCTURE# ===================================================================================================================&lt;br /&gt;
; Name...........: $tagPOINT&lt;br /&gt;
; Description ...: Defines the x and y coordinates of a point&lt;br /&gt;
; Fields ........: X - Specifies the x-coordinate of the point&lt;br /&gt;
;                  Y - Specifies the y-coordinate of the point&lt;br /&gt;
; Author ........: Paul Campbell (PaulIA)&lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Global Const $tagPOINT = &amp;quot;long X;long Y&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is essentially a shortened header, with the only thing new is the Fields line, which effectively replaces the Parameters field in terms of usage. All the same rules apply as listed [[#Function Header Fields|here]].&lt;br /&gt;
&lt;br /&gt;
The blank template is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #STRUCTURE# ===================================================================================================================&lt;br /&gt;
; Name...........: &lt;br /&gt;
; Description ...: &lt;br /&gt;
; Fields ........: &lt;br /&gt;
; Author ........: &lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Structures may also be marked for internal use only. In this case the header ramains the same, but the sections first line changes. The blank template is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;; #INTERNAL_USE_ONLY# ===========================================================================================================&lt;br /&gt;
; Name...........: &lt;br /&gt;
; Description ...: &lt;br /&gt;
; Fields ........: &lt;br /&gt;
; Author ........: &lt;br /&gt;
; Remarks .......: &lt;br /&gt;
; Related .......: &lt;br /&gt;
; ===============================================================================================================================&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variables ==&lt;br /&gt;
For code readability, there are special rules dealing with variables, particularly naming. All variables should be declared at the beginning of their scope, which usually means at the start of the function in which they are used, but could mean the top of the UDF itself in the [[#Variables|Variables section]].&lt;br /&gt;
&lt;br /&gt;
=== Naming ===&lt;br /&gt;
A variables first letter signifies the expected type of the variable. This should be as follows:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;$a&amp;amp;lt;letter&amp;amp;gt;&amp;lt;/code&amp;gt; - Array (the following letter describes the data type taken from the rest of the data types below, if it varies then &amp;lt;code&amp;gt;v&amp;lt;/code&amp;gt; should be used. A counter as the first element is ignored, so the array returned by StringSplit (with default options) would actually be marked as $as despite the integer in the zeroeth element).&lt;br /&gt;
* &amp;lt;code&amp;gt;$d&amp;lt;/code&amp;gt; - Binary data.&lt;br /&gt;
* &amp;lt;code&amp;gt;$h&amp;lt;/code&amp;gt; - Handle, usually to a file or window. NB: AutoIt handled controls return IDs, and so use $id instead.&lt;br /&gt;
* &amp;lt;code&amp;gt;$id&amp;lt;/code&amp;gt; - An AutoIt control Id.&lt;br /&gt;
* &amp;lt;code&amp;gt;$i&amp;lt;/code&amp;gt; - Integer.&lt;br /&gt;
* &amp;lt;code&amp;gt;$b&amp;lt;/code&amp;gt; - Boolean.&lt;br /&gt;
* &amp;lt;code&amp;gt;$f&amp;lt;/code&amp;gt; - Floating point number.&lt;br /&gt;
* &amp;lt;code&amp;gt;$n&amp;lt;/code&amp;gt; - general number with no preference for floating point or integral.&lt;br /&gt;
* &amp;lt;code&amp;gt;$s&amp;lt;/code&amp;gt; - String.&lt;br /&gt;
* &amp;lt;code&amp;gt;$v&amp;lt;/code&amp;gt; - Variant (unknown/variable type of data) .&lt;br /&gt;
* &amp;lt;code&amp;gt;$p&amp;lt;/code&amp;gt; - Pointer. It is assumed that it points to a struct so no further letters are needed. The type of struct being pointed to should be inferrable from the variable name e.g. &amp;lt;code&amp;gt;$pWindowRect&amp;lt;/code&amp;gt; can be assumed to be a pointer to a &amp;lt;code&amp;gt;$tagRECT&amp;lt;/code&amp;gt; structure.&lt;br /&gt;
* &amp;lt;code&amp;gt;$t&amp;lt;/code&amp;gt; - Structure returned from DllStructCreate.&lt;br /&gt;
* &amp;lt;code&amp;gt;$tag&amp;lt;/code&amp;gt; - Struct definition string.Structure definitions should conform to the structure guidelines.&lt;br /&gt;
&lt;br /&gt;
=== Globals ===&lt;br /&gt;
The use of globals in a UDF is generally frowned upon, and byref parameters and static variables should be used where possible instead. However, in cases where this is not possible and a global must be used they should be defined using the following naming pattern: &amp;lt;code&amp;gt;$__g&amp;amp;lt;VARNAME&amp;amp;gt;_&amp;amp;lt;UDF&amp;amp;gt;&amp;lt;/code&amp;gt; where &amp;lt;code&amp;gt;&amp;amp;lt;VARNAME&amp;amp;gt;&amp;lt;/code&amp;gt; is the name as it would usually appear according to the variable naming rules above and &amp;lt;code&amp;gt;&amp;amp;lt;UDF&amp;amp;gt;&amp;lt;/code&amp;gt; is the name of the library in which it appears. This ensures there will never be a conflict with user variables of other UDF globals. They should be declared at the top of the UDF in the Variables section.&lt;br /&gt;
&lt;br /&gt;
Globals are always private. If they need to be accessed by the user then functions need to be written wrapping that operation and values should be checked. Notable exceptions are debug variables, which are designed for developer purposes and may be used by some users in extreme cases. These are named &amp;lt;code&amp;gt;$Debug_&amp;amp;lt;UDF&amp;amp;gt;&amp;lt;/code&amp;gt; although the &amp;lt;code&amp;gt;&amp;amp;lt;UDF&amp;amp;gt;&amp;lt;/code&amp;gt; part is often shortened so &amp;lt;code&amp;gt;GUIEdit.au3&amp;lt;/code&amp;gt; uses &amp;lt;code&amp;gt;$Debug_Ed&amp;lt;/code&amp;gt;. It is not required that a UDF has debugging symbols, but they are allowed to remain in releases.&lt;br /&gt;
&lt;br /&gt;
=== Constants ===&lt;br /&gt;
There are two types of constants, internal and public. Public constants are designed to be utilised by the user, and are referenced in functions that use them. They include styles and flags. Internal constants are designed for use only within the library, so that values used fairly often can be held in one place to allow for easy updating. Both kinds of constant are always typed in all upper case. Constants taken from the windows API should appear exactly as they are defined there, but internal constants follow the naming pattern: &amp;lt;code&amp;gt;$__&amp;amp;lt;UDF&amp;amp;gt;CONSTANT_&amp;amp;lt;NAME&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== The &amp;lt;code&amp;gt;Dim&amp;lt;/code&amp;gt; statement ===&lt;br /&gt;
Should not be used.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
All functions and structures that are made public to the user need to have a good quality example. This means that it should:&lt;br /&gt;
&lt;br /&gt;
* Be simple. Ideally the only functions used are basic functions like ConsoleWrite and MsgBox and the function that the example is written for. Writing a single example that covers a wide range of functions is not nearly as easy to use as writing an example per function that clearly demonstrates its use.&lt;br /&gt;
* Be readable. Everything should be explained step by step in comments.&lt;br /&gt;
* Be correct. In addition to passing the same Au3Check flags as the UDF itself (&amp;lt;code&amp;gt;-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&amp;lt;/code&amp;gt;) it should always be written with best practice being the main consideration. This takes preference over the first point, just because code is shorter and looks easier doesn&#039;t mean it&#039;s right.&lt;br /&gt;
* Examples should represent all the functionality. If there is more than one way of using a function then include more than one example of how to use it.&lt;br /&gt;
&lt;br /&gt;
Examples are stored in individual files called &amp;lt;code&amp;gt;&amp;amp;lt;FUNCTION&amp;amp;gt;.au3&amp;lt;/code&amp;gt;. The files should be kept in a folder called &amp;lt;code&amp;gt;Examples&amp;lt;/code&amp;gt;. To remain correct all examples should be wrapped in functions, such that the only code executed in the global scope is calling the function. This is usually named &amp;lt;code&amp;gt;Example&amp;lt;/code&amp;gt;, though where multiple examples exists they are named &amp;lt;code&amp;gt;Example1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Example2&amp;lt;/code&amp;gt;, ..., &amp;lt;code&amp;gt;ExampleN&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Opt(&amp;quot;MustDeclareVars&amp;quot;, 1)&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
	Local $idButton_1, $idButton_2, $iMsg, $hGUI&lt;br /&gt;
	&lt;br /&gt;
	$hGUI = GUICreate(&amp;quot;My GUI Button&amp;quot;) ; Will create a dialog box that when displayed is centered&lt;br /&gt;
&lt;br /&gt;
	$idButton_1 = GUICtrlCreateButton(&amp;quot;Run Notepad&amp;quot;, 4, 4, 80, 30)&lt;br /&gt;
	$idButton_2 = GUICtrlCreateButton(&amp;quot;Button Test&amp;quot;, 4, 38, 80, 30)&lt;br /&gt;
&lt;br /&gt;
	GUISetState() ; will display a dialog box with 2 button&lt;br /&gt;
&lt;br /&gt;
	; Run the GUI until the dialog is closed&lt;br /&gt;
	While 1&lt;br /&gt;
		$iMsg = GUIGetMsg()&lt;br /&gt;
		Select&lt;br /&gt;
			Case $iMsg = $GUI_EVENT_CLOSE&lt;br /&gt;
				ExitLoop&lt;br /&gt;
			Case $iMsg = $idButton_1&lt;br /&gt;
				Run(&amp;quot;Notepad.exe&amp;quot;) ; Will Run/Open Notepad&lt;br /&gt;
			Case $iMsg = $idButton_2&lt;br /&gt;
				MsgBox(0, &amp;quot;Testing&amp;quot;, &amp;quot;Button 2 was pressed&amp;quot;) ; Will demonstrate Button 2 being pressed&lt;br /&gt;
		EndSelect&lt;br /&gt;
	WEnd&lt;br /&gt;
	GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Template UDF ==&lt;br /&gt;
Here is an example of a UDF called &amp;lt;code&amp;gt;MyUDF.au3&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include-once&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;MyUDFConstants.au3&amp;quot;&lt;br /&gt;
#include &amp;quot;AnInclude.au3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; #INDEX# =======================================================================================================================&lt;br /&gt;
; Title .........: MyUDF&lt;br /&gt;
; AutoIt Version : 3.3.6.1&lt;br /&gt;
; Language ......: English&lt;br /&gt;
; Description ...: An example UDF that does very little.&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
&lt;br /&gt;
; #CURRENT# =====================================================================================================================&lt;br /&gt;
;$tagMYSTRUCT&lt;br /&gt;
;_MyUDF_Function&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
&lt;br /&gt;
; #STRUCTURE# ===================================================================================================================&lt;br /&gt;
; Name...........: $tagMYSTRUCT&lt;br /&gt;
; Description ...: An example of a structure.&lt;br /&gt;
; Fields ........: hFoo       - A handle to foo that does something.&lt;br /&gt;
;                  iBar       - An integer that does something.&lt;br /&gt;
; Author ........: Matt Diesel (Mat)&lt;br /&gt;
; Remarks .......:&lt;br /&gt;
; Related .......: _MyUDF_Function&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Global Const $tagMYSTRUCT = &amp;quot;ptr hFoo; int iBar&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name...........: _MyUDF_Function&lt;br /&gt;
; Description ...: A function that does something.&lt;br /&gt;
; Syntax.........: _MyUDF_Function(ByRef $avAnArray, $iAnInt[, $hAHandle = 0[, $nSomeNumber = 42]])&lt;br /&gt;
; Parameters ....: $avAnArray       - [byref] An array of anything. The value of anything is changed and passed out using this&lt;br /&gt;
;                                     parameter. The array should only have one dimension&lt;br /&gt;
;                  $iAnInt          - An integer that does very little.&lt;br /&gt;
;                  $hAHandle        - [optional] A handle. Default is zero.&lt;br /&gt;
;                  $nSomeNumber     - [optional] A number of some kind. Default is 42.&lt;br /&gt;
; Return values .: Success          - A MYSTRUCT structure.&lt;br /&gt;
;                  Failure          - Returns zero and sets the @error flag:&lt;br /&gt;
;                                   |1 - The $avAnArray is invalid.&lt;br /&gt;
; Author ........: Matt Diesel (Mat)&lt;br /&gt;
; Modified.......:&lt;br /&gt;
; Remarks .......:&lt;br /&gt;
; Related .......: $tagMYSTRUCT&lt;br /&gt;
; Link ..........:&lt;br /&gt;
; Example .......: No&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _MyUDF_Function(ByRef $avAnArray, $iAnInt, $hAHandle = 0, $nSomeNumber = 42)&lt;br /&gt;
	; 1 - Error Checking for parameters.&lt;br /&gt;
	If Not IsArray($avAnArray) Or UBound($avAnArray, 0) &amp;lt;&amp;gt; 1 Then Return SetError(1, 0, 0) ; The $avAnArray is invalid.&lt;br /&gt;
&lt;br /&gt;
	; 2 - Declaration of locals.&lt;br /&gt;
	Local $tMS = DllStructCreate($tagMYSTRUCT)&lt;br /&gt;
&lt;br /&gt;
	; 3 - Function code&lt;br /&gt;
	DllStructSetData($tMS, &amp;quot;hFoo&amp;quot;, $hAHandle)&lt;br /&gt;
	DllStructSetData($tMS, &amp;quot;iBar&amp;quot;, $iAnInt * $nSomeNumber)&lt;br /&gt;
&lt;br /&gt;
	Return $tMS&lt;br /&gt;
EndFunc   ;==&amp;gt;_MyUDF_Function&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>BrewManNH</name></author>
	</entry>
</feed>