<?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=Guinness</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=Guinness"/>
	<link rel="alternate" type="text/html" href="https://www.autoitscript.com/wiki/Special:Contributions/Guinness"/>
	<updated>2026-05-14T14:34:46Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13300</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=13300"/>
		<updated>2016-02-06T12:04:43Z</updated>

		<summary type="html">&lt;p&gt;Guinness: &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;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;Hello world&amp;quot;&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;
| id || An AutoIt controlID || $idButton_Ok = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&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;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&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;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $oShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $vData = ClipGet()&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13299</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=13299"/>
		<updated>2016-02-06T12:02:01Z</updated>

		<summary type="html">&lt;p&gt;Guinness: Tidied comments&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;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;hello world&amp;quot;&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;
| id || An AutoIt controlID || $idButton_Ok = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&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;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Dow;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $oShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $vData = ClipGet()&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452&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 $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;
; Empty the array (and keep its size)&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13298</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=13298"/>
		<updated>2016-02-06T11:59:49Z</updated>

		<summary type="html">&lt;p&gt;Guinness: Typos&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;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;hello world&amp;quot;&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;
| id || An AutoIt controlID || $idButton_Ok = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&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;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Dow;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $oShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $vData = ClipGet()&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13225</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=13225"/>
		<updated>2015-09-04T06:11:04Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* 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;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;hello world&amp;quot;&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;
| id || An AutoIt controlId || $idButton = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&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;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Dow;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $oShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $vData = ClipGet()&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452&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 $idGo = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop), $idQuit = 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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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 efficent 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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=UDF-spec&amp;diff=13224</id>
		<title>UDF-spec</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=UDF-spec&amp;diff=13224"/>
		<updated>2015-09-04T06:09:00Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Globals */&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;
* Not use any magic numbers. Ever. None. At all. No excuses.&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 $__g_vMyGlobal = 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 scope and type of the variable. See [[Best_coding_practices#Names_of_Variables|Names of Variables]]&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;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. 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;
* Not make any permanent changes to the users computer. For example, if demonstrating a File function, be sure to delete the file after it has been used. The same applies for any function that makes a change to the environment: the changes MUST be undone.&lt;br /&gt;
&lt;br /&gt;
Always remember, the readability of code in an example is MORE important than the readability of code inside the UDF itself.&lt;br /&gt;
&lt;br /&gt;
Examples are stored in script 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;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include &amp;lt;Constants.au3&amp;gt;&lt;br /&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($MB_SYSTEMMODAL, &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;
=== Multiple Examples ===&lt;br /&gt;
The helpfile now supports multiple examples per function. In order to maintain backwards compatibility with any other tools that use examples, the first file is still named &amp;lt;code&amp;gt;&amp;amp;lt;FUNCTION&amp;amp;gt;.au3&amp;lt;/code&amp;gt;, but any additional examples are named &amp;lt;code&amp;gt;&amp;amp;lt;FUNCTION&amp;amp;gt;[n].au3&amp;lt;/code&amp;gt; where n is an integer counter starting at 2.&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;#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&lt;br /&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.10.2&lt;br /&gt;
; Language ......: English&lt;br /&gt;
; Author(s) .....: &lt;br /&gt;
; Modifiers .....: &lt;br /&gt;
; Forum link ....: a link to the main forum topic (if aplicable)&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13221</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=13221"/>
		<updated>2015-09-04T05:21:09Z</updated>

		<summary type="html">&lt;p&gt;Guinness: &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 Apps 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;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;hello world&amp;quot;&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;
| id || An AutoIt controlId || $idButton = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&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;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Dow;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $oShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $vData = ClipGet()&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452&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 $idGo = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop), $idQuit = 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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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 efficent 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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13220</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=13220"/>
		<updated>2015-09-04T05:04:52Z</updated>

		<summary type="html">&lt;p&gt;Guinness: &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 Apps 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;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;hello world&amp;quot;&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;
| id || An AutoIt controlId || $idButton = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&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;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Dow;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $oShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $vData = ClipGet()&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452&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 $idGo = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop), $idQuit = 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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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 efficent 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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13219</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=13219"/>
		<updated>2015-09-04T05:03:18Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Variable Initialization */&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 Apps 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;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;hello world&amp;quot;&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;
| id || An AutoIt controlID || $idButton = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&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;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Dow;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $oShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $vData = ClipGet()&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452&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 $idGo = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop), $idQuit = 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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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 efficent 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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=13218</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=13218"/>
		<updated>2015-09-04T05:02:21Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* 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 Apps 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;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;hello world&amp;quot;&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;
| id || An AutoIt controlID || $idButton = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&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;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Dow;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $oShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $vData = ClipGet()&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452&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 $idGo = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop), $idQuit = 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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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 efficent 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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Talk:UDF-spec&amp;diff=13217</id>
		<title>Talk:UDF-spec</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Talk:UDF-spec&amp;diff=13217"/>
		<updated>2015-09-04T04:59:07Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Coding Practice */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is currently under construction by Mat. It is being ported from this page: [http://dl.dropbox.com/u/22257420/Programming/UdfSpec.html]&lt;br /&gt;
&lt;br /&gt;
All content has been copied across, but links may not work and formatting may be broken.&lt;br /&gt;
&lt;br /&gt;
--[[User:Mat|Mat]] 09:28, 16 November 2011 (GMT)&lt;br /&gt;
&lt;br /&gt;
== Outdated information ==&lt;br /&gt;
New updates to AutoIt are including changes to the syntax. Certain sections of this document will need to be revisited. &lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
* There are a number of places where current headers differ slightly from these standards. &lt;br /&gt;
** Structures aren&#039;t using the Related field. It was added here as it is looked for by the docs generator, and should be there anyway.&lt;br /&gt;
** Structures have a varied naming convention, not always following the rule of including the type notation. Particularly StructureConstants.au3.&lt;br /&gt;
* The header for _WinAPI_GetMousePos isn&#039;t as it appears above, but it should be.&lt;br /&gt;
* Variable naming is still a matter of personal style. As long as it&#039;s readable and makes sense then it is acceptable. That part remains a guideline as opposed to a standard.&lt;br /&gt;
* There probably needs to be two versions of this document. One for MVPs working directly with the UDFs and examples and another for other community members working on non-standard UDFs.&lt;br /&gt;
&lt;br /&gt;
== Coding Practice ==&lt;br /&gt;
&lt;br /&gt;
This page does not currently cover coding practices other than naming conventions. The topic of programming best practice is very broad and so I have no intention of adding it to this page.&lt;br /&gt;
&lt;br /&gt;
Useful links:&lt;br /&gt;
* [https://www.autoitscript.com/wiki/Best_coding_practices Best Coding Practices In AutoIt]&lt;br /&gt;
* [http://www.autoitscript.com/forum/topic/146866-best-coding-practices-in-autoit/ Best Coding Practices In AutoIt [Forums&amp;lt;nowiki&amp;gt;]&amp;lt;/nowiki&amp;gt;]&lt;br /&gt;
&lt;br /&gt;
--[[User:Mdiesel|Mdiesel]] ([[User talk:Mdiesel|talk]]) 01:38, 7 January 2013 (UTC)&lt;br /&gt;
--[[User:guinness|guinness]] ([[User talk:guinness|talk]]) 06:57, 4 September 2015 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Variable naming conventions ==&lt;br /&gt;
&lt;br /&gt;
The variable prefix system is only designed to be a recommendation. The idea is that variable naming should be something someone else can read and understand easily.&lt;br /&gt;
&lt;br /&gt;
A usage prefix is preferred to a type prefix. For example, dll struct strings are always prefixed $tag, rather than $s. If there is a logical usage prefix then it should be used rather than the type prefixes showed.&lt;br /&gt;
&lt;br /&gt;
There is also discussion about floats and boolean prefixes [http://www.autoitscript.com/forum/topic/146866-best-coding-practices-in-autoit/page__st__240#entry1072359 here].&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Talk:UDF-spec&amp;diff=13216</id>
		<title>Talk:UDF-spec</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Talk:UDF-spec&amp;diff=13216"/>
		<updated>2015-09-04T04:57:47Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Coding Practice */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is currently under construction by Mat. It is being ported from this page: [http://dl.dropbox.com/u/22257420/Programming/UdfSpec.html]&lt;br /&gt;
&lt;br /&gt;
All content has been copied across, but links may not work and formatting may be broken.&lt;br /&gt;
&lt;br /&gt;
--[[User:Mat|Mat]] 09:28, 16 November 2011 (GMT)&lt;br /&gt;
&lt;br /&gt;
== Outdated information ==&lt;br /&gt;
New updates to AutoIt are including changes to the syntax. Certain sections of this document will need to be revisited. &lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
* There are a number of places where current headers differ slightly from these standards. &lt;br /&gt;
** Structures aren&#039;t using the Related field. It was added here as it is looked for by the docs generator, and should be there anyway.&lt;br /&gt;
** Structures have a varied naming convention, not always following the rule of including the type notation. Particularly StructureConstants.au3.&lt;br /&gt;
* The header for _WinAPI_GetMousePos isn&#039;t as it appears above, but it should be.&lt;br /&gt;
* Variable naming is still a matter of personal style. As long as it&#039;s readable and makes sense then it is acceptable. That part remains a guideline as opposed to a standard.&lt;br /&gt;
* There probably needs to be two versions of this document. One for MVPs working directly with the UDFs and examples and another for other community members working on non-standard UDFs.&lt;br /&gt;
&lt;br /&gt;
== Coding Practice ==&lt;br /&gt;
&lt;br /&gt;
This page does not currently cover coding practices other than naming conventions. The topic of programming best practice is very broad and so I have no intention of adding it to this page.&lt;br /&gt;
&lt;br /&gt;
Useful links:&lt;br /&gt;
* [http://www.autoitscript.com/forum/topic/146866-best-coding-practices-in-autoit/ Best Coding Practices In AutoIt [Forums&amp;lt;nowiki&amp;gt;]&amp;lt;/nowiki&amp;gt;]&lt;br /&gt;
* [https://www.autoitscript.com/wiki/Best_coding_practices Best Coding Practices In AutoIt [Forums&amp;lt;nowiki&amp;gt;]&amp;lt;/nowiki&amp;gt;]&lt;br /&gt;
&lt;br /&gt;
--[[User:Mdiesel|Mdiesel]] ([[User talk:Mdiesel|talk]]) 01:38, 7 January 2013 (UTC)&lt;br /&gt;
--[[User:guinness|guinness]] ([[User talk:guinness|talk]]) 06:57, 4 September 2015 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Variable naming conventions ==&lt;br /&gt;
&lt;br /&gt;
The variable prefix system is only designed to be a recommendation. The idea is that variable naming should be something someone else can read and understand easily.&lt;br /&gt;
&lt;br /&gt;
A usage prefix is preferred to a type prefix. For example, dll struct strings are always prefixed $tag, rather than $s. If there is a logical usage prefix then it should be used rather than the type prefixes showed.&lt;br /&gt;
&lt;br /&gt;
There is also discussion about floats and boolean prefixes [http://www.autoitscript.com/forum/topic/146866-best-coding-practices-in-autoit/page__st__240#entry1072359 here].&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12945</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=12945"/>
		<updated>2015-04-01T05:05:29Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* 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;
== Names of Variables ==&lt;br /&gt;
The variable naming convention used in AutoIt is based on [http://en.wikipedia.org/wiki/Hungarian_notation Apps 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;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;hello world&amp;quot;&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;
| id || An AutoIt controlID || $idButton = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&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;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Dow;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $oShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $vData = ClipGet()&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452&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, 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 $idGo = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop), $idQuit = 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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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 efficent 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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12944</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=12944"/>
		<updated>2015-04-01T04:59:02Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* 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;
== Names of Variables ==&lt;br /&gt;
The variable naming convention used in AutoIt is based on [http://en.wikipedia.org/wiki/Hungarian_notation Apps 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;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;hello world&amp;quot;&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;
| id || An AutoIt controlID || $idButton = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&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;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Dow;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $oShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $vData = ClipGet()&lt;br /&gt;
|-&lt;br /&gt;
| e || Constant variable || Local Const $eEulersConstant = 2.7182818284590452&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, 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 $idGo = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop), $idQuit = 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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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 $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $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 $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 $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;, $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 $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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 efficent 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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Variables_-_using_Global,_Local,_Static_and_ByRef&amp;diff=12938</id>
		<title>Variables - using Global, Local, Static and ByRef</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Variables_-_using_Global,_Local,_Static_and_ByRef&amp;diff=12938"/>
		<updated>2015-03-25T04:13:54Z</updated>

		<summary type="html">&lt;p&gt;Guinness: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Tutorials]]&lt;br /&gt;
These keywords confuse many coders - this tutorial should help make their use clear.&lt;br /&gt;
&lt;br /&gt;
In most programming languages you can define the scope of variables - this determines the visibility or accessibility of the variable from different parts of the program. &lt;br /&gt;
&lt;br /&gt;
In AutoIt there are two possible scopes: &#039;&#039;Global&#039;&#039; and &#039;&#039;Local&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
- A &#039;&#039;&#039;Global&#039;&#039;&#039; variable is visible throughout your script - any part of the script can both read its value and, importantly, change it.&lt;br /&gt;
&lt;br /&gt;
- A &#039;&#039;&#039;Local&#039;&#039;&#039; variable exists only within the function in which it is declared and is destroyed when the function terminates. It is invisible to any other function unless it is passed as a parameter.&lt;br /&gt;
&lt;br /&gt;
Additionally declaring a variable as &#039;&#039;&#039;Static&#039;&#039;&#039; changes its behaviour slightly. A &#039;&#039;Global Static&#039;&#039; variable serves no useful purpose as it is essentially the same as a normal &#039;&#039;Global&#039;&#039; variable. However, a &#039;&#039;Local Static&#039;&#039; variable exists only within the function in which it is declared, but is NOT destroyed when the function ends and can be reused when the function is next entered. You can assign an initial value to this variable when it is created - if it is already in existence then the assignment is ignored. Note that the order of the keywords is not important.&lt;br /&gt;
&lt;br /&gt;
Why do we need to scope variables? Well, it is often useful to have a single variable used throughout the script - perhaps the name of an Ini file which if declared as &#039;&#039;Global&#039;&#039; can then be read by any function that requires it. And &#039;&#039;Local&#039;&#039; variables allow us to save resources by only using variables as long as we need - for example if we create a large array which is only needed within a single function.&lt;br /&gt;
&lt;br /&gt;
We scope variables by using the &#039;&#039;Global, Local&#039;&#039; and &#039;&#039;Static&#039;&#039; keywords when the variables are first declared - look at the examples below. By default, AutoIt scopes any variables declared in the main body of a script (that is not between a &#039;&#039;Func&#039;&#039; and &#039;&#039;EndFunc&#039;&#039; pair) as &#039;&#039;Global&#039;&#039; and any variables declared within function declarations as &#039;&#039;Local&#039;&#039;. But it is a good idea to explicitly declare your variables to make sure that you get what you want. For example, you can declare a variable as &#039;&#039;Global&#039;&#039; within a function - although you may get a gentle reminder when you run your script within SciTE that this is not recommended. But there is no point declaring any variables in the main body of a script as &#039;&#039;Local&#039;&#039; - they will be &#039;&#039;Global&#039;&#039; regardless. If you use the &#039;&#039;AutoItSetOption(&amp;quot;MustDeclareVars&amp;quot;, 1)&#039;&#039; directive you &#039;&#039;must&#039;&#039; declare the scope of your variables or you will get error messages.&lt;br /&gt;
&lt;br /&gt;
In the Help file pages for &#039;&#039;Global, Local&#039;&#039; and &#039;&#039;Static&#039;&#039; you will also see mention of &#039;&#039;Dim&#039;&#039; and &#039;&#039;ReDim&#039;&#039;. Using &#039;&#039;Dim&#039;&#039; will declare a variable and satisfy the &#039;&#039;AutoItSetOption&#039;&#039; just mentioned, but will let AutoIt scope the variable using the default settings as described above. It is much better practice to use &#039;&#039;Global&#039;&#039; or &#039;&#039;Local&#039;&#039; to set the scope you require explicitly. Despite its similar name, &#039;&#039;ReDim&#039;&#039; is only used to resize arrays without destroying the content and is outside the scope of this tutorial.&lt;br /&gt;
&lt;br /&gt;
Let us now look at a simple example when we read and change &#039;&#039;Global&#039;&#039; variables in a function:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt; ; only required for MsgBox constants&lt;br /&gt;
&lt;br /&gt;
Global $Var_1 = &amp;quot;Variable 1&amp;quot;&lt;br /&gt;
Global $Var_2 = &amp;quot;Variable 2&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; Read the variables&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In The Main Script&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 1 = &amp;quot; &amp;amp; $Var_1 &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 2 = &amp;quot; &amp;amp; $Var_2)&lt;br /&gt;
&lt;br /&gt;
; Read the variables in a function&lt;br /&gt;
Function()&lt;br /&gt;
&lt;br /&gt;
; And now read the variables again - see that $iVar_2 has changed&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;Back In The Main Script&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 1 = &amp;quot; &amp;amp; $Var_1 &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 2 = &amp;quot; &amp;amp; $Var_2)&lt;br /&gt;
&lt;br /&gt;
Func Function()&lt;br /&gt;
	; Read the variables&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In The Function&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 1 = &amp;quot; &amp;amp; $Var_1 &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 2 = &amp;quot; &amp;amp; $Var_2)&lt;br /&gt;
	; Now let us change one of the variables WITHIN the function&lt;br /&gt;
	$Var_2 = &amp;quot;Changed Variable 2&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;Function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Here is a simple example showing how &#039;&#039;Local&#039;&#039; variables are only visible &#039;&#039;inside&#039;&#039; their own function:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt; ; only required for MsgBox constants&lt;br /&gt;
&lt;br /&gt;
Global $Var_1 = &amp;quot;Variable 1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; Read the variable&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In The Main Script&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 1 = &amp;quot; &amp;amp; $Var_1)&lt;br /&gt;
&lt;br /&gt;
; Now run a function&lt;br /&gt;
Function()&lt;br /&gt;
&lt;br /&gt;
; And now try to read Variable 3 outside the function&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;Back In The Main Script&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 1 = &amp;quot; &amp;amp; $Var_1 &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 3 = &amp;quot; &amp;amp; $Var_3)&lt;br /&gt;
&lt;br /&gt;
Func Function()&lt;br /&gt;
	; Declare a Local variable&lt;br /&gt;
	Local $Var_3 = &amp;quot;Variable 3&amp;quot;&lt;br /&gt;
	; Read the variables&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In The Function&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 1 = &amp;quot; &amp;amp; $Var_1 &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 3 = &amp;quot; &amp;amp; $Var_3)&lt;br /&gt;
EndFunc   ;==&amp;gt;Function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You should have got errors telling you that &#039;&#039;$Var3&#039;&#039; was &amp;quot;&#039;&#039;possibly used before declaration&#039;&#039;&amp;quot; and an &amp;quot;&#039;&#039;undeclared global variable&#039;&#039;&amp;quot;.  This is because &#039;&#039;$Var3&#039;&#039; exists only &#039;&#039;within&#039;&#039; the function - when the function ends it is destroyed.&lt;br /&gt;
&lt;br /&gt;
This means that we can use the same variable name in different functions without causing a problem - very useful for simple variables which are only used temporarily:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
 #include &amp;lt;MsgConstants.au3&amp;gt;; only required for MsgBox constants&lt;br /&gt;
&lt;br /&gt;
Function_1()&lt;br /&gt;
&lt;br /&gt;
Func Function_1()&lt;br /&gt;
	; Declare the variable in this function&lt;br /&gt;
	Local $sString = &amp;quot;Variable in Function One&amp;quot;&lt;br /&gt;
	; Read the value&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In Function One&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable = &amp;quot; &amp;amp; $sString)&lt;br /&gt;
&lt;br /&gt;
	; Now run Function Two&lt;br /&gt;
	Function_2()&lt;br /&gt;
&lt;br /&gt;
	; Now read the variable again - we still get the variable from this function&lt;br /&gt;
	; The variable in Function 2 has been destroyed now the function has terminated&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In Function One&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable = &amp;quot; &amp;amp; $sString)&lt;br /&gt;
EndFunc   ;==&amp;gt;Function_1&lt;br /&gt;
&lt;br /&gt;
Func Function_2()&lt;br /&gt;
	; Declare a variable with the same name&lt;br /&gt;
	Local $sString = &amp;quot;Variable in Function Two&amp;quot;&lt;br /&gt;
	; Read this variable - see how we get the value in this function, not the value in Function One&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In Function Two&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable = &amp;quot; &amp;amp; $sString)&lt;br /&gt;
EndFunc   ;==&amp;gt;Function_2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
AutoIt even allows you to use the same name for &#039;&#039;Global&#039;&#039; and &#039;&#039;Local&#039;&#039; variables, although this is &#039;&#039;not&#039;&#039; recommended as it could easily lead to confusion.  If there is a naming conflict of this kind, AutoIt uses the &#039;&#039;Local&#039;&#039; value as you can see here:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;; only required for MsgBox constants&lt;br /&gt;
&lt;br /&gt;
; Declare the variable as Global&lt;br /&gt;
Global $sString = &amp;quot;Global Variable in the Main Script&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; Read it&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In the Main Script&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable = &amp;quot; &amp;amp; $sString)&lt;br /&gt;
&lt;br /&gt;
; Run the functions which declare Local variables with the same name&lt;br /&gt;
Function_1()&lt;br /&gt;
&lt;br /&gt;
; And now see that the Global variable still exists unchanged&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In the Main Script&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable = &amp;quot; &amp;amp; $sString)&lt;br /&gt;
&lt;br /&gt;
Func Function_1()&lt;br /&gt;
	; Declare a variable with the SAME name as Local to this function&lt;br /&gt;
	Local $sString = &amp;quot;Variable in Function One&amp;quot;&lt;br /&gt;
	; Read the value - we get the value of the Local variable in this function, not the Global one&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In Function One&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable = &amp;quot; &amp;amp; $sString)&lt;br /&gt;
EndFunc   ;==&amp;gt;Function_1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A good use for &#039;&#039;Static&#039;&#039; variables is when you need to maintain a record of a value within a function even though the function itself ends.  An example might be that you want to do something the first time a function is called, but not subsequently:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Foo()&lt;br /&gt;
Foo()&lt;br /&gt;
Foo()&lt;br /&gt;
&lt;br /&gt;
Func Foo()&lt;br /&gt;
	; Set the flag only on the first entry into the function&lt;br /&gt;
	; This assignment will be ignored on subsequent entries&lt;br /&gt;
	Local Static $bFoo_First_Pass = True&lt;br /&gt;
&lt;br /&gt;
	; Check the flag&lt;br /&gt;
	If $bFoo_First_Pass Then&lt;br /&gt;
		; Immediately clear the flag to prevent running on subsequent passes&lt;br /&gt;
		$bFoo_First_Pass = False&lt;br /&gt;
		; Run on first pass because flag is set&lt;br /&gt;
		ConsoleWrite(&amp;quot;First pass&amp;quot; &amp;amp; @CRLF)&lt;br /&gt;
	Else&lt;br /&gt;
		; Flag remains cleared for subsequent passes&lt;br /&gt;
		ConsoleWrite(&amp;quot;Not first pass&amp;quot; &amp;amp; @CRLF)&lt;br /&gt;
	EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;Foo&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
As the &#039;&#039;Local&#039;&#039; part of their declaration implies, you can use the same name for &#039;&#039;Static&#039;&#039; variables in different functions - even though they are not destroyed when the functions end:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
 For $i = 1 To 5&lt;br /&gt;
	Function_1()&lt;br /&gt;
	Function_2()&lt;br /&gt;
Next&lt;br /&gt;
&lt;br /&gt;
Func Function_1()&lt;br /&gt;
	; Declare the variable as Static - remember this only happens once&lt;br /&gt;
	Local Static $vVar = 0&lt;br /&gt;
	; Increase the value of the variable each time we enter the function&lt;br /&gt;
	$vVar += 10&lt;br /&gt;
	; And show that it has retained its value as the function exits&lt;br /&gt;
	ConsoleWrite(&amp;quot;In Function_1: &amp;quot; &amp;amp; $vVar &amp;amp; @CRLF)&lt;br /&gt;
EndFunc   ;==&amp;gt;Function_1&lt;br /&gt;
&lt;br /&gt;
Func Function_2()&lt;br /&gt;
	; Use the same variable name&lt;br /&gt;
	Local Static $vVar = 0&lt;br /&gt;
	$vVar += 100&lt;br /&gt;
	ConsoleWrite(&amp;quot;In Function_2: &amp;quot; &amp;amp; $vVar &amp;amp; @CRLF)&lt;br /&gt;
EndFunc   ;==&amp;gt;Function_2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
As a general rule, try to have as few &#039;&#039;Global&#039;&#039; variables as you can.  Remember that you can share &#039;&#039;Local&#039;&#039; variables between functions - and even change their values - by passing them as parameters as we will see in the &#039;&#039;ByRef&#039;&#039; section below.  And declaring a variable as &#039;&#039;Static&#039;&#039; allows you retain its value even though the function in which it is used has ended.&lt;br /&gt;
&lt;br /&gt;
=Passing variables as parameters using ByRef=&lt;br /&gt;
When you call a function in AutoIt, you can pass parameters to the function by including them in the parentheses following the function name like this - &#039;&#039;Function(Parameter_1, Parameter_2)&#039;&#039;.  Passing variables in this way means that you can use variables that have been declared as &#039;&#039;Local&#039;&#039; within other functions. Note that the parameters are automatically declared as &#039;&#039;Local&#039;&#039; variables within the called function and so do not need to be declared again in the code.&lt;br /&gt;
&lt;br /&gt;
Variables can be passed as parameters to a function in 2 ways:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;By Value&#039;&#039;&#039; - This is the default. The parameter is treated as a &#039;&#039;Local&#039;&#039; variable within the function to which it is passed and any changes made to it are lost when the function ends. So no changes are made to the &#039;&#039;Local&#039;&#039; variable within the original function.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;By Reference&#039;&#039;&#039; - This is used when &#039;&#039;ByRef&#039;&#039; is added &#039;&#039;before&#039;&#039; the variable name in the parameter list of the function declaration. Now any changes to the variable made in the function to which it is passed also affect the &#039;&#039;Local&#039;&#039; variable in the original function.  If you do not understand why this is such a powerful capability, you need to read the &#039;&#039;Global/Local&#039;&#039; section again!&lt;br /&gt;
&lt;br /&gt;
Here is a small example to show how parameters are passed when calling a function:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
 #include &amp;lt;MsgBoxConstants.au3&amp;gt;; only required for MsgBox constants&lt;br /&gt;
&lt;br /&gt;
Func_A()&lt;br /&gt;
&lt;br /&gt;
Func Func_A()&lt;br /&gt;
	; Declare variables&lt;br /&gt;
	Local $iVar_A1 = 10&lt;br /&gt;
	Local $iVar_A2 = 20&lt;br /&gt;
	; And read them&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Initial read in Func A:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var A1 = &amp;quot; &amp;amp; $iVar_A1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var A2 = &amp;quot; &amp;amp; $iVar_A2)&lt;br /&gt;
&lt;br /&gt;
	; Now pass these variables to another function - we use the names we have already declared in this function&lt;br /&gt;
	Func_B($iVar_A1, $iVar_A2)&lt;br /&gt;
&lt;br /&gt;
	; We changed the parameters in Func_B - but nothing happened to the variables in this function&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Second read in Func A:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var A1 = &amp;quot; &amp;amp; $iVar_A1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var A2 = &amp;quot; &amp;amp; $iVar_A2)&lt;br /&gt;
EndFunc   ;==&amp;gt;Func_A&lt;br /&gt;
&lt;br /&gt;
Func Func_B($iVar_B1, $iVar_B2) ; There is no need to declare the variables as parameters are automatically Local in scope&lt;br /&gt;
	; Now read these variables - note that they have the same value as the variables in Func_A&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Initial read in Func B:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var B1 = &amp;quot; &amp;amp; $iVar_B1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var B2 = &amp;quot; &amp;amp; $iVar_B2)&lt;br /&gt;
&lt;br /&gt;
	; Let us change them&lt;br /&gt;
	$iVar_B1 = 100&lt;br /&gt;
	$iVar_B2 = 200&lt;br /&gt;
&lt;br /&gt;
	; And confirm that they have changed&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Second read in Func B:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var B1 = &amp;quot; &amp;amp; $iVar_B1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var B2 = &amp;quot; &amp;amp; $iVar_B2)&lt;br /&gt;
&lt;br /&gt;
	; Now return to the other function&lt;br /&gt;
EndFunc   ;==&amp;gt;Func_B&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
As you can see, the &#039;&#039;Local&#039;&#039; variables within &#039;&#039;Func_A&#039;&#039; are read perfectly by &#039;&#039;Func_B&#039;&#039; when passed as parameters, even though they were declared as &#039;&#039;Local&#039;&#039; in &#039;&#039;Func_A&#039;&#039;.  However, although &#039;&#039;Func_B&#039;&#039; changes the value of the variables, the values of the original variables within &#039;&#039;Func_A&#039;&#039; are not changed.&lt;br /&gt;
&lt;br /&gt;
If we want to change the value of the variables in &#039;&#039;Func_A&#039;&#039; from within &#039;&#039;Func_B&#039;&#039;, we need to use the &#039;&#039;ByRef&#039;&#039; keyword as explained above and illustrated here:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
 #include &amp;lt;MsgBoxConstants.au3&amp;gt;; only required for MsgBox constants&lt;br /&gt;
&lt;br /&gt;
Func_A()&lt;br /&gt;
&lt;br /&gt;
Func Func_A()&lt;br /&gt;
	; Declare variables&lt;br /&gt;
	Local $iVar_A1 = 10&lt;br /&gt;
	Local $iVar_A2 = 20&lt;br /&gt;
&lt;br /&gt;
	; And read them&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Initial read in Func A:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var A1 = &amp;quot; &amp;amp; $iVar_A1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var A2 = &amp;quot; &amp;amp; $iVar_A2)&lt;br /&gt;
&lt;br /&gt;
	; Now pass these variables to another function - but this time we will pass $iVar_A2 By Reference&lt;br /&gt;
	Func_B($iVar_A1, $iVar_A2)&lt;br /&gt;
&lt;br /&gt;
	; We changed the parameters in Func_B - this time we see that we have changed $iVar_A2&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Second read in Func A:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var A1 = &amp;quot; &amp;amp; $iVar_A1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var A2 = &amp;quot; &amp;amp; $iVar_A2)&lt;br /&gt;
EndFunc   ;==&amp;gt;Func_A&lt;br /&gt;
&lt;br /&gt;
Func Func_B($iVar_B1, ByRef $iVar_B2) ; Note the ByRef keyword in the function declaration for the second parameter&lt;br /&gt;
	; Now read these variables - they have the same value as the variables in Func_A&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Initial read in Func B:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var B1 = &amp;quot; &amp;amp; $iVar_B1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var B2 = &amp;quot; &amp;amp; $iVar_B2)&lt;br /&gt;
&lt;br /&gt;
	; Let us change them&lt;br /&gt;
	$iVar_B1 = 100&lt;br /&gt;
	$iVar_B2 = 200&lt;br /&gt;
&lt;br /&gt;
	; And confirm that they have changed&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Second read in Func B:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var B1 = &amp;quot; &amp;amp; $iVar_B1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var B2 = &amp;quot; &amp;amp; $iVar_B2)&lt;br /&gt;
&lt;br /&gt;
	; Now return to the other function&lt;br /&gt;
EndFunc   ;==&amp;gt;Func_B&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A couple of more advanced points:&lt;br /&gt;
&lt;br /&gt;
- It was mentioned earlier that when you pass variables to functions AutoIt makes local copies of these variables unless you declare that they are to be passed &#039;&#039;ByRef&#039;&#039;.  In the special case of arrays, which are typically larger than a simple variable, AutoIt will only make a local copy if you change the array inside the function - merely accessing the array will use the original version.  So passing the array &#039;&#039;ByRef&#039;&#039; is only advantageous if you intend to modify the array within the function - however, it does no harm to force the issue by using the keyword.&lt;br /&gt;
&lt;br /&gt;
- If you are dealing with a simple variable of considerable size (the text of a file for example) then passing it &#039;&#039;ByRef&#039;&#039; is a sensible action.  But if you want to make sure that the variable cannot be altered inside the function, you can declare it as &#039;&#039;Const ByRef&#039;&#039; in the function definition as shown here:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Local $sString = &amp;quot;A very large chunk of data which we do not want to change&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Foo($sString)&lt;br /&gt;
&lt;br /&gt;
Func Foo(Const ByRef $sText) ; The data is not copied, but also cannot be changed&lt;br /&gt;
	; Uncomment this line to see what happens when we try&lt;br /&gt;
	;$sText = &amp;quot;New value&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;Foo&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;ByRef&#039;&#039; is a very powerful feature - but use it carefully, or you may find that you have changed a variable when you did not want to!&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Variables_-_using_Global,_Local,_Static_and_ByRef&amp;diff=12937</id>
		<title>Variables - using Global, Local, Static and ByRef</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Variables_-_using_Global,_Local,_Static_and_ByRef&amp;diff=12937"/>
		<updated>2015-03-25T04:11:59Z</updated>

		<summary type="html">&lt;p&gt;Guinness: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Tutorials]]&lt;br /&gt;
These keywords confuse many coders - this tutorial should help make their use clear.&lt;br /&gt;
&lt;br /&gt;
In most programming languages you can define the scope of variables - this determines the visibility or accessibility of the variable from different parts of the program. &lt;br /&gt;
&lt;br /&gt;
In AutoIt there are two possible scopes: &#039;&#039;Global&#039;&#039; and &#039;&#039;Local&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
- A &#039;&#039;&#039;Global&#039;&#039;&#039; variable is visible throughout your script - any part of the script can both read its value and, importantly, change it.&lt;br /&gt;
&lt;br /&gt;
- A &#039;&#039;&#039;Local&#039;&#039;&#039; variable exists only within the function in which it is declared and is destroyed when the function terminates. It is invisible to any other function unless it is passed as a parameter.&lt;br /&gt;
&lt;br /&gt;
Additionally declaring a variable as &#039;&#039;&#039;Static&#039;&#039;&#039; changes its behaviour slightly. A &#039;&#039;Global Static&#039;&#039; variable serves no useful purpose as it is essentially the same as a normal &#039;&#039;Global&#039;&#039; variable. However, a &#039;&#039;Local Static&#039;&#039; variable exists only within the function in which it is declared, but is NOT destroyed when the function ends and can be reused when the function is next entered. You can assign an initial value to this variable when it is created - if it is already in existence then the assignment is ignored. Note that the order of the keywords is not important.&lt;br /&gt;
&lt;br /&gt;
Why do we need to scope variables? Well, it is often useful to have a single variable used throughout the script - perhaps the name of an Ini file which if declared as &#039;&#039;Global&#039;&#039; can then be read by any function that requires it. And &#039;&#039;Local&#039;&#039; variables allow us to save resources by only using variables as long as we need - for example if we create a large array which is only needed within a single function.&lt;br /&gt;
&lt;br /&gt;
We scope variables by using the &#039;&#039;Global, Local&#039;&#039; and &#039;&#039;Static&#039;&#039; keywords when the variables are first declared - look at the examples below. By default, AutoIt scopes any variables declared in the main body of a script (that is not between a &#039;&#039;Func&#039;&#039; and &#039;&#039;EndFunc&#039;&#039; pair) as &#039;&#039;Global&#039;&#039; and any variables declared within function declarations as &#039;&#039;Local&#039;&#039;. But it is a good idea to explicitly declare your variables to make sure that you get what you want. For example, you can declare a variable as &#039;&#039;Global&#039;&#039; within a function - although you may get a gentle reminder when you run your script within SciTE that this is not recommended. But there is no point declaring any variables in the main body of a script as &#039;&#039;Local&#039;&#039; - they will be &#039;&#039;Global&#039;&#039; regardless. If you use the &#039;&#039;AutoItSetOption(&amp;quot;MustDeclareVars&amp;quot;, 1)&#039;&#039; directive you &#039;&#039;must&#039;&#039; declare the scope of your variables or you will get error messages.&lt;br /&gt;
&lt;br /&gt;
In the Help file pages for &#039;&#039;Global, Local&#039;&#039; and &#039;&#039;Static&#039;&#039; you will also see mention of &#039;&#039;Dim&#039;&#039; and &#039;&#039;ReDim&#039;&#039;. Using &#039;&#039;Dim&#039;&#039; will declare a variable and satisfy the &#039;&#039;AutoItSetOption&#039;&#039; just mentioned, but will let AutoIt scope the variable using the default settings as described above. It is much better practice to use &#039;&#039;Global&#039;&#039; or &#039;&#039;Local&#039;&#039; to set the scope you require explicitly. Despite its similar name, &#039;&#039;ReDim&#039;&#039; is only used to resize arrays without destroying the content and is outside the scope of this tutorial.&lt;br /&gt;
&lt;br /&gt;
Let us now look at a simple example when we read and change &#039;&#039;Global&#039;&#039; variables in a function:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt; ; only required for MsgBox constants&lt;br /&gt;
&lt;br /&gt;
Global $Var_1 = &amp;quot;Variable 1&amp;quot;&lt;br /&gt;
Global $Var_2 = &amp;quot;Variable 2&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; Read the variables&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In The Main Script&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 1 = &amp;quot; &amp;amp; $Var_1 &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 2 = &amp;quot; &amp;amp; $Var_2)&lt;br /&gt;
&lt;br /&gt;
; Read the variables in a function&lt;br /&gt;
_Function()&lt;br /&gt;
&lt;br /&gt;
; And now read the variables again - see that $iVar_2 has changed&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;Back In The Main Script&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 1 = &amp;quot; &amp;amp; $Var_1 &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 2 = &amp;quot; &amp;amp; $Var_2)&lt;br /&gt;
&lt;br /&gt;
Func _Function()&lt;br /&gt;
	; Read the variables&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In The Function&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 1 = &amp;quot; &amp;amp; $Var_1 &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 2 = &amp;quot; &amp;amp; $Var_2)&lt;br /&gt;
	; Now let us change one of the variables WITHIN the function&lt;br /&gt;
	$Var_2 = &amp;quot;Changed Variable 2&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;_Function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Here is a simple example showing how &#039;&#039;Local&#039;&#039; variables are only visible &#039;&#039;inside&#039;&#039; their own function:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt; ; only required for MsgBox constants&lt;br /&gt;
&lt;br /&gt;
Global $Var_1 = &amp;quot;Variable 1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; Read the variable&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In The Main Script&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 1 = &amp;quot; &amp;amp; $Var_1)&lt;br /&gt;
&lt;br /&gt;
; Now run a function&lt;br /&gt;
_Function()&lt;br /&gt;
&lt;br /&gt;
; And now try to read Variable 3 outside the function&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;Back In The Main Script&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 1 = &amp;quot; &amp;amp; $Var_1 &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 3 = &amp;quot; &amp;amp; $Var_3)&lt;br /&gt;
&lt;br /&gt;
Func _Function()&lt;br /&gt;
	; Declare a Local variable&lt;br /&gt;
	Local $Var_3 = &amp;quot;Variable 3&amp;quot;&lt;br /&gt;
	; Read the variables&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In The Function&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 1 = &amp;quot; &amp;amp; $Var_1 &amp;amp; @CRLF &amp;amp; &amp;quot;Variable 3 = &amp;quot; &amp;amp; $Var_3)&lt;br /&gt;
EndFunc   ;==&amp;gt;_Function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You should have got errors telling you that &#039;&#039;$Var3&#039;&#039; was &amp;quot;&#039;&#039;possibly used before declaration&#039;&#039;&amp;quot; and an &amp;quot;&#039;&#039;undeclared global variable&#039;&#039;&amp;quot;.  This is because &#039;&#039;$Var3&#039;&#039; exists only &#039;&#039;within&#039;&#039; the function - when the function ends it is destroyed.&lt;br /&gt;
&lt;br /&gt;
This means that we can use the same variable name in different functions without causing a problem - very useful for simple variables which are only used temporarily:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
 #include &amp;lt;MsgConstants.au3&amp;gt;; only required for MsgBox constants&lt;br /&gt;
&lt;br /&gt;
Function_1()&lt;br /&gt;
&lt;br /&gt;
Func Function_1()&lt;br /&gt;
	; Declare the variable in this function&lt;br /&gt;
	Local $sString = &amp;quot;Variable in Function One&amp;quot;&lt;br /&gt;
	; Read the value&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In Function One&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable = &amp;quot; &amp;amp; $sString)&lt;br /&gt;
&lt;br /&gt;
	; Now run Function Two&lt;br /&gt;
	Function_2()&lt;br /&gt;
&lt;br /&gt;
	; Now read the variable again - we still get the variable from this function&lt;br /&gt;
	; The variable in Function 2 has been destroyed now the function has terminated&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In Function One&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable = &amp;quot; &amp;amp; $sString)&lt;br /&gt;
EndFunc   ;==&amp;gt;Function_1&lt;br /&gt;
&lt;br /&gt;
Func Function_2()&lt;br /&gt;
	; Declare a variable with the SAME name&lt;br /&gt;
	Local $sString = &amp;quot;Variable in Function Two&amp;quot;&lt;br /&gt;
	; Read this variable - see how we get the value in this function, not the value in Function One&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In Function Two&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable = &amp;quot; &amp;amp; $sString)&lt;br /&gt;
EndFunc   ;==&amp;gt;Function_2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
AutoIt even allows you to use the same name for &#039;&#039;Global&#039;&#039; and &#039;&#039;Local&#039;&#039; variables, although this is &#039;&#039;not&#039;&#039; recommended as it could easily lead to confusion.  If there is a naming conflict of this kind, AutoIt uses the &#039;&#039;Local&#039;&#039; value as you can see here:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;; only required for MsgBox constants&lt;br /&gt;
&lt;br /&gt;
; Declare the variable as Global&lt;br /&gt;
Global $sString = &amp;quot;Global Variable in the Main Script&amp;quot;&lt;br /&gt;
&lt;br /&gt;
; Read it&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In the Main Script&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable = &amp;quot; &amp;amp; $sString)&lt;br /&gt;
&lt;br /&gt;
; Run the functions which declare Local variables with the same name&lt;br /&gt;
Function_1()&lt;br /&gt;
&lt;br /&gt;
; And now see that the Global variable still exists unchanged&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In the Main Script&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable = &amp;quot; &amp;amp; $sString)&lt;br /&gt;
&lt;br /&gt;
Func Function_1()&lt;br /&gt;
	; Declare a variable with the SAME name as Local to this function&lt;br /&gt;
	Local $sString = &amp;quot;Variable in Function One&amp;quot;&lt;br /&gt;
	; Read the value - we get the value of the Local variable in this function, not the Global one&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Reading&amp;quot;, &amp;quot;In Function One&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; &amp;quot;Variable = &amp;quot; &amp;amp; $sString)&lt;br /&gt;
EndFunc   ;==&amp;gt;Function_1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A good use for &#039;&#039;Static&#039;&#039; variables is when you need to maintain a record of a value within a function even though the function itself ends.  An example might be that you want to do something the first time a function is called, but not subsequently:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Foo()&lt;br /&gt;
Foo()&lt;br /&gt;
Foo()&lt;br /&gt;
&lt;br /&gt;
Func Foo()&lt;br /&gt;
	; Set the flag only on the first entry into the function&lt;br /&gt;
	; This assignment will be ignored on subsequent entries&lt;br /&gt;
	Local Static $bFoo_First_Pass = True&lt;br /&gt;
&lt;br /&gt;
	; Check the flag&lt;br /&gt;
	If $bFoo_First_Pass Then&lt;br /&gt;
		; Immediately clear the flag to prevent running on subsequent passes&lt;br /&gt;
		$bFoo_First_Pass = False&lt;br /&gt;
		; Run on first pass because flag is set&lt;br /&gt;
		ConsoleWrite(&amp;quot;First pass&amp;quot; &amp;amp; @CRLF)&lt;br /&gt;
	Else&lt;br /&gt;
		; Flag remains cleared for subsequent passes&lt;br /&gt;
		ConsoleWrite(&amp;quot;Not first pass&amp;quot; &amp;amp; @CRLF)&lt;br /&gt;
	EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;Foo&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
As the &#039;&#039;Local&#039;&#039; part of their declaration implies, you can use the same name for &#039;&#039;Static&#039;&#039; variables in different functions - even though they are not destroyed when the functions end:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
 For $i = 1 To 5&lt;br /&gt;
	_Function_1()&lt;br /&gt;
	_Function_2()&lt;br /&gt;
Next&lt;br /&gt;
&lt;br /&gt;
Func _Function_1()&lt;br /&gt;
	; Declare the variable as Static - remember this only happens once&lt;br /&gt;
	Local Static $vVar = 0&lt;br /&gt;
	; Increase the value of the variable each time we enter the function&lt;br /&gt;
	$vVar += 10&lt;br /&gt;
	; And show that it has retained its value as the function exits&lt;br /&gt;
	ConsoleWrite(&amp;quot;In Function_1: &amp;quot; &amp;amp; $vVar &amp;amp; @CRLF)&lt;br /&gt;
EndFunc   ;==&amp;gt;_Function_1&lt;br /&gt;
&lt;br /&gt;
Func _Function_2()&lt;br /&gt;
	; Use the same variable name&lt;br /&gt;
	Local Static $vVar = 0&lt;br /&gt;
	$vVar += 100&lt;br /&gt;
	ConsoleWrite(&amp;quot;In Function_2: &amp;quot; &amp;amp; $vVar &amp;amp; @CRLF)&lt;br /&gt;
EndFunc   ;==&amp;gt;_Function_2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
As a general rule, try to have as few &#039;&#039;Global&#039;&#039; variables as you can.  Remember that you can share &#039;&#039;Local&#039;&#039; variables between functions - and even change their values - by passing them as parameters as we will see in the &#039;&#039;ByRef&#039;&#039; section below.  And declaring a variable as &#039;&#039;Static&#039;&#039; allows you retain its value even though the function in which it is used has ended.&lt;br /&gt;
&lt;br /&gt;
=Passing variables as parameters using ByRef=&lt;br /&gt;
When you call a function in AutoIt, you can pass parameters to the function by including them in the parentheses following the function name like this - &#039;&#039;Function(Parameter_1, Parameter_2)&#039;&#039;.  Passing variables in this way means that you can use variables that have been declared as &#039;&#039;Local&#039;&#039; within other functions. Note that the parameters are automatically declared as &#039;&#039;Local&#039;&#039; variables within the called function and so do not need to be declared again in the code.&lt;br /&gt;
&lt;br /&gt;
Variables can be passed as parameters to a function in 2 ways:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;By Value&#039;&#039;&#039; - This is the default. The parameter is treated as a &#039;&#039;Local&#039;&#039; variable within the function to which it is passed and any changes made to it are lost when the function ends. So no changes are made to the &#039;&#039;Local&#039;&#039; variable within the original function.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;By Reference&#039;&#039;&#039; - This is used when &#039;&#039;ByRef&#039;&#039; is added &#039;&#039;before&#039;&#039; the variable name in the parameter list of the function declaration. Now any changes to the variable made in the function to which it is passed also affect the &#039;&#039;Local&#039;&#039; variable in the original function.  If you do not understand why this is such a powerful capability, you need to read the &#039;&#039;Global/Local&#039;&#039; section again!&lt;br /&gt;
&lt;br /&gt;
Here is a small example to show how parameters are passed when calling a function:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
 #include &amp;lt;MsgBoxConstants.au3&amp;gt;; only required for MsgBox constants&lt;br /&gt;
&lt;br /&gt;
Func_A()&lt;br /&gt;
&lt;br /&gt;
Func Func_A()&lt;br /&gt;
	; Declare variables&lt;br /&gt;
	Local $iVar_A1 = 10&lt;br /&gt;
	Local $iVar_A2 = 20&lt;br /&gt;
	; And read them&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Initial read in Func A:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var A1 = &amp;quot; &amp;amp; $iVar_A1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var A2 = &amp;quot; &amp;amp; $iVar_A2)&lt;br /&gt;
&lt;br /&gt;
	; Now pass these variables to another function - we use the names we have already declared in this function&lt;br /&gt;
	Func_B($iVar_A1, $iVar_A2)&lt;br /&gt;
&lt;br /&gt;
	; We changed the parameters in Func_B - but nothing happened to the variables in this function&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Second read in Func A:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var A1 = &amp;quot; &amp;amp; $iVar_A1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var A2 = &amp;quot; &amp;amp; $iVar_A2)&lt;br /&gt;
EndFunc   ;==&amp;gt;Func_A&lt;br /&gt;
&lt;br /&gt;
Func Func_B($iVar_B1, $iVar_B2) ; There is no need to declare the variables as parameters are automatically Local in scope&lt;br /&gt;
	; Now read these variables - note that they have the same value as the variables in Func_A&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Initial read in Func B:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var B1 = &amp;quot; &amp;amp; $iVar_B1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var B2 = &amp;quot; &amp;amp; $iVar_B2)&lt;br /&gt;
&lt;br /&gt;
	; Let us change them&lt;br /&gt;
	$iVar_B1 = 100&lt;br /&gt;
	$iVar_B2 = 200&lt;br /&gt;
&lt;br /&gt;
	; And confirm that they have changed&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Second read in Func B:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var B1 = &amp;quot; &amp;amp; $iVar_B1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var B2 = &amp;quot; &amp;amp; $iVar_B2)&lt;br /&gt;
&lt;br /&gt;
	; Now return to the other function&lt;br /&gt;
EndFunc   ;==&amp;gt;Func_B&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
As you can see, the &#039;&#039;Local&#039;&#039; variables within &#039;&#039;Func_A&#039;&#039; are read perfectly by &#039;&#039;Func_B&#039;&#039; when passed as parameters, even though they were declared as &#039;&#039;Local&#039;&#039; in &#039;&#039;Func_A&#039;&#039;.  However, although &#039;&#039;Func_B&#039;&#039; changes the value of the variables, the values of the original variables within &#039;&#039;Func_A&#039;&#039; are not changed.&lt;br /&gt;
&lt;br /&gt;
If we want to change the value of the variables in &#039;&#039;Func_A&#039;&#039; from within &#039;&#039;Func_B&#039;&#039;, we need to use the &#039;&#039;ByRef&#039;&#039; keyword as explained above and illustrated here:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
 #include &amp;lt;MsgBoxConstants.au3&amp;gt;; only required for MsgBox constants&lt;br /&gt;
&lt;br /&gt;
Func_A()&lt;br /&gt;
&lt;br /&gt;
Func Func_A()&lt;br /&gt;
	; Declare variables&lt;br /&gt;
	Local $iVar_A1 = 10&lt;br /&gt;
	Local $iVar_A2 = 20&lt;br /&gt;
&lt;br /&gt;
	; And read them&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Initial read in Func A:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var A1 = &amp;quot; &amp;amp; $iVar_A1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var A2 = &amp;quot; &amp;amp; $iVar_A2)&lt;br /&gt;
&lt;br /&gt;
	; Now pass these variables to another function - but this time we will pass $iVar_A2 By Reference&lt;br /&gt;
	Func_B($iVar_A1, $iVar_A2)&lt;br /&gt;
&lt;br /&gt;
	; We changed the parameters in Func_B - this time we see that we have changed $iVar_A2&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Second read in Func A:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var A1 = &amp;quot; &amp;amp; $iVar_A1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var A2 = &amp;quot; &amp;amp; $iVar_A2)&lt;br /&gt;
EndFunc   ;==&amp;gt;Func_A&lt;br /&gt;
&lt;br /&gt;
Func Func_B($iVar_B1, ByRef $iVar_B2) ; Note the ByRef keyword in the function declaration for the second parameter&lt;br /&gt;
	; Now read these variables - they have the same value as the variables in Func_A&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Initial read in Func B:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var B1 = &amp;quot; &amp;amp; $iVar_B1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var B2 = &amp;quot; &amp;amp; $iVar_B2)&lt;br /&gt;
&lt;br /&gt;
	; Let us change them&lt;br /&gt;
	$iVar_B1 = 100&lt;br /&gt;
	$iVar_B2 = 200&lt;br /&gt;
&lt;br /&gt;
	; And confirm that they have changed&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;Read&amp;quot;, &amp;quot;Second read in Func B:&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;Var B1 = &amp;quot; &amp;amp; $iVar_B1 &amp;amp; @CRLF &amp;amp; &amp;quot;Var B2 = &amp;quot; &amp;amp; $iVar_B2)&lt;br /&gt;
&lt;br /&gt;
	; Now return to the other function&lt;br /&gt;
EndFunc   ;==&amp;gt;Func_B&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A couple of more advanced points:&lt;br /&gt;
&lt;br /&gt;
- It was mentioned earlier that when you pass variables to functions AutoIt makes local copies of these variables unless you declare that they are to be passed &#039;&#039;ByRef&#039;&#039;.  In the special case of arrays, which are typically larger than a simple variable, AutoIt will only make a local copy if you change the array inside the function - merely accessing the array will use the original version.  So passing the array &#039;&#039;ByRef&#039;&#039; is only advantageous if you intend to modify the array within the function - however, it does no harm to force the issue by using the keyword.&lt;br /&gt;
&lt;br /&gt;
- If you are dealing with a simple variable of considerable size (the text of a file for example) then passing it &#039;&#039;ByRef&#039;&#039; is a sensible action.  But if you want to make sure that the variable cannot be altered inside the function, you can declare it as &#039;&#039;Const ByRef&#039;&#039; in the function definition as shown here:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Local $sString = &amp;quot;A very large chunk of data which we do not want to change&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Foo($sString)&lt;br /&gt;
&lt;br /&gt;
Func Foo(Const ByRef $sText) ; The data is not copied, but also cannot be changed&lt;br /&gt;
	; Uncomment this line to see what happens when we try&lt;br /&gt;
	;$sText = &amp;quot;New value&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;Foo&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;ByRef&#039;&#039; is a very powerful feature - but use it carefully, or you may find that you have changed a variable when you did not want to!&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12924</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=12924"/>
		<updated>2015-03-10T21:14:02Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Variable Initialization */&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;
A few notes:&lt;br /&gt;
* You must use the latest version of 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;
== Names of Variables ==&lt;br /&gt;
The variable naming convention used in AutoIt is based on [http://en.wikipedia.org/wiki/Hungarian_notation Apps 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;
| i || Integer || $iInteger = 10&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $fFloat = 0.123&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $nNumber = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $aArray[0]&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || $mMap[]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $sString = &amp;quot;hello world&amp;quot;&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;
| id || An AutoIt controlID || $idButton = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 5, 5)&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;
| fu || Functions || $fuMessage = MsgBox&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $pRect = DllStructGetPtr($tRECT)&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tagDATE = &amp;quot;struct; word Year;word Month;word Dow;word Day; endstruct&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $tSTRUCT = DllStructCreate($tagSTRUCT)&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $oShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $vData = ClipGet()&lt;br /&gt;
|-&lt;br /&gt;
| e || Enumerations || Enum $e1st = 1, $e2nd, $e3rd&lt;br /&gt;
|-&lt;br /&gt;
| k || Keywords || $kKeyword = Default&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 || $fu, $o, $s, $v&lt;br /&gt;
|-&lt;br /&gt;
| False (or True) || $b&lt;br /&gt;
|-&lt;br /&gt;
| Default || $k&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, 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 $idGo = GUICtrlCreateButton(&amp;quot;Go&amp;quot;, $iLeft, $iTop), $idQuit = 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;
To make the transition, the variables are also 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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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 $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $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 $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 $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;, $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 $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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 efficent 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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=UDF-spec&amp;diff=12858</id>
		<title>UDF-spec</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=UDF-spec&amp;diff=12858"/>
		<updated>2015-03-06T20:05:40Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* 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;
* Not use any magic numbers. Ever. None. At all. No excuses.&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. See [[Best_coding_practices#Names_of_Variables|Names of Variables]]&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;
* Not make any permanent changes to the users computer. For example, if demonstrating a File function, be sure to delete the file after it has been used. The same applies for any function that makes a change to the environment: the changes MUST be undone.&lt;br /&gt;
&lt;br /&gt;
Always remember, the readability of code in an example is MORE important than the readability of code inside the UDF itself.&lt;br /&gt;
&lt;br /&gt;
Examples are stored in script 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;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include &amp;lt;Constants.au3&amp;gt;&lt;br /&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($MB_SYSTEMMODAL, &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;
=== Multiple Examples ===&lt;br /&gt;
The helpfile now supports multiple examples per function. In order to maintain backwards compatibility with any other tools that use examples, the first file is still named &amp;lt;code&amp;gt;&amp;amp;lt;FUNCTION&amp;amp;gt;.au3&amp;lt;/code&amp;gt;, but any additional examples are named &amp;lt;code&amp;gt;&amp;amp;lt;FUNCTION&amp;amp;gt;[n].au3&amp;lt;/code&amp;gt; where n is an integer counter starting at 2.&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;#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&lt;br /&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.10.2&lt;br /&gt;
; Language ......: English&lt;br /&gt;
; Author(s) .....: &lt;br /&gt;
; Modifiers .....: &lt;br /&gt;
; Forum link ....: a link to the main forum topic (if aplicable)&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12857</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=12857"/>
		<updated>2015-03-06T20:04:02Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Names of Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
* You must use the latest version of 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;
== Names of Variables ==&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation] is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&amp;lt;br /&amp;gt;&lt;br /&gt;
In AutoIt the Hungarian notation strives to encode 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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Variables are initialized with the &amp;quot;default&amp;quot; value (or the most logical representation) of their type. See below in the table for specific value.&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;
| i || Integer || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $f = 0.0&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $n = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || Local $a[0]&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || Local $m[]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $b = False or $b = True &lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $d = Binary(&amp;quot;&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlid || $id = 0&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| fu || Functions || $fu = Null&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = 0&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0 or $o = Null&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $v = 0 or $v = &amp;quot;&amp;quot; (or $v = Null)&lt;br /&gt;
|-&lt;br /&gt;
| e || Enumerations || N/A&lt;br /&gt;
|-&lt;br /&gt;
| k || Keywords || $k = Default&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
;Good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
Example2:&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;
Local $vValue ; Bad, this is initially blank.&lt;br /&gt;
Local $vVal = 0 ; Good&lt;br /&gt;
&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$vValue: &#039; &amp;amp; $vValue &amp;amp; @CRLF &amp;amp; &#039;$vVal: &#039; &amp;amp; $vVal)&lt;br /&gt;
&lt;br /&gt;
; In C++ $vValue would display the previous value that was residing in the memory address $vValue points to. AutoIt&lt;br /&gt;
; is a little less forgiving in that it initialises the variable as being blank and doesn&#039;t throw any error, unlike some moder C++ compilers.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
&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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&lt;br /&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;
&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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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;
&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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;
&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;
&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 $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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 $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 $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;, $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 $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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;
&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 efficent 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;
&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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&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;
;Good&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;
&lt;br /&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;
&lt;br /&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;
&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;
&lt;br /&gt;
&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;
&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12856</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=12856"/>
		<updated>2015-03-06T20:03:20Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Names of Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
* You must use the latest version of 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;
== Names of Variables ==&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation] is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&amp;lt;br /&amp;gt;&lt;br /&gt;
In AutoIt the Hungarian notation strives to encode 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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Variables are initialized with the &amp;quot;default&amp;quot; value (or the most logical representation) of their type. See below in the table for specific value.&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;
| i || Integer || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $f = 0.0&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $n = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || Local $a[0] = &amp;quot;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || Local $m[]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $b = False or $b = True &lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $d = Binary(&amp;quot;&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlid || $id = 0&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| fu || Functions || $fu = Null&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = 0&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0 or $o = Null&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $v = 0 or $v = &amp;quot;&amp;quot; (or $v = Null)&lt;br /&gt;
|-&lt;br /&gt;
| e || Enumerations || N/A&lt;br /&gt;
|-&lt;br /&gt;
| k || Keywords || $k = Default&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
;Good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
Example2:&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;
Local $vValue ; Bad, this is initially blank.&lt;br /&gt;
Local $vVal = 0 ; Good&lt;br /&gt;
&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$vValue: &#039; &amp;amp; $vValue &amp;amp; @CRLF &amp;amp; &#039;$vVal: &#039; &amp;amp; $vVal)&lt;br /&gt;
&lt;br /&gt;
; In C++ $vValue would display the previous value that was residing in the memory address $vValue points to. AutoIt&lt;br /&gt;
; is a little less forgiving in that it initialises the variable as being blank and doesn&#039;t throw any error, unlike some moder C++ compilers.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
&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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&lt;br /&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;
&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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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;
&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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;
&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;
&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 $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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 $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 $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;, $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 $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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;
&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 efficent 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;
&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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&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;
;Good&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;
&lt;br /&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;
&lt;br /&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;
&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;
&lt;br /&gt;
&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;
&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12855</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=12855"/>
		<updated>2015-03-06T19:59:46Z</updated>

		<summary type="html">&lt;p&gt;Guinness: Fixed comment&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
* You must use the latest version of 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;
== Names of Variables ==&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation] is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&amp;lt;br /&amp;gt;&lt;br /&gt;
In AutoIt the Hungarian notation strives to encode 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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Variables are initialized with the &amp;quot;default&amp;quot; value (or the most logical representation) of their type. See below in the table for specific value.&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;
| i || Integer || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $f = 0.0&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $n = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || Dim $a[1] and $a[0] = &amp;quot;Value&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| m || Maps || Dim $m[] and $m[&amp;quot;key&amp;quot;] = &amp;quot;Value&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot; or $s = Null&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $b = False or $b = True &lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $d = Binary(&amp;quot;&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlid || $id = 0&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| fu || Functions || $fu = Null&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = 0&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0 or $o = Null&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $v = 0 or $v = &amp;quot;&amp;quot; (or $v = Null)&lt;br /&gt;
|-&lt;br /&gt;
| e || Enumerations || N/A&lt;br /&gt;
|-&lt;br /&gt;
| k || Keywords || $k = Default&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
;Good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
Example2:&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;
Local $vValue ; Bad, this is initially blank.&lt;br /&gt;
Local $vVal = 0 ; Good&lt;br /&gt;
&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$vValue: &#039; &amp;amp; $vValue &amp;amp; @CRLF &amp;amp; &#039;$vVal: &#039; &amp;amp; $vVal)&lt;br /&gt;
&lt;br /&gt;
; In C++ $vValue would display the previous value that was residing in the memory address $vValue points to. AutoIt&lt;br /&gt;
; is a little less forgiving in that it initialises the variable as being blank and doesn&#039;t throw any error, unlike some moder C++ compilers.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
&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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&lt;br /&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;
&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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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;
&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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;
&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;
&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 $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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 $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 $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;, $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 $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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;
&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 efficent 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;
&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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&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;
;Good&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;
&lt;br /&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;
&lt;br /&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;
&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;
&lt;br /&gt;
&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;
&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_AutoIt_)&amp;diff=12761</id>
		<title>Snippets ( AutoIt )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_AutoIt_)&amp;diff=12761"/>
		<updated>2015-01-16T21:42:59Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* _IsInTrial */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
[[category:Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Snippet Credit Header}}&lt;br /&gt;
&lt;br /&gt;
== AutoItWinShow ==&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;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Display AutoIt&#039;s Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.&lt;br /&gt;
    AutoItWinShow()&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Display AutoIt&#039;s Hidden Window. Returns the handle of the window.&lt;br /&gt;
Func AutoItWinShow()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    WinMove($hWnd, &#039;&#039;, (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.&lt;br /&gt;
    WinSetState($hWnd, &#039;&#039;, @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I&#039;m displaying it.&lt;br /&gt;
    Return $hWnd&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinShow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== AutoItWinGetText ==&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;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Display AutoIt&#039;s Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.&lt;br /&gt;
    AutoItWinShow()&lt;br /&gt;
&lt;br /&gt;
    ; Add a text string to AutoIt&#039;s Hidden Window. Compile to see the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    AutoItWinSetText(&#039;Welcome to AutoIt V&#039; &amp;amp; @AutoItVersion &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Add a text string to AutoIt&#039;s Hidden Window. Compile to see the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    AutoItWinSetText(&#039;Windows Type: &#039; &amp;amp; @OSType &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Display the text stored in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, AutoItWinGetText())&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Retrieve the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
Func AutoItWinGetText()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    Return ControlGetText($hWnd, &#039;&#039;, ControlGetHandle($hWnd, &#039;&#039;, &#039;Edit1&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinGetText&lt;br /&gt;
&lt;br /&gt;
; Add text to AutoIt&#039;s Hidden Window.&lt;br /&gt;
Func AutoItWinSetText($sString)&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    Return ControlSetText($hWnd, &amp;quot;&amp;quot;, ControlGetHandle($hWnd, &amp;quot;&amp;quot;, &#039;Edit1&#039;), ControlGetText($hWnd, &#039;&#039;, ControlGetHandle($hWnd, &#039;&#039;, &#039;Edit1&#039;)) &amp;amp; $sString)&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinSetText&lt;br /&gt;
&lt;br /&gt;
; Display AutoIt&#039;s Hidden Window. Returns the handle of the window.&lt;br /&gt;
Func AutoItWinShow()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    WinMove($hWnd, &#039;&#039;, (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.&lt;br /&gt;
    WinSetState($hWnd, &#039;&#039;, @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I&#039;m displaying it.&lt;br /&gt;
    Return $hWnd&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinShow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _DockToWindow ==&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;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If (Not ProcessExists(&amp;quot;SciTE.exe&amp;quot;)) Then&lt;br /&gt;
    Exit MsgBox(4096, &#039;&#039;, &amp;quot;Please start SciTE.exe&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Create a GUI, similar to SciTE Jump&#039;s GUI.&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;, 215, 400, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    ; Dock the first window to left and adjust the width based on the width of the second GUI.&lt;br /&gt;
    _DockToWindow(WinGetHandle(&amp;quot;[CLASS:SciTEWindow]&amp;quot;), $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&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;
&lt;br /&gt;
Func _DockToWindow(Const $hHandle_1, Const $hHandle_2)&lt;br /&gt;
    ; Retrieve the working area, this is minus the taskbar dimensions so slightly different to @DesktopHeight and @DesktopWidth which is the&lt;br /&gt;
    ; monitors height and width.&lt;br /&gt;
    Local Const $SPI_GETWORKAREA = 48&lt;br /&gt;
    Local Const $tWorkArea = DllStructCreate($tagRECT)&lt;br /&gt;
    _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($tWorkArea))&lt;br /&gt;
&lt;br /&gt;
    ; Retieve the position of the second GUI.&lt;br /&gt;
    Local Const $aClientSize_2 = WinGetPos($hHandle_2)&lt;br /&gt;
&lt;br /&gt;
    ; Set the state of the windows to &#039;Restore&#039;.&lt;br /&gt;
    WinSetState($hHandle_1, &#039;&#039;, @SW_RESTORE)&lt;br /&gt;
    WinSetState($hHandle_2, &#039;&#039;, @SW_RESTORE)&lt;br /&gt;
&lt;br /&gt;
    ; Move the first to the far left of the screen and adjust the width to the total screen width minus the width of the second GUI. e.g. 1366 - 215&lt;br /&gt;
    WinMove($hHandle_1, &#039;&#039;, DllStructGetData($tWorkArea, &#039;Left&#039;), DllStructGetData($tWorkArea, &#039;Top&#039;), DllStructGetData($tWorkArea, &#039;Right&#039;) - DllStructGetData($tWorkArea, &#039;Left&#039;) - $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Bottom&#039;) - DllStructGetData($tWorkArea, &#039;Top&#039;))&lt;br /&gt;
&lt;br /&gt;
    ; Move the second window to the far right in between the remaining space and adjust the height of the GUI.&lt;br /&gt;
    WinMove($hHandle_2, &#039;&#039;, DllStructGetData($tWorkArea, &#039;Right&#039;) - DllStructGetData($tWorkArea, &#039;Left&#039;) - $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Top&#039;), $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Bottom&#039;) - DllStructGetData($tWorkArea, &#039;Top&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;_DockToWindow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FuncExists ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 52-geosoft&lt;br /&gt;
| AuthorName = GEOSoft&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox(0, &amp;quot;TEST&amp;quot;, &amp;quot;Function Exists = &amp;quot; &amp;amp; _FuncExists(&amp;quot;_FuncExists&amp;quot;, @ScriptFullPath))&lt;br /&gt;
&lt;br /&gt;
Func _FuncExists($sFunc, $sPath)&lt;br /&gt;
   If Not FileExists($sPath) Then Return SetError(1)&lt;br /&gt;
   Local Const $sStr = FileRead($sPath)&lt;br /&gt;
   Local Const $sRegEx = &amp;quot;(?i)(?m:^|\n)\s*Func\s+(&amp;quot; &amp;amp; $sFunc &amp;amp; &amp;quot;)\s*\(&amp;quot;&lt;br /&gt;
   Local Const $aRegEx = StringRegExp($sStr, $sRegEx, 1)&lt;br /&gt;
   If IsArray($aRegEx) Then Return 1&lt;br /&gt;
   Return 0&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FunctionSort ==&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;
; Get the list of Functions in a script and sort by alphabetical order.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;String.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local $sFile = FileOpenDialog(@ScriptName, &amp;quot;Select an AutoIt file.&amp;quot;, &amp;quot;Au3 (*.au3)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    Exit&lt;br /&gt;
EndIf&lt;br /&gt;
ClipPut(_FunctionSort($sFile))&lt;br /&gt;
&lt;br /&gt;
Func _FunctionSort($sFilePath)&lt;br /&gt;
    Local Const $sRead = FileRead($sFilePath)&lt;br /&gt;
&lt;br /&gt;
	Local $aReturn = StringRegExp(&amp;quot;Func _Count()&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;EndFunc ;==&amp;gt;_Count&amp;quot; &amp;amp; $sRead, &#039;(?s)(?i)Func(.*?)EndFunc&#039;, 3)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    $aReturn[0] = UBound($aReturn, 1) - 1&lt;br /&gt;
&lt;br /&gt;
    _ArraySort($aReturn, 0, 1)&lt;br /&gt;
&lt;br /&gt;
    Local $sReturn&lt;br /&gt;
&lt;br /&gt;
    For $A = 1 To $aReturn[0]&lt;br /&gt;
        $sReturn &amp;amp;= &amp;quot;Func&amp;quot; &amp;amp; $aReturn[$A] &amp;amp; &amp;quot;EndFunc&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    Return $sReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_FunctionSort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsBeta ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 10673-mlipok&lt;br /&gt;
| AuthorName = mLipok&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;
#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;
    Local $aTest[10]&lt;br /&gt;
    _ArrayUnique($aTest, 0, 5)&lt;br /&gt;
    Local $iError = @error&lt;br /&gt;
    ConsoleWrite(&#039;$iError = &#039; &amp;amp; $iError &amp;amp; @CRLF)&lt;br /&gt;
    If _IsBeta() Then&lt;br /&gt;
        If $iError = 3 Then&lt;br /&gt;
            MsgBox($MB_SYSTEMMODAL, &#039;@error&#039;, &#039;3 - $iBase or $iCase contains an invalid value&#039; &amp;amp; @CRLF &amp;amp; @AutoItVersion)&lt;br /&gt;
        EndIf&lt;br /&gt;
    Else&lt;br /&gt;
        If $iError = 2 Then&lt;br /&gt;
            MsgBox($MB_SYSTEMMODAL, &#039;@error&#039;, &#039;2 - $iBase or $iCase contains an invalid value&#039; &amp;amp; @CRLF &amp;amp; @AutoItVersion)&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _IsBeta()&lt;br /&gt;
       Return Mod(StringSplit(@AutoItVersion, &#039;.&#039;)[3], 2) == 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsBeta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsButton ==&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;ButtonConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;Constants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    Local Const $iLabel = GUICtrlCreateButton(&#039;&#039;, 0, 0, 50, 50)&lt;br /&gt;
    Local Const $iCheckbox = GUICtrlCreateCheckbox(&#039;&#039;, 0, 0, 100, 20) ; This is considered a &#039;Button&#039; by _WinAPI_GetClassName too.&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;AutoIt Button ID: &#039; &amp;amp; _IsButton($iLabel) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Button Handle: &#039; &amp;amp; _IsButton(GUICtrlGetHandle($iLabel)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Checkbox ID: &#039; &amp;amp; _IsButton($iCheckbox) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Checkbox Handle: &#039; &amp;amp; _IsButton(GUICtrlGetHandle($iCheckbox)) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    Return GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Check if a variable is referencing a Button control.&lt;br /&gt;
Func _IsButton($hWnd)&lt;br /&gt;
    If IsHWnd($hWnd) = 0 Then&lt;br /&gt;
        $hWnd = GUICtrlGetHandle($hWnd)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Local Const $sClassName = _WinAPI_GetClassName($hWnd)&lt;br /&gt;
&lt;br /&gt;
    If $sClassName = &#039;Button&#039; Then&lt;br /&gt;
        Local Const $aStyle[5] = [4, $BS_CHECKBOX, $BS_AUTOCHECKBOX, $BS_RADIOBUTTON, $BS_AUTORADIOBUTTON]&lt;br /&gt;
&lt;br /&gt;
        Local Const $iLong = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)&lt;br /&gt;
&lt;br /&gt;
		For $i = 1 To $aStyle[0]&lt;br /&gt;
            If BitAND($iLong, $aStyle[$i]) = $aStyle[$i] Then&lt;br /&gt;
                Return False&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
&lt;br /&gt;
        Return True&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return False&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsButton&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsControlID ==&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 if a Control ID is a native AutoIt control.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;GUIListView.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    Local Const $iControlID = GUICtrlCreateLabel(&#039;&#039;, 0, 0, 500, 500)&lt;br /&gt;
    Local Const $hListView = _GUICtrlListView_Create($hGUI, &#039;Example&#039;, 0, 0, 500, 500)&lt;br /&gt;
&lt;br /&gt;
	GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;AutoIt ControlID: &#039; &amp;amp; _IsControlID($iControlID) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;Random Number: &#039; &amp;amp; _IsControlID(Random(42, 99, 1)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt ControlID Handle: &#039; &amp;amp; _IsControlID(GUICtrlGetHandle($iControlID)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;ListView UDF Handle: &#039; &amp;amp; _IsControlID($hListView) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;ListView UDF Handle: &#039; &amp;amp; _IsControlID(GUICtrlGetHandle($hListView)) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    _GUICtrlListView_Destroy($hListView)&lt;br /&gt;
&lt;br /&gt;
    Return GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _IsControlID($iControlID)&lt;br /&gt;
    If IsHWnd($iControlID) Then&lt;br /&gt;
        $iControlID = _WinAPI_GetDlgCtrlID($iControlID)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return IsHWnd(GUICtrlGetHandle($iControlID)) = 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsControlID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItIncludesFromSciTE ==&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;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetAutoItIncludesFromSciTE() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Retrieve the AutoIt includes path from the SciTE process.&lt;br /&gt;
Func _GetAutoItIncludesFromSciTE()&lt;br /&gt;
    Local $sRelativePath = &#039;..\Include&#039;&lt;br /&gt;
	Local Const $sWorkingDir = @WorkingDir&lt;br /&gt;
    FileChangeDir(_WinAPI_PathRemoveFileSpec(_WinAPI_GetProcessFileName(ProcessExists(&#039;SciTE.exe&#039;))))&lt;br /&gt;
    $sRelativePath = _WinAPI_GetFullPathName($sRelativePath)&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return _WinAPI_PathRemoveBackslash($sRelativePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItIncludesFromSciTE&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstall ==&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;
; Get the AutoIt installation folder.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetAutoItInstall() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetAutoItInstall()&lt;br /&gt;
    Return StringLeft(@AutoItExe, StringInStr(@AutoItExe, &amp;quot;\&amp;quot;, 2, -1) - 1)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstall&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstallEx ==&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(_GetAutoItInstallEx() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the installation of AutoIt. An improved version of _GetAutoItInstall.&lt;br /&gt;
Func _GetAutoItInstallEx()&lt;br /&gt;
    Local $aWow6432Node[2] = [&#039;&#039;, &#039;Wow6432Node\&#039;], $aFiles[4] = [3, @ProgramFilesDir, EnvGet(&amp;quot;PROGRAMFILES&amp;quot;), EnvGet(&amp;quot;PROGRAMFILES(X86)&amp;quot;)]&lt;br /&gt;
    Local $sFilePath = RegRead(&#039;HKEY_LOCAL_MACHINE\SOFTWARE\&#039; &amp;amp; $aWow6432Node[@AutoItX64] &amp;amp; &#039;AutoIt v3\AutoIt\&#039;, &#039;InstallDir&#039;)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        For $A = 1 To $aFiles[0]&lt;br /&gt;
            $aFiles[$A] &amp;amp;= &#039;\AutoIt&#039;&lt;br /&gt;
            If FileExists($aFiles[$A]) Then&lt;br /&gt;
                Return $aFiles[$A]&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
        Return SetError(1, 0, &#039;&#039;)&lt;br /&gt;
    Else&lt;br /&gt;
        Return $sFilePath&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstallEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstallFromSciTE ==&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(_GetAutoItInstallFromSciTE() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Retrieve the AutoIt installation path from the SciTE process.&lt;br /&gt;
Func _GetAutoItInstallFromSciTE()&lt;br /&gt;
    Local $sRelativePath = &#039;..\&#039;, $sWorkingDir = @WorkingDir&lt;br /&gt;
    FileChangeDir( _WinAPI_PathRemoveFileSpec(_WinAPI_GetProcessFileName(ProcessExists(&amp;quot;SciTE.exe&amp;quot;))))&lt;br /&gt;
    $sRelativePath = _WinAPI_GetFullPathName($sRelativePath)&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return _WinAPI_PathRemoveBackslash($sRelativePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstallFromSciTE&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetClasses ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 24-cyberslug&lt;br /&gt;
| AuthorName = CyberSlug&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Get ALL Controls Info&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
	; Run Calculator&lt;br /&gt;
	Run(&amp;quot;calc.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	; Wait 10 seconds for the Calculator window to appear.&lt;br /&gt;
	Local const $hWnd = WinWait(&amp;quot;[CLASS:CalcFrame]&amp;quot;, &#039;&#039;, 10)&lt;br /&gt;
&lt;br /&gt;
	; Retrieve a list of all the controls in the Calculator window using the handle returned by WinWait.&lt;br /&gt;
	MsgBox(4096, &#039;&#039;, _GetClasses($hWnd))&lt;br /&gt;
&lt;br /&gt;
	; Close the Calculator window using the handle returned by WinWait.&lt;br /&gt;
	WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; This function returns an @LF-separated list of controls on the specified window.&lt;br /&gt;
Func _GetClasses($sTitle, $sText = &#039;&#039;)&lt;br /&gt;
	Local $iCount_Button = 0, $iCount_Edit = 0, $iCount_Static = 0&lt;br /&gt;
	Local $aClasses = StringSplit(WinGetClassList($sTitle, $sText), @LF)&lt;br /&gt;
	Local $aClassID[$aClasses[0] + 1] = [$aClasses[0]]&lt;br /&gt;
&lt;br /&gt;
	For $i = 1 To $aClasses[0]&lt;br /&gt;
		Select&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Button&amp;quot;&lt;br /&gt;
				$iCount_Button += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Button&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Edit&amp;quot;&lt;br /&gt;
				$iCount_Edit += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Edit&lt;br /&gt;
				$aClasses[$i] = &amp;quot;Input&amp;quot;&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Static&amp;quot;&lt;br /&gt;
				$iCount_Static += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Static&lt;br /&gt;
				$aClasses[$i] = &amp;quot;Label&amp;quot;&lt;br /&gt;
			Case Else&lt;br /&gt;
				If $aClasses[$i] &amp;lt;&amp;gt; &amp;quot;&amp;quot; Then&lt;br /&gt;
					$aClassID[$i] = $aClasses[$i] &amp;amp; &amp;quot;?&amp;quot;&lt;br /&gt;
				EndIf&lt;br /&gt;
		EndSelect&lt;br /&gt;
	Next&lt;br /&gt;
&lt;br /&gt;
	; Combine the results.&lt;br /&gt;
	Local $sReturn = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	For $i = 1 To $aClassID[0]&lt;br /&gt;
		$sReturn &amp;amp;= $aClassID[$i] &amp;amp; @LF&lt;br /&gt;
	Next&lt;br /&gt;
&lt;br /&gt;
	Return $sReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetClasses&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFile ==&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;
; FileRead Alternative&lt;br /&gt;
&lt;br /&gt;
Func _GetFile($sFile, $iFormat = 0)&lt;br /&gt;
    Local $hFileOpen = FileOpen($sFile, $iFormat)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(1, 0, &amp;quot;&amp;quot;)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $sData = FileRead($hFileOpen)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
    Return $sData&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetTitle ==&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;
; Get the title of your program.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetTitle(&#039;Example&#039;) &amp;amp; @CRLF)&lt;br /&gt;
; The second parameter would normally be @ScriptDir &amp;amp; &#039;\Uninstall.exe&#039; for example, but for this demonstration I&#039;m using the full path.&lt;br /&gt;
ConsoleWrite(_GetTitle(&#039;Example&#039;, @ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetTitle($sProgramName, $sInstallPath = &#039;&#039;)&lt;br /&gt;
    Local $aOSArch[2] = [&#039;&#039;, &#039; (64-bit)&#039;], $aPortable[2] = [&#039; (Portable)&#039;, &#039;&#039;]&lt;br /&gt;
    Return $sProgramName &amp;amp; $aOSArch[@AutoItX64] &amp;amp; $aPortable[FileExists($sInstallPath)]&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetTitle&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetXML ==&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;
; Simple Way Of Parsing XML Data.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $aReturn, $sXMLData&lt;br /&gt;
&lt;br /&gt;
$sXMLData = &amp;quot;&amp;lt;data&amp;gt;This is a Simple example of XML&amp;lt;/data&amp;gt;&amp;lt;data&amp;gt;This is a Simple example of XML and is the Second String.&amp;lt;/data&amp;gt;&amp;quot;&lt;br /&gt;
$aReturn = _GetXML($sXMLData, &amp;quot;data&amp;quot;)&lt;br /&gt;
_ArrayDisplay($aReturn, &amp;quot;_GetXML()&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _GetXML($sString, $sData)&lt;br /&gt;
    Local $aError[2] = [1, $sString], $aReturn&lt;br /&gt;
    $aReturn = StringRegExp(&#039;&amp;lt;&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&amp;lt;/&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&#039; &amp;amp; $sString, &#039;(?s)(?i)&amp;lt;&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;(.*?)&amp;lt;/&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&#039;, 3)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $aError)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aReturn[0] = UBound($aReturn, 1) - 1&lt;br /&gt;
    Return SetError(0, 0, $aReturn)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetXML&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Include Source With Exe ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 54985-jlogan3o13&lt;br /&gt;
| AuthorName = JLogan3o13&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;recover source .au3 file with /Extract switch&lt;br /&gt;
; The above code would be copied into the top of your script. The source location (C:\Test.au3 in my example) is the full path to your script file.&lt;br /&gt;
;Once compiled, if you run the script from the Run line with the /Extract switch, it will extact the original .au3 file into the Temp directory and will exit without actually executing the script.&lt;br /&gt;
If StringInStr($cmdlineRaw, &amp;quot;/Extract&amp;quot;) Then&lt;br /&gt;
	FileInstall(&amp;quot;C:\Test.au3&amp;quot;, @TempDir &amp;amp; &amp;quot;\Test.au3&amp;quot;, 1)&lt;br /&gt;
	Exit&lt;br /&gt;
EndIf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsANSIFile ==&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;FileConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_IsANSIFile(@ScriptFullPath) &amp;amp; @LF) ; Returns True.&lt;br /&gt;
&lt;br /&gt;
Func _IsANSIFile($sFilePath)&lt;br /&gt;
    Return FileGetEncoding($sFilePath) = $FO_READ&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsUnicodeFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsUnicodeFile ==&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;FileConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_IsUnicodeFile(@ScriptFullPath) &amp;amp; @LF) ; Returns False.&lt;br /&gt;
&lt;br /&gt;
Func _IsUnicodeFile($sFilePath)&lt;br /&gt;
    Return FileGetEncoding($sFilePath) = $FO_UNICODE&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsUnicodeFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsAu3File ==&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(_IsAu3File(@AutoItExe) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_IsAu3File(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Checks whether the filepath is an au3 file.&lt;br /&gt;
Func _IsAu3File($sFilePath)&lt;br /&gt;
    Return StringTrimLeft($sFilePath, StringInStr($sFilePath, &amp;quot;.&amp;quot;, 2, -1)) = &amp;quot;au3&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsAu3File&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsDefault ==&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;
If _IsDefault(Default) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 1&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
If _IsDefault(-1) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 2&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
If _IsDefault(&amp;quot;Other&amp;quot;) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 3&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
Func _IsDefault($sDefault)&lt;br /&gt;
    Return StringRegExp($sDefault, &amp;quot;(?-i)\s|Default|-1|0&amp;quot;)&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsDefault&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsInTrial ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 4813-smoke-n&lt;br /&gt;
| AuthorName = SmOke_N&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;Date.au3&amp;gt; ; Required for _DateDiff()&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;Date trial started: &#039; &amp;amp; @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/01&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Today&#039;&#039;s date: &#039; &amp;amp; @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/&#039; &amp;amp; @MDAY &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Trial period: 30 days&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Is the trial period still valid: &#039; &amp;amp; _IsInTrial(@YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/01&#039;, 30) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a trial period date is still valid.&lt;br /&gt;
Func _IsInTrial($sDateString, $iDays)&lt;br /&gt;
    Return (_DateDiff(&#039;D&#039;, $sDateString, _NowCalcDate()) &amp;lt; $iDays)&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsInTrial&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsVisible ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = &lt;br /&gt;
| AuthorName = Multiple&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Check if the Notepad Window is visible.&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Run Notepad&lt;br /&gt;
    Run(&amp;quot;notepad.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    ; Wait 10 seconds for the Notepad window to appear.&lt;br /&gt;
    Local $hWnd = WinWait(&amp;quot;[CLASS:Notepad]&amp;quot;, &amp;quot;&amp;quot;, 10)&lt;br /&gt;
&lt;br /&gt;
    ; Check if the Notepad window is visible and display the appropriate message box.&lt;br /&gt;
    If _IsVisible($hWnd) Then&lt;br /&gt;
        MsgBox(4096, &amp;quot;&amp;quot;, &amp;quot;Notepad is visible.&amp;quot;)&lt;br /&gt;
    Else&lt;br /&gt;
        MsgBox(4096, &amp;quot;&amp;quot;, &amp;quot;Notepad isn&#039;t visible.&amp;quot;)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    ; Close the Notepad window using the handle returned by WinWait.&lt;br /&gt;
    WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Check if the window is visible.&lt;br /&gt;
Func _IsVisible($hWnd)&lt;br /&gt;
    Return BitAND(WinGetState($hWnd), 2) = 2&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsVisible&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Open Help File to Desired Page ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 1967-garyfrost&lt;br /&gt;
| AuthorName = GaryFrost&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Open help file / Open a desired page&lt;br /&gt;
&lt;br /&gt;
Global Const $sAutoItPath = RegRead(&amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt&amp;quot;, &amp;quot;InstallDir&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Run(@WindowsDir &amp;amp; &amp;quot;\hh.exe &amp;quot; &amp;amp; $sAutoItPath &amp;amp; &amp;quot;\AutoIt3.chm::/html/functions/GUICtrlCreateUpdown.htm&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _RunAU3 ==&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;
_RunAU3(&amp;quot;AU3_Example.txt&amp;quot;, &#039;&amp;quot;This is a commandline example!&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
Func _RunAU3($sFilePath,  $sCommandLine = &amp;quot;&amp;quot;, $sWorkingDir = &amp;quot;&amp;quot;, $iShowFlag = @SW_SHOW, $iOptFlag = 0)&lt;br /&gt;
    Return Run(&#039;&amp;quot;&#039; &amp;amp; @AutoItExe &amp;amp; &#039;&amp;quot; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; $sCommandLine, $sWorkingDir, $iShowFlag, $iOptFlag)&lt;br /&gt;
EndFunc   ;==&amp;gt;_RunAU3&lt;br /&gt;
&lt;br /&gt;
Func _RunWaitAU3($sFilePath, $sCommandLine = &amp;quot;&amp;quot;, $sWorkingDir = &amp;quot;&amp;quot;, $iShowFlag = @SW_SHOW, $iOptFlag = 0)&lt;br /&gt;
    Local $iPID&lt;br /&gt;
    $iPID = RunWait(&#039;&amp;quot;&#039; &amp;amp; @AutoItExe &amp;amp; &#039;&amp;quot; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; $sCommandLine, $sWorkingDir, $iShowFlag, $iOptFlag)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(@error, 1, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $iPID&lt;br /&gt;
EndFunc   ;==&amp;gt;_RunWaitAU3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Run Any au3 File From Your Program ==&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;
; Run Any Au3 File From Your Program&lt;br /&gt;
&lt;br /&gt;
Global Const $sFilePath = @ScriptDir &amp;amp; &amp;quot;\Test.au3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If @Compiled Then&lt;br /&gt;
	Global Const $sFileExe = FileGetShortName(@AutoItExe &amp;amp; &#039; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot;&#039;)&lt;br /&gt;
	Run($sFileExe)&lt;br /&gt;
Else&lt;br /&gt;
	Global Const $sFileAu3 = FileGetShortName($sFilePath)&lt;br /&gt;
	Run(@AutoItExe &amp;amp; &amp;quot; &amp;quot; &amp;amp; $sFileAu3, &amp;quot;&amp;quot;, @SW_HIDE)&lt;br /&gt;
EndIf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ScriptName ==&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(_ScriptName() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Return the @ScriptName minus the .exe or .au3 extension.&lt;br /&gt;
Func _ScriptName()&lt;br /&gt;
	Return StringLeft(@ScriptName, StringInStr(@ScriptName, &#039;.&#039;, 2, -1) - 1)&lt;br /&gt;
EndFunc   ;==&amp;gt;_ScriptName&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ScriptVersion ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 31149-milesahead&lt;br /&gt;
| AuthorName = MilesAhead&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#NoTrayIcon&lt;br /&gt;
&lt;br /&gt;
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****&lt;br /&gt;
#AutoIt3Wrapper_UseUpx=n&lt;br /&gt;
#AutoIt3Wrapper_Res_Fileversion=1.2.3.4&lt;br /&gt;
#AutoIt3Wrapper_Res_LegalCopyright=2012  www.favessoft.com&lt;br /&gt;
#AutoIt3Wrapper_Res_Language=1033&lt;br /&gt;
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&lt;br /&gt;
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****&lt;br /&gt;
&lt;br /&gt;
Global $version = _ScriptVersion()&lt;br /&gt;
&lt;br /&gt;
Global $msg = &amp;quot;ScriptVerDemo&amp;quot; &amp;amp; &amp;quot; &amp;quot; &amp;amp; $version &amp;amp; &amp;quot;  Copyright (c) 2012  www.favessoft.com&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF&lt;br /&gt;
&lt;br /&gt;
MsgBox(0x1040, &amp;quot;&amp;quot;, $msg)&lt;br /&gt;
&lt;br /&gt;
; return File Version string from compiled or .au3 script&lt;br /&gt;
; returns &amp;quot;&amp;quot; if no version info available&lt;br /&gt;
; Note: The .au3 script must contain #AutoItWrapper&lt;br /&gt;
; directives with file version or &amp;quot;&amp;quot; is returned.&lt;br /&gt;
Func _ScriptVersion(Const $Script = @ScriptFullPath)&lt;br /&gt;
    If StringRight($Script,4) = &amp;quot;.exe&amp;quot; Then&lt;br /&gt;
        Return FileGetVersion($Script)&lt;br /&gt;
    Else&lt;br /&gt;
        Local Const $scriptHandle = FileOpen($Script)&lt;br /&gt;
		Local $ver&lt;br /&gt;
		Local $found = False&lt;br /&gt;
		Local $pos&lt;br /&gt;
&lt;br /&gt;
        If $scriptHandle &amp;lt;&amp;gt; -1 Then&lt;br /&gt;
            Do&lt;br /&gt;
                $ver = FileReadLine($scriptHandle)&lt;br /&gt;
                $sPos = StringInStr($ver, &amp;quot;_Fileversion=&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
                If $sPos Then&lt;br /&gt;
                    $ver = StringMid($ver, $sPos + StringLen(&amp;quot;_Fileversion=&amp;quot;))&lt;br /&gt;
                    $found = True&lt;br /&gt;
                    ExitLoop&lt;br /&gt;
                EndIf&lt;br /&gt;
            Until StringLeft($ver, 1) &amp;lt;&amp;gt; &amp;quot;#&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            FileClose($scriptHandle)&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    If Not $found Then $ver = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    Return $ver&lt;br /&gt;
EndFunc   ;==&amp;gt;_ScriptVersion&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SetFile ==&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;
; FileWrite Alternative&lt;br /&gt;
&lt;br /&gt;
Func _SetFile(Const $sString, Const $sFile, Const $iOverwrite = 0)&lt;br /&gt;
    Local Const $hFileOpen = FileOpen($sFile, $iOverwrite + 1)&lt;br /&gt;
&lt;br /&gt;
    FileWrite($hFileOpen, $sString)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $sString)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return $sString&lt;br /&gt;
EndFunc   ;==&amp;gt;_SetFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ShowHelp ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 60350-chimaera&lt;br /&gt;
| AuthorName = Chimaera&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
HotKeySet(&amp;quot;{F1}&amp;quot;, &amp;quot;_ShowHelp&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _ShowHelp()&lt;br /&gt;
	Return ShellExecute(@ProgramFilesDir &amp;amp; &amp;quot;\AutoIt3\AutoIt3Help.exe&amp;quot;) ; change this to the location of your own helpfile.&lt;br /&gt;
EndFunc   ;==&amp;gt;_ShowHelp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SingletonPID ==&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;
Local $iSingleton = _SingletonPID(&#039;RandomName&#039;, 1)&lt;br /&gt;
&lt;br /&gt;
If $iSingleton = 0 Then&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;This is the first instance of the program running: &#039; &amp;amp; $iSingleton)&lt;br /&gt;
Else&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;There is another instance running. This PID is: &#039; &amp;amp; $iSingleton)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name ..........: _SingletonPID&lt;br /&gt;
; Description ...: Enforce a design paradigm where only one instance of the script may be running.&lt;br /&gt;
; Syntax ........: _SingletonPID($sOccurenceName[, $iFlag = 0])&lt;br /&gt;
; Parameters ....: $sOccurenceName      - String to identify the occurrence of the script.&lt;br /&gt;
;                  $iFlag               - [optional] Optional parameters. Default is 0.&lt;br /&gt;
;                  0 - Exit the script with the exit code -1 if another instance already exists.&lt;br /&gt;
;                  1 - Return the PID of the main executable and without exiting the script too.&lt;br /&gt;
; Return values .: Success - 0 No other process is running.&lt;br /&gt;
;                  Failure - The PID of the main executable.&lt;br /&gt;
; Author ........: guinness with initial ideas by Valik for _Singleton &amp;amp; KaFu for _EnforceSingleInstance.&lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _SingletonPID(Const $sOccurenceName, Const $iFlag = 0)&lt;br /&gt;
    Local $hHandle = WinGetHandle($sOccurenceName)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        AutoItWinSetTitle($sOccurenceName)&lt;br /&gt;
        $hHandle = WinGetHandle($sOccurenceName)&lt;br /&gt;
        ControlSetText($hHandle, &#039;&#039;, ControlGetHandle($hHandle, &#039;&#039;, &#039;Edit1&#039;), @AutoItPID)&lt;br /&gt;
    Else&lt;br /&gt;
        If BitAND($iFlag, 1) Then&lt;br /&gt;
            Return Number(ControlGetText($hHandle, &#039;&#039;, ControlGetHandle($hHandle, &#039;&#039;, &#039;Edit1&#039;)))&lt;br /&gt;
        Else&lt;br /&gt;
            Exit -1&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_SingletonPID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _Sort ==&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(_Sort(&amp;quot;$sVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$iVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$tVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$pVariable&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
Func _Sort(Const $sSortList)&lt;br /&gt;
    Local Const $iPID = Run(&amp;quot;sort.exe&amp;quot;, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD), $sOutput = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    StdinWrite($iPID, $sSortList)&lt;br /&gt;
    StdinWrite($iPID)&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;_Sort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Speak Object and Save to WAV File ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 52278-solidsnake26&lt;br /&gt;
| AuthorName = SolidSnake26&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Speak Object and save to wav file&lt;br /&gt;
&lt;br /&gt;
_SpeakToWAV(&amp;quot;AutoIt Snippets&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\SavedFile.wav&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _SpeakToWAV(Const $sText, Const $sFilePath)&lt;br /&gt;
	Local $ObjVoice = ObjCreate(&amp;quot;Sapi.SpVoice&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	Local $ObjFile = ObjCreate(&amp;quot;Sapi.SpFileStream.1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	$ObjVoice.Speak($sText)&lt;br /&gt;
&lt;br /&gt;
	$ObjFile.Open($sFilePath, 3)&lt;br /&gt;
&lt;br /&gt;
	$ObjVoice.AudioOutputStream = $ObjFile&lt;br /&gt;
EndFunc   ;==&amp;gt;_SpeakToWAV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _VariableSwap ==&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;
Global $sString_1 = &#039;This is string 1.&#039;&lt;br /&gt;
Global $sString_2 = &#039;This is string 2.&#039;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;$sString_1: &#039; &amp;amp; $sString_1 &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(&#039;$sString_2: &#039; &amp;amp; $sString_2 &amp;amp; @CRLF &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
_VariableSwap($sString_1, $sString_2)&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;$sString_1: &#039; &amp;amp; $sString_1 &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(&#039;$sString_2: &#039; &amp;amp; $sString_2 &amp;amp; @CRLF &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Swap the contents of two variables.&lt;br /&gt;
Func _VariableSwap(ByRef $vVariable_1, ByRef $vVariable_2) ; Similar to _ArraySwap though not obvious to some this isn&#039;t limited to arrays.&lt;br /&gt;
    Local Const $vTemp = $vVariable_1&lt;br /&gt;
    $vVariable_1 = $vVariable_2&lt;br /&gt;
    $vVariable_2 = $vTemp&lt;br /&gt;
EndFunc   ;==&amp;gt;_VariableSwap&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_CharLower ==&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(_WinAPI_CharLower(&amp;quot;EXAMPLE&amp;quot;) &amp;amp; @CRLF) ; Similar to StringLower.&lt;br /&gt;
&lt;br /&gt;
; Convert characters to lowercase.&lt;br /&gt;
Func _WinAPI_CharLower($sString)&lt;br /&gt;
    Local $aReturn = DllCall(&#039;user32.dll&#039;, &#039;wstr&#039;, &#039;CharLowerW&#039;, &#039;wstr&#039;, $sString)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $sString)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_CharLower&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_CharUpper ==&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(_WinAPI_CharUpper(&amp;quot;example&amp;quot;) &amp;amp; @CRLF) ; Similar to StringUpper.&lt;br /&gt;
&lt;br /&gt;
; Convert characters to uppercase.&lt;br /&gt;
Func _WinAPI_CharUpper($sString)&lt;br /&gt;
	Local $aReturn = DllCall(&#039;user32.dll&#039;, &#039;wstr&#039;, &#039;CharUpperW&#039;, &#039;wstr&#039;, $sString)&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Return SetError(1, 0, $sString)&lt;br /&gt;
	EndIf&lt;br /&gt;
	Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_CharUpper&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_PathFileExists ==&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;
; An API Alternative To FileExist.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(@ScriptFullPath) &amp;amp; @LF) ; File.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(&amp;quot;C:\&amp;quot;) &amp;amp; @LF) ; Drive.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(@ProgramFilesDir) &amp;amp; @LF) ; Directory.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(&amp;quot;Z:\File.txt&amp;quot;) &amp;amp; @LF) ; Shouldn&#039;t exist!&lt;br /&gt;
&lt;br /&gt;
Func _WinAPI_PathFileExists($sFilePath)&lt;br /&gt;
    Local $aReturn = DllCall(&#039;shlwapi.dll&#039;, &#039;int&#039;, &#039;PathFileExistsW&#039;, &#039;wstr&#039;, $sFilePath)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_PathFileExists&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinActiveByExe ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 4813-smoke-n&lt;br /&gt;
| AuthorName = SmOke_N&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Window Active/Activate by Exe, Open Notepad whilst script is running&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
    If _WinActiveByExe(&#039;notepad.exe&#039;, False) Then MsgBox(64, &#039;info&#039;, &#039;true&#039;)&lt;br /&gt;
    Sleep(100)&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func _WinActiveByExe($sExe, $iActive = True);False to WinActivate, True to just see if it&#039;s active&lt;br /&gt;
    If Not ProcessExists($sExe) Then Return SetError(1, 0, 0)&lt;br /&gt;
    Local $aPL = ProcessList($sExe)&lt;br /&gt;
    Local $aWL = WinList()&lt;br /&gt;
    For $iCC = 1 To $aWL[0][0]&lt;br /&gt;
        For $xCC = 1 To $aPL[0][0]&lt;br /&gt;
            If $aWL[$iCC][0] &amp;lt;&amp;gt; &#039;&#039; And _&lt;br /&gt;
                WinGetProcess($aWL[$iCC][1]) = $aPL[$xCC][1] And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) Then&lt;br /&gt;
                If $iActive And WinActive($aWL[$iCC][1]) Then Return 1&lt;br /&gt;
                If Not $iActive And Not WinActive($aWL[$iCC][1]) Then&lt;br /&gt;
                    WinActivate($aWL[$iCC][1])&lt;br /&gt;
                    Return 1&lt;br /&gt;
                EndIf&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
    Next&lt;br /&gt;
    Return SetError(2, 0, 0)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WindowShake ==&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;
; Shake a window left to right.&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Run Notepad&lt;br /&gt;
    Run(&amp;quot;notepad.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    ; Wait 10 seconds for the Notepad window to appear.&lt;br /&gt;
    Local $hWnd = WinWait(&amp;quot;[CLASS:Notepad]&amp;quot;, &amp;quot;&amp;quot;, 10)&lt;br /&gt;
&lt;br /&gt;
    ; Wait for 1 second.&lt;br /&gt;
    Sleep(1000)&lt;br /&gt;
&lt;br /&gt;
    ; Shake the Notepad window left to right.&lt;br /&gt;
    _WindowShake($hWnd)&lt;br /&gt;
&lt;br /&gt;
    ; Wait for 1 second.&lt;br /&gt;
    Sleep(1000)&lt;br /&gt;
&lt;br /&gt;
    ; Close the Notepad window using the handle returned by WinWait.&lt;br /&gt;
    WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _WindowShake($sTitle, $sText = &#039;&#039;, $iDistance = 20)&lt;br /&gt;
    Local $hWnd = WinGetHandle($sTitle, $sText)&lt;br /&gt;
    Local $aWinGetPos = WinGetPos($hWnd)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $aArray[5] = [4, $aWinGetPos[0] + $iDistance, $aWinGetPos[0], $aWinGetPos[0] + $iDistance, $aWinGetPos[0]]&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To $aArray[0]&lt;br /&gt;
        WinMove($hWnd, &#039;&#039;, $aArray[$i], Default)&lt;br /&gt;
        Sleep(100)&lt;br /&gt;
    Next&lt;br /&gt;
EndFunc   ;==&amp;gt;_WindowShake&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetDetails ==&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;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $aArray = _WinGetDetails(&#039;[ACTIVE]&#039;) ; Returns the Window&#039;s title, PID, folder path filename.&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    Exit&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&lt;br /&gt;
Func _WinGetDetails($sTitle, $sText = &#039;&#039;) ; Based on code of _WinGetPath by GaryFrost.&lt;br /&gt;
    Local $aReturn[5] = [4, &#039;-WinTitle&#039;, &#039;-PID&#039;, &#039;-FolderPath&#039;, &#039;-FileName&#039;], $aStringSplit&lt;br /&gt;
&lt;br /&gt;
    If StringLen($sText) &amp;gt; 0 Then&lt;br /&gt;
        $aReturn[1] = WinGetTitle($sTitle, $sText)&lt;br /&gt;
    Else&lt;br /&gt;
        $aReturn[1] = WinGetTitle($sTitle)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aReturn[2] = WinGetProcess($aReturn[1])&lt;br /&gt;
&lt;br /&gt;
    Local $oWMIService = ObjGet(&#039;winmgmts:\\.\root\CIMV2&#039;)&lt;br /&gt;
    Local $oItems = $oWMIService.ExecQuery(&#039;Select * From Win32_Process Where ProcessId = &#039; &amp;amp; $aReturn[2], &#039;WQL&#039;, 0x30)&lt;br /&gt;
    If IsObj($oItems) Then&lt;br /&gt;
        For $oItem In $oItems&lt;br /&gt;
            If $oItem.ExecutablePath Then&lt;br /&gt;
                $aStringSplit = StringSplit($oItem.ExecutablePath, &#039;\&#039;)&lt;br /&gt;
                $aReturn[3] = &#039;&#039;&lt;br /&gt;
                For $A = 1 To $aStringSplit[0] - 1&lt;br /&gt;
                    $aReturn[3] &amp;amp;= $aStringSplit[$A] &amp;amp; &#039;\&#039;&lt;br /&gt;
                Next&lt;br /&gt;
                $aReturn[3] = StringTrimRight($aReturn[3], 1)&lt;br /&gt;
                $aReturn[4] = $aStringSplit[$aStringSplit[0]]&lt;br /&gt;
                Return $aReturn&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return SetError(1, 0, $aReturn)&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinGetPath&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetNumeratedClassList ==&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;
; Description: Retrieves the numerated classes from a window.&lt;br /&gt;
&lt;br /&gt;
Func _WinGetNumeratedClassList($sTitle)&lt;br /&gt;
    Local $sClassList = WinGetClassList($sTitle)&lt;br /&gt;
    Local $aClassList = StringSplit($sClassList, @LF)&lt;br /&gt;
    Local $sRetClassList = &amp;quot;&amp;quot;, $sHold_List = &amp;quot;|&amp;quot;&lt;br /&gt;
    Local $aiInHold, $iInHold&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To UBound($aClassList) - 1&lt;br /&gt;
        If $aClassList[$i] = &amp;quot;&amp;quot; Then ContinueLoop&lt;br /&gt;
&lt;br /&gt;
        If StringRegExp($sHold_List, &amp;quot;\|&amp;quot; &amp;amp; $aClassList[$i] &amp;amp; &amp;quot;~(\d+)\|&amp;quot;) Then&lt;br /&gt;
            $aiInHold = StringRegExp($sHold_List, &amp;quot;.*\|&amp;quot; &amp;amp; $aClassList[$i] &amp;amp; &amp;quot;~(\d+)\|.*&amp;quot;, 1)&lt;br /&gt;
            $iInHold = Number($aiInHold[UBound($aiInHold)-1])&lt;br /&gt;
&lt;br /&gt;
            If $iInHold = 0 Then $iInHold += 1&lt;br /&gt;
&lt;br /&gt;
            $aClassList[$i] &amp;amp;= &amp;quot;~&amp;quot; &amp;amp; $iInHold + 1&lt;br /&gt;
            $sHold_List &amp;amp;= $aClassList[$i] &amp;amp; &amp;quot;|&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            $sRetClassList &amp;amp;= $aClassList[$i] &amp;amp; @LF&lt;br /&gt;
        Else&lt;br /&gt;
            $aClassList[$i] &amp;amp;= &amp;quot;~1&amp;quot;&lt;br /&gt;
            $sHold_List &amp;amp;= $aClassList[$i] &amp;amp; &amp;quot;|&amp;quot;&lt;br /&gt;
            $sRetClassList &amp;amp;= $aClassList[$i] &amp;amp; @LF&lt;br /&gt;
        EndIf&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    Return StringReplace(StringStripWS($sRetClassList, 3), &amp;quot;~&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetHandleByPID ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 4813-smoke-n&lt;br /&gt;
| AuthorName = SmOke_N&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Get Window Handle by PID&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $a1 = _WinGetHandleByPID(232)&lt;br /&gt;
Global $a2 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, -1)&lt;br /&gt;
Global $a3 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, 0)&lt;br /&gt;
Global $a4 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, 1)&lt;br /&gt;
&lt;br /&gt;
_ArrayDisplay($a1, &amp;quot;1&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a2, &amp;quot;2&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a3, &amp;quot;3&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a4, &amp;quot;4&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
;$nVisible = -1 &amp;quot;All (Visble or not)&amp;quot;, $nVisible = 0 &amp;quot;Not Visible Only&amp;quot;, $nVisible = 1 &amp;quot;Visible Only&amp;quot;&lt;br /&gt;
Func _WinGetHandleByPID($vProc, $nVisible = 1)&lt;br /&gt;
    $vProc = ProcessExists($vProc);&lt;br /&gt;
&lt;br /&gt;
    If Not $vProc Then Return SetError(1, 0, 0)&lt;br /&gt;
&lt;br /&gt;
    Local $aWL = WinList()&lt;br /&gt;
&lt;br /&gt;
    Local $aTemp[UBound($aWL)][2]&lt;br /&gt;
&lt;br /&gt;
	Local $nAdd = 0&lt;br /&gt;
&lt;br /&gt;
    For $iCC = 1 To $aWL[0][0]&lt;br /&gt;
        If $nVisible = -1 And WinGetProcess($aWL[$iCC][1]) = $vProc Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        ElseIf $nVisible = 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) = 0 Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        ElseIf $nVisible &amp;gt; 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        EndIf&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    If $nAdd = 0 Then Return SetError(2, 0, 0) ; No windows found&lt;br /&gt;
&lt;br /&gt;
    ReDim $aTemp[$nAdd + 1][2]&lt;br /&gt;
&lt;br /&gt;
    $aTemp[0][0] = $nAdd&lt;br /&gt;
&lt;br /&gt;
    Return $aTemp&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_AutoIt_)&amp;diff=12760</id>
		<title>Snippets ( AutoIt )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_AutoIt_)&amp;diff=12760"/>
		<updated>2015-01-16T21:36:35Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* _IsVisible */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
[[category:Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Snippet Credit Header}}&lt;br /&gt;
&lt;br /&gt;
== AutoItWinShow ==&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;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Display AutoIt&#039;s Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.&lt;br /&gt;
    AutoItWinShow()&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Display AutoIt&#039;s Hidden Window. Returns the handle of the window.&lt;br /&gt;
Func AutoItWinShow()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    WinMove($hWnd, &#039;&#039;, (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.&lt;br /&gt;
    WinSetState($hWnd, &#039;&#039;, @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I&#039;m displaying it.&lt;br /&gt;
    Return $hWnd&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinShow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== AutoItWinGetText ==&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;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Display AutoIt&#039;s Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.&lt;br /&gt;
    AutoItWinShow()&lt;br /&gt;
&lt;br /&gt;
    ; Add a text string to AutoIt&#039;s Hidden Window. Compile to see the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    AutoItWinSetText(&#039;Welcome to AutoIt V&#039; &amp;amp; @AutoItVersion &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Add a text string to AutoIt&#039;s Hidden Window. Compile to see the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    AutoItWinSetText(&#039;Windows Type: &#039; &amp;amp; @OSType &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Display the text stored in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, AutoItWinGetText())&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Retrieve the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
Func AutoItWinGetText()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    Return ControlGetText($hWnd, &#039;&#039;, ControlGetHandle($hWnd, &#039;&#039;, &#039;Edit1&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinGetText&lt;br /&gt;
&lt;br /&gt;
; Add text to AutoIt&#039;s Hidden Window.&lt;br /&gt;
Func AutoItWinSetText($sString)&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    Return ControlSetText($hWnd, &amp;quot;&amp;quot;, ControlGetHandle($hWnd, &amp;quot;&amp;quot;, &#039;Edit1&#039;), ControlGetText($hWnd, &#039;&#039;, ControlGetHandle($hWnd, &#039;&#039;, &#039;Edit1&#039;)) &amp;amp; $sString)&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinSetText&lt;br /&gt;
&lt;br /&gt;
; Display AutoIt&#039;s Hidden Window. Returns the handle of the window.&lt;br /&gt;
Func AutoItWinShow()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    WinMove($hWnd, &#039;&#039;, (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.&lt;br /&gt;
    WinSetState($hWnd, &#039;&#039;, @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I&#039;m displaying it.&lt;br /&gt;
    Return $hWnd&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinShow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _DockToWindow ==&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;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If (Not ProcessExists(&amp;quot;SciTE.exe&amp;quot;)) Then&lt;br /&gt;
    Exit MsgBox(4096, &#039;&#039;, &amp;quot;Please start SciTE.exe&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Create a GUI, similar to SciTE Jump&#039;s GUI.&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;, 215, 400, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    ; Dock the first window to left and adjust the width based on the width of the second GUI.&lt;br /&gt;
    _DockToWindow(WinGetHandle(&amp;quot;[CLASS:SciTEWindow]&amp;quot;), $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&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;
&lt;br /&gt;
Func _DockToWindow(Const $hHandle_1, Const $hHandle_2)&lt;br /&gt;
    ; Retrieve the working area, this is minus the taskbar dimensions so slightly different to @DesktopHeight and @DesktopWidth which is the&lt;br /&gt;
    ; monitors height and width.&lt;br /&gt;
    Local Const $SPI_GETWORKAREA = 48&lt;br /&gt;
    Local Const $tWorkArea = DllStructCreate($tagRECT)&lt;br /&gt;
    _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($tWorkArea))&lt;br /&gt;
&lt;br /&gt;
    ; Retieve the position of the second GUI.&lt;br /&gt;
    Local Const $aClientSize_2 = WinGetPos($hHandle_2)&lt;br /&gt;
&lt;br /&gt;
    ; Set the state of the windows to &#039;Restore&#039;.&lt;br /&gt;
    WinSetState($hHandle_1, &#039;&#039;, @SW_RESTORE)&lt;br /&gt;
    WinSetState($hHandle_2, &#039;&#039;, @SW_RESTORE)&lt;br /&gt;
&lt;br /&gt;
    ; Move the first to the far left of the screen and adjust the width to the total screen width minus the width of the second GUI. e.g. 1366 - 215&lt;br /&gt;
    WinMove($hHandle_1, &#039;&#039;, DllStructGetData($tWorkArea, &#039;Left&#039;), DllStructGetData($tWorkArea, &#039;Top&#039;), DllStructGetData($tWorkArea, &#039;Right&#039;) - DllStructGetData($tWorkArea, &#039;Left&#039;) - $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Bottom&#039;) - DllStructGetData($tWorkArea, &#039;Top&#039;))&lt;br /&gt;
&lt;br /&gt;
    ; Move the second window to the far right in between the remaining space and adjust the height of the GUI.&lt;br /&gt;
    WinMove($hHandle_2, &#039;&#039;, DllStructGetData($tWorkArea, &#039;Right&#039;) - DllStructGetData($tWorkArea, &#039;Left&#039;) - $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Top&#039;), $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Bottom&#039;) - DllStructGetData($tWorkArea, &#039;Top&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;_DockToWindow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FuncExists ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 52-geosoft&lt;br /&gt;
| AuthorName = GEOSoft&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox(0, &amp;quot;TEST&amp;quot;, &amp;quot;Function Exists = &amp;quot; &amp;amp; _FuncExists(&amp;quot;_FuncExists&amp;quot;, @ScriptFullPath))&lt;br /&gt;
&lt;br /&gt;
Func _FuncExists($sFunc, $sPath)&lt;br /&gt;
   If Not FileExists($sPath) Then Return SetError(1)&lt;br /&gt;
   Local Const $sStr = FileRead($sPath)&lt;br /&gt;
   Local Const $sRegEx = &amp;quot;(?i)(?m:^|\n)\s*Func\s+(&amp;quot; &amp;amp; $sFunc &amp;amp; &amp;quot;)\s*\(&amp;quot;&lt;br /&gt;
   Local Const $aRegEx = StringRegExp($sStr, $sRegEx, 1)&lt;br /&gt;
   If IsArray($aRegEx) Then Return 1&lt;br /&gt;
   Return 0&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FunctionSort ==&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;
; Get the list of Functions in a script and sort by alphabetical order.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;String.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local $sFile = FileOpenDialog(@ScriptName, &amp;quot;Select an AutoIt file.&amp;quot;, &amp;quot;Au3 (*.au3)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    Exit&lt;br /&gt;
EndIf&lt;br /&gt;
ClipPut(_FunctionSort($sFile))&lt;br /&gt;
&lt;br /&gt;
Func _FunctionSort($sFilePath)&lt;br /&gt;
    Local Const $sRead = FileRead($sFilePath)&lt;br /&gt;
&lt;br /&gt;
	Local $aReturn = StringRegExp(&amp;quot;Func _Count()&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;EndFunc ;==&amp;gt;_Count&amp;quot; &amp;amp; $sRead, &#039;(?s)(?i)Func(.*?)EndFunc&#039;, 3)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    $aReturn[0] = UBound($aReturn, 1) - 1&lt;br /&gt;
&lt;br /&gt;
    _ArraySort($aReturn, 0, 1)&lt;br /&gt;
&lt;br /&gt;
    Local $sReturn&lt;br /&gt;
&lt;br /&gt;
    For $A = 1 To $aReturn[0]&lt;br /&gt;
        $sReturn &amp;amp;= &amp;quot;Func&amp;quot; &amp;amp; $aReturn[$A] &amp;amp; &amp;quot;EndFunc&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    Return $sReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_FunctionSort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsBeta ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 10673-mlipok&lt;br /&gt;
| AuthorName = mLipok&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;
#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;
    Local $aTest[10]&lt;br /&gt;
    _ArrayUnique($aTest, 0, 5)&lt;br /&gt;
    Local $iError = @error&lt;br /&gt;
    ConsoleWrite(&#039;$iError = &#039; &amp;amp; $iError &amp;amp; @CRLF)&lt;br /&gt;
    If _IsBeta() Then&lt;br /&gt;
        If $iError = 3 Then&lt;br /&gt;
            MsgBox($MB_SYSTEMMODAL, &#039;@error&#039;, &#039;3 - $iBase or $iCase contains an invalid value&#039; &amp;amp; @CRLF &amp;amp; @AutoItVersion)&lt;br /&gt;
        EndIf&lt;br /&gt;
    Else&lt;br /&gt;
        If $iError = 2 Then&lt;br /&gt;
            MsgBox($MB_SYSTEMMODAL, &#039;@error&#039;, &#039;2 - $iBase or $iCase contains an invalid value&#039; &amp;amp; @CRLF &amp;amp; @AutoItVersion)&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _IsBeta()&lt;br /&gt;
       Return Mod(StringSplit(@AutoItVersion, &#039;.&#039;)[3], 2) == 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsBeta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsButton ==&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;ButtonConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;Constants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    Local Const $iLabel = GUICtrlCreateButton(&#039;&#039;, 0, 0, 50, 50)&lt;br /&gt;
    Local Const $iCheckbox = GUICtrlCreateCheckbox(&#039;&#039;, 0, 0, 100, 20) ; This is considered a &#039;Button&#039; by _WinAPI_GetClassName too.&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;AutoIt Button ID: &#039; &amp;amp; _IsButton($iLabel) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Button Handle: &#039; &amp;amp; _IsButton(GUICtrlGetHandle($iLabel)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Checkbox ID: &#039; &amp;amp; _IsButton($iCheckbox) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Checkbox Handle: &#039; &amp;amp; _IsButton(GUICtrlGetHandle($iCheckbox)) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    Return GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Check if a variable is referencing a Button control.&lt;br /&gt;
Func _IsButton($hWnd)&lt;br /&gt;
    If IsHWnd($hWnd) = 0 Then&lt;br /&gt;
        $hWnd = GUICtrlGetHandle($hWnd)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Local Const $sClassName = _WinAPI_GetClassName($hWnd)&lt;br /&gt;
&lt;br /&gt;
    If $sClassName = &#039;Button&#039; Then&lt;br /&gt;
        Local Const $aStyle[5] = [4, $BS_CHECKBOX, $BS_AUTOCHECKBOX, $BS_RADIOBUTTON, $BS_AUTORADIOBUTTON]&lt;br /&gt;
&lt;br /&gt;
        Local Const $iLong = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)&lt;br /&gt;
&lt;br /&gt;
		For $i = 1 To $aStyle[0]&lt;br /&gt;
            If BitAND($iLong, $aStyle[$i]) = $aStyle[$i] Then&lt;br /&gt;
                Return False&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
&lt;br /&gt;
        Return True&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return False&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsButton&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsControlID ==&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 if a Control ID is a native AutoIt control.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;GUIListView.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    Local Const $iControlID = GUICtrlCreateLabel(&#039;&#039;, 0, 0, 500, 500)&lt;br /&gt;
    Local Const $hListView = _GUICtrlListView_Create($hGUI, &#039;Example&#039;, 0, 0, 500, 500)&lt;br /&gt;
&lt;br /&gt;
	GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;AutoIt ControlID: &#039; &amp;amp; _IsControlID($iControlID) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;Random Number: &#039; &amp;amp; _IsControlID(Random(42, 99, 1)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt ControlID Handle: &#039; &amp;amp; _IsControlID(GUICtrlGetHandle($iControlID)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;ListView UDF Handle: &#039; &amp;amp; _IsControlID($hListView) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;ListView UDF Handle: &#039; &amp;amp; _IsControlID(GUICtrlGetHandle($hListView)) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    _GUICtrlListView_Destroy($hListView)&lt;br /&gt;
&lt;br /&gt;
    Return GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _IsControlID($iControlID)&lt;br /&gt;
    If IsHWnd($iControlID) Then&lt;br /&gt;
        $iControlID = _WinAPI_GetDlgCtrlID($iControlID)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return IsHWnd(GUICtrlGetHandle($iControlID)) = 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsControlID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItIncludesFromSciTE ==&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;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetAutoItIncludesFromSciTE() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Retrieve the AutoIt includes path from the SciTE process.&lt;br /&gt;
Func _GetAutoItIncludesFromSciTE()&lt;br /&gt;
    Local $sRelativePath = &#039;..\Include&#039;&lt;br /&gt;
	Local Const $sWorkingDir = @WorkingDir&lt;br /&gt;
    FileChangeDir(_WinAPI_PathRemoveFileSpec(_WinAPI_GetProcessFileName(ProcessExists(&#039;SciTE.exe&#039;))))&lt;br /&gt;
    $sRelativePath = _WinAPI_GetFullPathName($sRelativePath)&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return _WinAPI_PathRemoveBackslash($sRelativePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItIncludesFromSciTE&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstall ==&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;
; Get the AutoIt installation folder.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetAutoItInstall() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetAutoItInstall()&lt;br /&gt;
    Return StringLeft(@AutoItExe, StringInStr(@AutoItExe, &amp;quot;\&amp;quot;, 2, -1) - 1)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstall&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstallEx ==&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(_GetAutoItInstallEx() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the installation of AutoIt. An improved version of _GetAutoItInstall.&lt;br /&gt;
Func _GetAutoItInstallEx()&lt;br /&gt;
    Local $aWow6432Node[2] = [&#039;&#039;, &#039;Wow6432Node\&#039;], $aFiles[4] = [3, @ProgramFilesDir, EnvGet(&amp;quot;PROGRAMFILES&amp;quot;), EnvGet(&amp;quot;PROGRAMFILES(X86)&amp;quot;)]&lt;br /&gt;
    Local $sFilePath = RegRead(&#039;HKEY_LOCAL_MACHINE\SOFTWARE\&#039; &amp;amp; $aWow6432Node[@AutoItX64] &amp;amp; &#039;AutoIt v3\AutoIt\&#039;, &#039;InstallDir&#039;)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        For $A = 1 To $aFiles[0]&lt;br /&gt;
            $aFiles[$A] &amp;amp;= &#039;\AutoIt&#039;&lt;br /&gt;
            If FileExists($aFiles[$A]) Then&lt;br /&gt;
                Return $aFiles[$A]&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
        Return SetError(1, 0, &#039;&#039;)&lt;br /&gt;
    Else&lt;br /&gt;
        Return $sFilePath&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstallEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstallFromSciTE ==&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(_GetAutoItInstallFromSciTE() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Retrieve the AutoIt installation path from the SciTE process.&lt;br /&gt;
Func _GetAutoItInstallFromSciTE()&lt;br /&gt;
    Local $sRelativePath = &#039;..\&#039;, $sWorkingDir = @WorkingDir&lt;br /&gt;
    FileChangeDir( _WinAPI_PathRemoveFileSpec(_WinAPI_GetProcessFileName(ProcessExists(&amp;quot;SciTE.exe&amp;quot;))))&lt;br /&gt;
    $sRelativePath = _WinAPI_GetFullPathName($sRelativePath)&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return _WinAPI_PathRemoveBackslash($sRelativePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstallFromSciTE&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetClasses ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 24-cyberslug&lt;br /&gt;
| AuthorName = CyberSlug&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Get ALL Controls Info&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
	; Run Calculator&lt;br /&gt;
	Run(&amp;quot;calc.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	; Wait 10 seconds for the Calculator window to appear.&lt;br /&gt;
	Local const $hWnd = WinWait(&amp;quot;[CLASS:CalcFrame]&amp;quot;, &#039;&#039;, 10)&lt;br /&gt;
&lt;br /&gt;
	; Retrieve a list of all the controls in the Calculator window using the handle returned by WinWait.&lt;br /&gt;
	MsgBox(4096, &#039;&#039;, _GetClasses($hWnd))&lt;br /&gt;
&lt;br /&gt;
	; Close the Calculator window using the handle returned by WinWait.&lt;br /&gt;
	WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; This function returns an @LF-separated list of controls on the specified window.&lt;br /&gt;
Func _GetClasses($sTitle, $sText = &#039;&#039;)&lt;br /&gt;
	Local $iCount_Button = 0, $iCount_Edit = 0, $iCount_Static = 0&lt;br /&gt;
	Local $aClasses = StringSplit(WinGetClassList($sTitle, $sText), @LF)&lt;br /&gt;
	Local $aClassID[$aClasses[0] + 1] = [$aClasses[0]]&lt;br /&gt;
&lt;br /&gt;
	For $i = 1 To $aClasses[0]&lt;br /&gt;
		Select&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Button&amp;quot;&lt;br /&gt;
				$iCount_Button += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Button&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Edit&amp;quot;&lt;br /&gt;
				$iCount_Edit += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Edit&lt;br /&gt;
				$aClasses[$i] = &amp;quot;Input&amp;quot;&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Static&amp;quot;&lt;br /&gt;
				$iCount_Static += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Static&lt;br /&gt;
				$aClasses[$i] = &amp;quot;Label&amp;quot;&lt;br /&gt;
			Case Else&lt;br /&gt;
				If $aClasses[$i] &amp;lt;&amp;gt; &amp;quot;&amp;quot; Then&lt;br /&gt;
					$aClassID[$i] = $aClasses[$i] &amp;amp; &amp;quot;?&amp;quot;&lt;br /&gt;
				EndIf&lt;br /&gt;
		EndSelect&lt;br /&gt;
	Next&lt;br /&gt;
&lt;br /&gt;
	; Combine the results.&lt;br /&gt;
	Local $sReturn = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	For $i = 1 To $aClassID[0]&lt;br /&gt;
		$sReturn &amp;amp;= $aClassID[$i] &amp;amp; @LF&lt;br /&gt;
	Next&lt;br /&gt;
&lt;br /&gt;
	Return $sReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetClasses&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFile ==&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;
; FileRead Alternative&lt;br /&gt;
&lt;br /&gt;
Func _GetFile($sFile, $iFormat = 0)&lt;br /&gt;
    Local $hFileOpen = FileOpen($sFile, $iFormat)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(1, 0, &amp;quot;&amp;quot;)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $sData = FileRead($hFileOpen)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
    Return $sData&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetTitle ==&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;
; Get the title of your program.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetTitle(&#039;Example&#039;) &amp;amp; @CRLF)&lt;br /&gt;
; The second parameter would normally be @ScriptDir &amp;amp; &#039;\Uninstall.exe&#039; for example, but for this demonstration I&#039;m using the full path.&lt;br /&gt;
ConsoleWrite(_GetTitle(&#039;Example&#039;, @ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetTitle($sProgramName, $sInstallPath = &#039;&#039;)&lt;br /&gt;
    Local $aOSArch[2] = [&#039;&#039;, &#039; (64-bit)&#039;], $aPortable[2] = [&#039; (Portable)&#039;, &#039;&#039;]&lt;br /&gt;
    Return $sProgramName &amp;amp; $aOSArch[@AutoItX64] &amp;amp; $aPortable[FileExists($sInstallPath)]&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetTitle&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetXML ==&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;
; Simple Way Of Parsing XML Data.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $aReturn, $sXMLData&lt;br /&gt;
&lt;br /&gt;
$sXMLData = &amp;quot;&amp;lt;data&amp;gt;This is a Simple example of XML&amp;lt;/data&amp;gt;&amp;lt;data&amp;gt;This is a Simple example of XML and is the Second String.&amp;lt;/data&amp;gt;&amp;quot;&lt;br /&gt;
$aReturn = _GetXML($sXMLData, &amp;quot;data&amp;quot;)&lt;br /&gt;
_ArrayDisplay($aReturn, &amp;quot;_GetXML()&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _GetXML($sString, $sData)&lt;br /&gt;
    Local $aError[2] = [1, $sString], $aReturn&lt;br /&gt;
    $aReturn = StringRegExp(&#039;&amp;lt;&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&amp;lt;/&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&#039; &amp;amp; $sString, &#039;(?s)(?i)&amp;lt;&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;(.*?)&amp;lt;/&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&#039;, 3)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $aError)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aReturn[0] = UBound($aReturn, 1) - 1&lt;br /&gt;
    Return SetError(0, 0, $aReturn)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetXML&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Include Source With Exe ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 54985-jlogan3o13&lt;br /&gt;
| AuthorName = JLogan3o13&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;recover source .au3 file with /Extract switch&lt;br /&gt;
; The above code would be copied into the top of your script. The source location (C:\Test.au3 in my example) is the full path to your script file.&lt;br /&gt;
;Once compiled, if you run the script from the Run line with the /Extract switch, it will extact the original .au3 file into the Temp directory and will exit without actually executing the script.&lt;br /&gt;
If StringInStr($cmdlineRaw, &amp;quot;/Extract&amp;quot;) Then&lt;br /&gt;
	FileInstall(&amp;quot;C:\Test.au3&amp;quot;, @TempDir &amp;amp; &amp;quot;\Test.au3&amp;quot;, 1)&lt;br /&gt;
	Exit&lt;br /&gt;
EndIf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsANSIFile ==&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;FileConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_IsANSIFile(@ScriptFullPath) &amp;amp; @LF) ; Returns True.&lt;br /&gt;
&lt;br /&gt;
Func _IsANSIFile($sFilePath)&lt;br /&gt;
    Return FileGetEncoding($sFilePath) = $FO_READ&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsUnicodeFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsUnicodeFile ==&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;FileConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_IsUnicodeFile(@ScriptFullPath) &amp;amp; @LF) ; Returns False.&lt;br /&gt;
&lt;br /&gt;
Func _IsUnicodeFile($sFilePath)&lt;br /&gt;
    Return FileGetEncoding($sFilePath) = $FO_UNICODE&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsUnicodeFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsAu3File ==&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(_IsAu3File(@AutoItExe) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_IsAu3File(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Checks whether the filepath is an au3 file.&lt;br /&gt;
Func _IsAu3File($sFilePath)&lt;br /&gt;
    Return StringTrimLeft($sFilePath, StringInStr($sFilePath, &amp;quot;.&amp;quot;, 2, -1)) = &amp;quot;au3&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsAu3File&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsDefault ==&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;
If _IsDefault(Default) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 1&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
If _IsDefault(-1) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 2&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
If _IsDefault(&amp;quot;Other&amp;quot;) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 3&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
Func _IsDefault($sDefault)&lt;br /&gt;
    Return StringRegExp($sDefault, &amp;quot;(?-i)\s|Default|-1|0&amp;quot;)&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsDefault&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsInTrial ==&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;Date.au3&amp;gt; ; Required for _DateDiff()&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;Date trial started: &#039; &amp;amp; @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/01&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Today&#039;&#039;s date: &#039; &amp;amp; @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/&#039; &amp;amp; @MDAY &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Trial period: 30 days&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Is the trial period still valid: &#039; &amp;amp; _IsInTrial(@YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/01&#039;, 30) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a trial period date is still valid.&lt;br /&gt;
Func _IsInTrial($sDateString, $iDays) ; Based on the idea found here: http://www.autoitscript.com/forum/topic/...ial-time/page__view__findpost_&lt;br /&gt;
    Return (_DateDiff(&#039;D&#039;, $sDateString, @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/&#039; &amp;amp; @MDAY) &amp;lt; $iDays)&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsInTrial&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsVisible ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = &lt;br /&gt;
| AuthorName = Multiple&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Check if the Notepad Window is visible.&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Run Notepad&lt;br /&gt;
    Run(&amp;quot;notepad.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    ; Wait 10 seconds for the Notepad window to appear.&lt;br /&gt;
    Local $hWnd = WinWait(&amp;quot;[CLASS:Notepad]&amp;quot;, &amp;quot;&amp;quot;, 10)&lt;br /&gt;
&lt;br /&gt;
    ; Check if the Notepad window is visible and display the appropriate message box.&lt;br /&gt;
    If _IsVisible($hWnd) Then&lt;br /&gt;
        MsgBox(4096, &amp;quot;&amp;quot;, &amp;quot;Notepad is visible.&amp;quot;)&lt;br /&gt;
    Else&lt;br /&gt;
        MsgBox(4096, &amp;quot;&amp;quot;, &amp;quot;Notepad isn&#039;t visible.&amp;quot;)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    ; Close the Notepad window using the handle returned by WinWait.&lt;br /&gt;
    WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Check if the window is visible.&lt;br /&gt;
Func _IsVisible($hWnd)&lt;br /&gt;
    Return BitAND(WinGetState($hWnd), 2) = 2&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsVisible&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Open Help File to Desired Page ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 1967-garyfrost&lt;br /&gt;
| AuthorName = GaryFrost&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Open help file / Open a desired page&lt;br /&gt;
&lt;br /&gt;
Global Const $sAutoItPath = RegRead(&amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt&amp;quot;, &amp;quot;InstallDir&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Run(@WindowsDir &amp;amp; &amp;quot;\hh.exe &amp;quot; &amp;amp; $sAutoItPath &amp;amp; &amp;quot;\AutoIt3.chm::/html/functions/GUICtrlCreateUpdown.htm&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _RunAU3 ==&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;
_RunAU3(&amp;quot;AU3_Example.txt&amp;quot;, &#039;&amp;quot;This is a commandline example!&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
Func _RunAU3($sFilePath,  $sCommandLine = &amp;quot;&amp;quot;, $sWorkingDir = &amp;quot;&amp;quot;, $iShowFlag = @SW_SHOW, $iOptFlag = 0)&lt;br /&gt;
    Return Run(&#039;&amp;quot;&#039; &amp;amp; @AutoItExe &amp;amp; &#039;&amp;quot; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; $sCommandLine, $sWorkingDir, $iShowFlag, $iOptFlag)&lt;br /&gt;
EndFunc   ;==&amp;gt;_RunAU3&lt;br /&gt;
&lt;br /&gt;
Func _RunWaitAU3($sFilePath, $sCommandLine = &amp;quot;&amp;quot;, $sWorkingDir = &amp;quot;&amp;quot;, $iShowFlag = @SW_SHOW, $iOptFlag = 0)&lt;br /&gt;
    Local $iPID&lt;br /&gt;
    $iPID = RunWait(&#039;&amp;quot;&#039; &amp;amp; @AutoItExe &amp;amp; &#039;&amp;quot; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; $sCommandLine, $sWorkingDir, $iShowFlag, $iOptFlag)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(@error, 1, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $iPID&lt;br /&gt;
EndFunc   ;==&amp;gt;_RunWaitAU3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Run Any au3 File From Your Program ==&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;
; Run Any Au3 File From Your Program&lt;br /&gt;
&lt;br /&gt;
Global Const $sFilePath = @ScriptDir &amp;amp; &amp;quot;\Test.au3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If @Compiled Then&lt;br /&gt;
	Global Const $sFileExe = FileGetShortName(@AutoItExe &amp;amp; &#039; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot;&#039;)&lt;br /&gt;
	Run($sFileExe)&lt;br /&gt;
Else&lt;br /&gt;
	Global Const $sFileAu3 = FileGetShortName($sFilePath)&lt;br /&gt;
	Run(@AutoItExe &amp;amp; &amp;quot; &amp;quot; &amp;amp; $sFileAu3, &amp;quot;&amp;quot;, @SW_HIDE)&lt;br /&gt;
EndIf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ScriptName ==&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(_ScriptName() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Return the @ScriptName minus the .exe or .au3 extension.&lt;br /&gt;
Func _ScriptName()&lt;br /&gt;
	Return StringLeft(@ScriptName, StringInStr(@ScriptName, &#039;.&#039;, 2, -1) - 1)&lt;br /&gt;
EndFunc   ;==&amp;gt;_ScriptName&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ScriptVersion ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 31149-milesahead&lt;br /&gt;
| AuthorName = MilesAhead&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#NoTrayIcon&lt;br /&gt;
&lt;br /&gt;
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****&lt;br /&gt;
#AutoIt3Wrapper_UseUpx=n&lt;br /&gt;
#AutoIt3Wrapper_Res_Fileversion=1.2.3.4&lt;br /&gt;
#AutoIt3Wrapper_Res_LegalCopyright=2012  www.favessoft.com&lt;br /&gt;
#AutoIt3Wrapper_Res_Language=1033&lt;br /&gt;
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&lt;br /&gt;
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****&lt;br /&gt;
&lt;br /&gt;
Global $version = _ScriptVersion()&lt;br /&gt;
&lt;br /&gt;
Global $msg = &amp;quot;ScriptVerDemo&amp;quot; &amp;amp; &amp;quot; &amp;quot; &amp;amp; $version &amp;amp; &amp;quot;  Copyright (c) 2012  www.favessoft.com&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF&lt;br /&gt;
&lt;br /&gt;
MsgBox(0x1040, &amp;quot;&amp;quot;, $msg)&lt;br /&gt;
&lt;br /&gt;
; return File Version string from compiled or .au3 script&lt;br /&gt;
; returns &amp;quot;&amp;quot; if no version info available&lt;br /&gt;
; Note: The .au3 script must contain #AutoItWrapper&lt;br /&gt;
; directives with file version or &amp;quot;&amp;quot; is returned.&lt;br /&gt;
Func _ScriptVersion(Const $Script = @ScriptFullPath)&lt;br /&gt;
    If StringRight($Script,4) = &amp;quot;.exe&amp;quot; Then&lt;br /&gt;
        Return FileGetVersion($Script)&lt;br /&gt;
    Else&lt;br /&gt;
        Local Const $scriptHandle = FileOpen($Script)&lt;br /&gt;
		Local $ver&lt;br /&gt;
		Local $found = False&lt;br /&gt;
		Local $pos&lt;br /&gt;
&lt;br /&gt;
        If $scriptHandle &amp;lt;&amp;gt; -1 Then&lt;br /&gt;
            Do&lt;br /&gt;
                $ver = FileReadLine($scriptHandle)&lt;br /&gt;
                $sPos = StringInStr($ver, &amp;quot;_Fileversion=&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
                If $sPos Then&lt;br /&gt;
                    $ver = StringMid($ver, $sPos + StringLen(&amp;quot;_Fileversion=&amp;quot;))&lt;br /&gt;
                    $found = True&lt;br /&gt;
                    ExitLoop&lt;br /&gt;
                EndIf&lt;br /&gt;
            Until StringLeft($ver, 1) &amp;lt;&amp;gt; &amp;quot;#&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            FileClose($scriptHandle)&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    If Not $found Then $ver = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    Return $ver&lt;br /&gt;
EndFunc   ;==&amp;gt;_ScriptVersion&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SetFile ==&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;
; FileWrite Alternative&lt;br /&gt;
&lt;br /&gt;
Func _SetFile(Const $sString, Const $sFile, Const $iOverwrite = 0)&lt;br /&gt;
    Local Const $hFileOpen = FileOpen($sFile, $iOverwrite + 1)&lt;br /&gt;
&lt;br /&gt;
    FileWrite($hFileOpen, $sString)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $sString)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return $sString&lt;br /&gt;
EndFunc   ;==&amp;gt;_SetFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ShowHelp ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 60350-chimaera&lt;br /&gt;
| AuthorName = Chimaera&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
HotKeySet(&amp;quot;{F1}&amp;quot;, &amp;quot;_ShowHelp&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _ShowHelp()&lt;br /&gt;
	Return ShellExecute(@ProgramFilesDir &amp;amp; &amp;quot;\AutoIt3\AutoIt3Help.exe&amp;quot;) ; change this to the location of your own helpfile.&lt;br /&gt;
EndFunc   ;==&amp;gt;_ShowHelp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SingletonPID ==&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;
Local $iSingleton = _SingletonPID(&#039;RandomName&#039;, 1)&lt;br /&gt;
&lt;br /&gt;
If $iSingleton = 0 Then&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;This is the first instance of the program running: &#039; &amp;amp; $iSingleton)&lt;br /&gt;
Else&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;There is another instance running. This PID is: &#039; &amp;amp; $iSingleton)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name ..........: _SingletonPID&lt;br /&gt;
; Description ...: Enforce a design paradigm where only one instance of the script may be running.&lt;br /&gt;
; Syntax ........: _SingletonPID($sOccurenceName[, $iFlag = 0])&lt;br /&gt;
; Parameters ....: $sOccurenceName      - String to identify the occurrence of the script.&lt;br /&gt;
;                  $iFlag               - [optional] Optional parameters. Default is 0.&lt;br /&gt;
;                  0 - Exit the script with the exit code -1 if another instance already exists.&lt;br /&gt;
;                  1 - Return the PID of the main executable and without exiting the script too.&lt;br /&gt;
; Return values .: Success - 0 No other process is running.&lt;br /&gt;
;                  Failure - The PID of the main executable.&lt;br /&gt;
; Author ........: guinness with initial ideas by Valik for _Singleton &amp;amp; KaFu for _EnforceSingleInstance.&lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _SingletonPID(Const $sOccurenceName, Const $iFlag = 0)&lt;br /&gt;
    Local $hHandle = WinGetHandle($sOccurenceName)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        AutoItWinSetTitle($sOccurenceName)&lt;br /&gt;
        $hHandle = WinGetHandle($sOccurenceName)&lt;br /&gt;
        ControlSetText($hHandle, &#039;&#039;, ControlGetHandle($hHandle, &#039;&#039;, &#039;Edit1&#039;), @AutoItPID)&lt;br /&gt;
    Else&lt;br /&gt;
        If BitAND($iFlag, 1) Then&lt;br /&gt;
            Return Number(ControlGetText($hHandle, &#039;&#039;, ControlGetHandle($hHandle, &#039;&#039;, &#039;Edit1&#039;)))&lt;br /&gt;
        Else&lt;br /&gt;
            Exit -1&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_SingletonPID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _Sort ==&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(_Sort(&amp;quot;$sVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$iVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$tVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$pVariable&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
Func _Sort(Const $sSortList)&lt;br /&gt;
    Local Const $iPID = Run(&amp;quot;sort.exe&amp;quot;, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD), $sOutput = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    StdinWrite($iPID, $sSortList)&lt;br /&gt;
    StdinWrite($iPID)&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;_Sort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Speak Object and Save to WAV File ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 52278-solidsnake26&lt;br /&gt;
| AuthorName = SolidSnake26&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Speak Object and save to wav file&lt;br /&gt;
&lt;br /&gt;
_SpeakToWAV(&amp;quot;AutoIt Snippets&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\SavedFile.wav&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _SpeakToWAV(Const $sText, Const $sFilePath)&lt;br /&gt;
	Local $ObjVoice = ObjCreate(&amp;quot;Sapi.SpVoice&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	Local $ObjFile = ObjCreate(&amp;quot;Sapi.SpFileStream.1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	$ObjVoice.Speak($sText)&lt;br /&gt;
&lt;br /&gt;
	$ObjFile.Open($sFilePath, 3)&lt;br /&gt;
&lt;br /&gt;
	$ObjVoice.AudioOutputStream = $ObjFile&lt;br /&gt;
EndFunc   ;==&amp;gt;_SpeakToWAV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _VariableSwap ==&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;
Global $sString_1 = &#039;This is string 1.&#039;&lt;br /&gt;
Global $sString_2 = &#039;This is string 2.&#039;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;$sString_1: &#039; &amp;amp; $sString_1 &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(&#039;$sString_2: &#039; &amp;amp; $sString_2 &amp;amp; @CRLF &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
_VariableSwap($sString_1, $sString_2)&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;$sString_1: &#039; &amp;amp; $sString_1 &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(&#039;$sString_2: &#039; &amp;amp; $sString_2 &amp;amp; @CRLF &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Swap the contents of two variables.&lt;br /&gt;
Func _VariableSwap(ByRef $vVariable_1, ByRef $vVariable_2) ; Similar to _ArraySwap though not obvious to some this isn&#039;t limited to arrays.&lt;br /&gt;
    Local Const $vTemp = $vVariable_1&lt;br /&gt;
    $vVariable_1 = $vVariable_2&lt;br /&gt;
    $vVariable_2 = $vTemp&lt;br /&gt;
EndFunc   ;==&amp;gt;_VariableSwap&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_CharLower ==&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(_WinAPI_CharLower(&amp;quot;EXAMPLE&amp;quot;) &amp;amp; @CRLF) ; Similar to StringLower.&lt;br /&gt;
&lt;br /&gt;
; Convert characters to lowercase.&lt;br /&gt;
Func _WinAPI_CharLower($sString)&lt;br /&gt;
    Local $aReturn = DllCall(&#039;user32.dll&#039;, &#039;wstr&#039;, &#039;CharLowerW&#039;, &#039;wstr&#039;, $sString)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $sString)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_CharLower&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_CharUpper ==&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(_WinAPI_CharUpper(&amp;quot;example&amp;quot;) &amp;amp; @CRLF) ; Similar to StringUpper.&lt;br /&gt;
&lt;br /&gt;
; Convert characters to uppercase.&lt;br /&gt;
Func _WinAPI_CharUpper($sString)&lt;br /&gt;
	Local $aReturn = DllCall(&#039;user32.dll&#039;, &#039;wstr&#039;, &#039;CharUpperW&#039;, &#039;wstr&#039;, $sString)&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Return SetError(1, 0, $sString)&lt;br /&gt;
	EndIf&lt;br /&gt;
	Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_CharUpper&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_PathFileExists ==&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;
; An API Alternative To FileExist.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(@ScriptFullPath) &amp;amp; @LF) ; File.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(&amp;quot;C:\&amp;quot;) &amp;amp; @LF) ; Drive.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(@ProgramFilesDir) &amp;amp; @LF) ; Directory.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(&amp;quot;Z:\File.txt&amp;quot;) &amp;amp; @LF) ; Shouldn&#039;t exist!&lt;br /&gt;
&lt;br /&gt;
Func _WinAPI_PathFileExists($sFilePath)&lt;br /&gt;
    Local $aReturn = DllCall(&#039;shlwapi.dll&#039;, &#039;int&#039;, &#039;PathFileExistsW&#039;, &#039;wstr&#039;, $sFilePath)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_PathFileExists&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinActiveByExe ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 4813-smoke-n&lt;br /&gt;
| AuthorName = SmOke_N&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Window Active/Activate by Exe, Open Notepad whilst script is running&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
    If _WinActiveByExe(&#039;notepad.exe&#039;, False) Then MsgBox(64, &#039;info&#039;, &#039;true&#039;)&lt;br /&gt;
    Sleep(100)&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func _WinActiveByExe($sExe, $iActive = True);False to WinActivate, True to just see if it&#039;s active&lt;br /&gt;
    If Not ProcessExists($sExe) Then Return SetError(1, 0, 0)&lt;br /&gt;
    Local $aPL = ProcessList($sExe)&lt;br /&gt;
    Local $aWL = WinList()&lt;br /&gt;
    For $iCC = 1 To $aWL[0][0]&lt;br /&gt;
        For $xCC = 1 To $aPL[0][0]&lt;br /&gt;
            If $aWL[$iCC][0] &amp;lt;&amp;gt; &#039;&#039; And _&lt;br /&gt;
                WinGetProcess($aWL[$iCC][1]) = $aPL[$xCC][1] And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) Then&lt;br /&gt;
                If $iActive And WinActive($aWL[$iCC][1]) Then Return 1&lt;br /&gt;
                If Not $iActive And Not WinActive($aWL[$iCC][1]) Then&lt;br /&gt;
                    WinActivate($aWL[$iCC][1])&lt;br /&gt;
                    Return 1&lt;br /&gt;
                EndIf&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
    Next&lt;br /&gt;
    Return SetError(2, 0, 0)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WindowShake ==&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;
; Shake a window left to right.&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Run Notepad&lt;br /&gt;
    Run(&amp;quot;notepad.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    ; Wait 10 seconds for the Notepad window to appear.&lt;br /&gt;
    Local $hWnd = WinWait(&amp;quot;[CLASS:Notepad]&amp;quot;, &amp;quot;&amp;quot;, 10)&lt;br /&gt;
&lt;br /&gt;
    ; Wait for 1 second.&lt;br /&gt;
    Sleep(1000)&lt;br /&gt;
&lt;br /&gt;
    ; Shake the Notepad window left to right.&lt;br /&gt;
    _WindowShake($hWnd)&lt;br /&gt;
&lt;br /&gt;
    ; Wait for 1 second.&lt;br /&gt;
    Sleep(1000)&lt;br /&gt;
&lt;br /&gt;
    ; Close the Notepad window using the handle returned by WinWait.&lt;br /&gt;
    WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _WindowShake($sTitle, $sText = &#039;&#039;, $iDistance = 20)&lt;br /&gt;
    Local $hWnd = WinGetHandle($sTitle, $sText)&lt;br /&gt;
    Local $aWinGetPos = WinGetPos($hWnd)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $aArray[5] = [4, $aWinGetPos[0] + $iDistance, $aWinGetPos[0], $aWinGetPos[0] + $iDistance, $aWinGetPos[0]]&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To $aArray[0]&lt;br /&gt;
        WinMove($hWnd, &#039;&#039;, $aArray[$i], Default)&lt;br /&gt;
        Sleep(100)&lt;br /&gt;
    Next&lt;br /&gt;
EndFunc   ;==&amp;gt;_WindowShake&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetDetails ==&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;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $aArray = _WinGetDetails(&#039;[ACTIVE]&#039;) ; Returns the Window&#039;s title, PID, folder path filename.&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    Exit&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&lt;br /&gt;
Func _WinGetDetails($sTitle, $sText = &#039;&#039;) ; Based on code of _WinGetPath by GaryFrost.&lt;br /&gt;
    Local $aReturn[5] = [4, &#039;-WinTitle&#039;, &#039;-PID&#039;, &#039;-FolderPath&#039;, &#039;-FileName&#039;], $aStringSplit&lt;br /&gt;
&lt;br /&gt;
    If StringLen($sText) &amp;gt; 0 Then&lt;br /&gt;
        $aReturn[1] = WinGetTitle($sTitle, $sText)&lt;br /&gt;
    Else&lt;br /&gt;
        $aReturn[1] = WinGetTitle($sTitle)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aReturn[2] = WinGetProcess($aReturn[1])&lt;br /&gt;
&lt;br /&gt;
    Local $oWMIService = ObjGet(&#039;winmgmts:\\.\root\CIMV2&#039;)&lt;br /&gt;
    Local $oItems = $oWMIService.ExecQuery(&#039;Select * From Win32_Process Where ProcessId = &#039; &amp;amp; $aReturn[2], &#039;WQL&#039;, 0x30)&lt;br /&gt;
    If IsObj($oItems) Then&lt;br /&gt;
        For $oItem In $oItems&lt;br /&gt;
            If $oItem.ExecutablePath Then&lt;br /&gt;
                $aStringSplit = StringSplit($oItem.ExecutablePath, &#039;\&#039;)&lt;br /&gt;
                $aReturn[3] = &#039;&#039;&lt;br /&gt;
                For $A = 1 To $aStringSplit[0] - 1&lt;br /&gt;
                    $aReturn[3] &amp;amp;= $aStringSplit[$A] &amp;amp; &#039;\&#039;&lt;br /&gt;
                Next&lt;br /&gt;
                $aReturn[3] = StringTrimRight($aReturn[3], 1)&lt;br /&gt;
                $aReturn[4] = $aStringSplit[$aStringSplit[0]]&lt;br /&gt;
                Return $aReturn&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return SetError(1, 0, $aReturn)&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinGetPath&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetNumeratedClassList ==&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;
; Description: Retrieves the numerated classes from a window.&lt;br /&gt;
&lt;br /&gt;
Func _WinGetNumeratedClassList($sTitle)&lt;br /&gt;
    Local $sClassList = WinGetClassList($sTitle)&lt;br /&gt;
    Local $aClassList = StringSplit($sClassList, @LF)&lt;br /&gt;
    Local $sRetClassList = &amp;quot;&amp;quot;, $sHold_List = &amp;quot;|&amp;quot;&lt;br /&gt;
    Local $aiInHold, $iInHold&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To UBound($aClassList) - 1&lt;br /&gt;
        If $aClassList[$i] = &amp;quot;&amp;quot; Then ContinueLoop&lt;br /&gt;
&lt;br /&gt;
        If StringRegExp($sHold_List, &amp;quot;\|&amp;quot; &amp;amp; $aClassList[$i] &amp;amp; &amp;quot;~(\d+)\|&amp;quot;) Then&lt;br /&gt;
            $aiInHold = StringRegExp($sHold_List, &amp;quot;.*\|&amp;quot; &amp;amp; $aClassList[$i] &amp;amp; &amp;quot;~(\d+)\|.*&amp;quot;, 1)&lt;br /&gt;
            $iInHold = Number($aiInHold[UBound($aiInHold)-1])&lt;br /&gt;
&lt;br /&gt;
            If $iInHold = 0 Then $iInHold += 1&lt;br /&gt;
&lt;br /&gt;
            $aClassList[$i] &amp;amp;= &amp;quot;~&amp;quot; &amp;amp; $iInHold + 1&lt;br /&gt;
            $sHold_List &amp;amp;= $aClassList[$i] &amp;amp; &amp;quot;|&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            $sRetClassList &amp;amp;= $aClassList[$i] &amp;amp; @LF&lt;br /&gt;
        Else&lt;br /&gt;
            $aClassList[$i] &amp;amp;= &amp;quot;~1&amp;quot;&lt;br /&gt;
            $sHold_List &amp;amp;= $aClassList[$i] &amp;amp; &amp;quot;|&amp;quot;&lt;br /&gt;
            $sRetClassList &amp;amp;= $aClassList[$i] &amp;amp; @LF&lt;br /&gt;
        EndIf&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    Return StringReplace(StringStripWS($sRetClassList, 3), &amp;quot;~&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetHandleByPID ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 4813-smoke-n&lt;br /&gt;
| AuthorName = SmOke_N&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Get Window Handle by PID&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $a1 = _WinGetHandleByPID(232)&lt;br /&gt;
Global $a2 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, -1)&lt;br /&gt;
Global $a3 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, 0)&lt;br /&gt;
Global $a4 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, 1)&lt;br /&gt;
&lt;br /&gt;
_ArrayDisplay($a1, &amp;quot;1&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a2, &amp;quot;2&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a3, &amp;quot;3&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a4, &amp;quot;4&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
;$nVisible = -1 &amp;quot;All (Visble or not)&amp;quot;, $nVisible = 0 &amp;quot;Not Visible Only&amp;quot;, $nVisible = 1 &amp;quot;Visible Only&amp;quot;&lt;br /&gt;
Func _WinGetHandleByPID($vProc, $nVisible = 1)&lt;br /&gt;
    $vProc = ProcessExists($vProc);&lt;br /&gt;
&lt;br /&gt;
    If Not $vProc Then Return SetError(1, 0, 0)&lt;br /&gt;
&lt;br /&gt;
    Local $aWL = WinList()&lt;br /&gt;
&lt;br /&gt;
    Local $aTemp[UBound($aWL)][2]&lt;br /&gt;
&lt;br /&gt;
	Local $nAdd = 0&lt;br /&gt;
&lt;br /&gt;
    For $iCC = 1 To $aWL[0][0]&lt;br /&gt;
        If $nVisible = -1 And WinGetProcess($aWL[$iCC][1]) = $vProc Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        ElseIf $nVisible = 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) = 0 Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        ElseIf $nVisible &amp;gt; 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        EndIf&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    If $nAdd = 0 Then Return SetError(2, 0, 0) ; No windows found&lt;br /&gt;
&lt;br /&gt;
    ReDim $aTemp[$nAdd + 1][2]&lt;br /&gt;
&lt;br /&gt;
    $aTemp[0][0] = $nAdd&lt;br /&gt;
&lt;br /&gt;
    Return $aTemp&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_AutoIt_)&amp;diff=12759</id>
		<title>Snippets ( AutoIt )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_AutoIt_)&amp;diff=12759"/>
		<updated>2015-01-16T21:36:12Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* _IsVisible */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
[[category:Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Snippet Credit Header}}&lt;br /&gt;
&lt;br /&gt;
== AutoItWinShow ==&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;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Display AutoIt&#039;s Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.&lt;br /&gt;
    AutoItWinShow()&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Display AutoIt&#039;s Hidden Window. Returns the handle of the window.&lt;br /&gt;
Func AutoItWinShow()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    WinMove($hWnd, &#039;&#039;, (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.&lt;br /&gt;
    WinSetState($hWnd, &#039;&#039;, @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I&#039;m displaying it.&lt;br /&gt;
    Return $hWnd&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinShow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== AutoItWinGetText ==&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;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Display AutoIt&#039;s Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.&lt;br /&gt;
    AutoItWinShow()&lt;br /&gt;
&lt;br /&gt;
    ; Add a text string to AutoIt&#039;s Hidden Window. Compile to see the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    AutoItWinSetText(&#039;Welcome to AutoIt V&#039; &amp;amp; @AutoItVersion &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Add a text string to AutoIt&#039;s Hidden Window. Compile to see the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    AutoItWinSetText(&#039;Windows Type: &#039; &amp;amp; @OSType &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Display the text stored in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, AutoItWinGetText())&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Retrieve the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
Func AutoItWinGetText()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    Return ControlGetText($hWnd, &#039;&#039;, ControlGetHandle($hWnd, &#039;&#039;, &#039;Edit1&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinGetText&lt;br /&gt;
&lt;br /&gt;
; Add text to AutoIt&#039;s Hidden Window.&lt;br /&gt;
Func AutoItWinSetText($sString)&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    Return ControlSetText($hWnd, &amp;quot;&amp;quot;, ControlGetHandle($hWnd, &amp;quot;&amp;quot;, &#039;Edit1&#039;), ControlGetText($hWnd, &#039;&#039;, ControlGetHandle($hWnd, &#039;&#039;, &#039;Edit1&#039;)) &amp;amp; $sString)&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinSetText&lt;br /&gt;
&lt;br /&gt;
; Display AutoIt&#039;s Hidden Window. Returns the handle of the window.&lt;br /&gt;
Func AutoItWinShow()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    WinMove($hWnd, &#039;&#039;, (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.&lt;br /&gt;
    WinSetState($hWnd, &#039;&#039;, @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I&#039;m displaying it.&lt;br /&gt;
    Return $hWnd&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinShow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _DockToWindow ==&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;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If (Not ProcessExists(&amp;quot;SciTE.exe&amp;quot;)) Then&lt;br /&gt;
    Exit MsgBox(4096, &#039;&#039;, &amp;quot;Please start SciTE.exe&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Create a GUI, similar to SciTE Jump&#039;s GUI.&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;, 215, 400, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    ; Dock the first window to left and adjust the width based on the width of the second GUI.&lt;br /&gt;
    _DockToWindow(WinGetHandle(&amp;quot;[CLASS:SciTEWindow]&amp;quot;), $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&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;
&lt;br /&gt;
Func _DockToWindow(Const $hHandle_1, Const $hHandle_2)&lt;br /&gt;
    ; Retrieve the working area, this is minus the taskbar dimensions so slightly different to @DesktopHeight and @DesktopWidth which is the&lt;br /&gt;
    ; monitors height and width.&lt;br /&gt;
    Local Const $SPI_GETWORKAREA = 48&lt;br /&gt;
    Local Const $tWorkArea = DllStructCreate($tagRECT)&lt;br /&gt;
    _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($tWorkArea))&lt;br /&gt;
&lt;br /&gt;
    ; Retieve the position of the second GUI.&lt;br /&gt;
    Local Const $aClientSize_2 = WinGetPos($hHandle_2)&lt;br /&gt;
&lt;br /&gt;
    ; Set the state of the windows to &#039;Restore&#039;.&lt;br /&gt;
    WinSetState($hHandle_1, &#039;&#039;, @SW_RESTORE)&lt;br /&gt;
    WinSetState($hHandle_2, &#039;&#039;, @SW_RESTORE)&lt;br /&gt;
&lt;br /&gt;
    ; Move the first to the far left of the screen and adjust the width to the total screen width minus the width of the second GUI. e.g. 1366 - 215&lt;br /&gt;
    WinMove($hHandle_1, &#039;&#039;, DllStructGetData($tWorkArea, &#039;Left&#039;), DllStructGetData($tWorkArea, &#039;Top&#039;), DllStructGetData($tWorkArea, &#039;Right&#039;) - DllStructGetData($tWorkArea, &#039;Left&#039;) - $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Bottom&#039;) - DllStructGetData($tWorkArea, &#039;Top&#039;))&lt;br /&gt;
&lt;br /&gt;
    ; Move the second window to the far right in between the remaining space and adjust the height of the GUI.&lt;br /&gt;
    WinMove($hHandle_2, &#039;&#039;, DllStructGetData($tWorkArea, &#039;Right&#039;) - DllStructGetData($tWorkArea, &#039;Left&#039;) - $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Top&#039;), $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Bottom&#039;) - DllStructGetData($tWorkArea, &#039;Top&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;_DockToWindow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FuncExists ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 52-geosoft&lt;br /&gt;
| AuthorName = GEOSoft&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox(0, &amp;quot;TEST&amp;quot;, &amp;quot;Function Exists = &amp;quot; &amp;amp; _FuncExists(&amp;quot;_FuncExists&amp;quot;, @ScriptFullPath))&lt;br /&gt;
&lt;br /&gt;
Func _FuncExists($sFunc, $sPath)&lt;br /&gt;
   If Not FileExists($sPath) Then Return SetError(1)&lt;br /&gt;
   Local Const $sStr = FileRead($sPath)&lt;br /&gt;
   Local Const $sRegEx = &amp;quot;(?i)(?m:^|\n)\s*Func\s+(&amp;quot; &amp;amp; $sFunc &amp;amp; &amp;quot;)\s*\(&amp;quot;&lt;br /&gt;
   Local Const $aRegEx = StringRegExp($sStr, $sRegEx, 1)&lt;br /&gt;
   If IsArray($aRegEx) Then Return 1&lt;br /&gt;
   Return 0&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FunctionSort ==&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;
; Get the list of Functions in a script and sort by alphabetical order.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;String.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local $sFile = FileOpenDialog(@ScriptName, &amp;quot;Select an AutoIt file.&amp;quot;, &amp;quot;Au3 (*.au3)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    Exit&lt;br /&gt;
EndIf&lt;br /&gt;
ClipPut(_FunctionSort($sFile))&lt;br /&gt;
&lt;br /&gt;
Func _FunctionSort($sFilePath)&lt;br /&gt;
    Local Const $sRead = FileRead($sFilePath)&lt;br /&gt;
&lt;br /&gt;
	Local $aReturn = StringRegExp(&amp;quot;Func _Count()&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;EndFunc ;==&amp;gt;_Count&amp;quot; &amp;amp; $sRead, &#039;(?s)(?i)Func(.*?)EndFunc&#039;, 3)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    $aReturn[0] = UBound($aReturn, 1) - 1&lt;br /&gt;
&lt;br /&gt;
    _ArraySort($aReturn, 0, 1)&lt;br /&gt;
&lt;br /&gt;
    Local $sReturn&lt;br /&gt;
&lt;br /&gt;
    For $A = 1 To $aReturn[0]&lt;br /&gt;
        $sReturn &amp;amp;= &amp;quot;Func&amp;quot; &amp;amp; $aReturn[$A] &amp;amp; &amp;quot;EndFunc&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    Return $sReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_FunctionSort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsBeta ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 10673-mlipok&lt;br /&gt;
| AuthorName = mLipok&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;
#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;
    Local $aTest[10]&lt;br /&gt;
    _ArrayUnique($aTest, 0, 5)&lt;br /&gt;
    Local $iError = @error&lt;br /&gt;
    ConsoleWrite(&#039;$iError = &#039; &amp;amp; $iError &amp;amp; @CRLF)&lt;br /&gt;
    If _IsBeta() Then&lt;br /&gt;
        If $iError = 3 Then&lt;br /&gt;
            MsgBox($MB_SYSTEMMODAL, &#039;@error&#039;, &#039;3 - $iBase or $iCase contains an invalid value&#039; &amp;amp; @CRLF &amp;amp; @AutoItVersion)&lt;br /&gt;
        EndIf&lt;br /&gt;
    Else&lt;br /&gt;
        If $iError = 2 Then&lt;br /&gt;
            MsgBox($MB_SYSTEMMODAL, &#039;@error&#039;, &#039;2 - $iBase or $iCase contains an invalid value&#039; &amp;amp; @CRLF &amp;amp; @AutoItVersion)&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _IsBeta()&lt;br /&gt;
       Return Mod(StringSplit(@AutoItVersion, &#039;.&#039;)[3], 2) == 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsBeta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsButton ==&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;ButtonConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;Constants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    Local Const $iLabel = GUICtrlCreateButton(&#039;&#039;, 0, 0, 50, 50)&lt;br /&gt;
    Local Const $iCheckbox = GUICtrlCreateCheckbox(&#039;&#039;, 0, 0, 100, 20) ; This is considered a &#039;Button&#039; by _WinAPI_GetClassName too.&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;AutoIt Button ID: &#039; &amp;amp; _IsButton($iLabel) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Button Handle: &#039; &amp;amp; _IsButton(GUICtrlGetHandle($iLabel)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Checkbox ID: &#039; &amp;amp; _IsButton($iCheckbox) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Checkbox Handle: &#039; &amp;amp; _IsButton(GUICtrlGetHandle($iCheckbox)) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    Return GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Check if a variable is referencing a Button control.&lt;br /&gt;
Func _IsButton($hWnd)&lt;br /&gt;
    If IsHWnd($hWnd) = 0 Then&lt;br /&gt;
        $hWnd = GUICtrlGetHandle($hWnd)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Local Const $sClassName = _WinAPI_GetClassName($hWnd)&lt;br /&gt;
&lt;br /&gt;
    If $sClassName = &#039;Button&#039; Then&lt;br /&gt;
        Local Const $aStyle[5] = [4, $BS_CHECKBOX, $BS_AUTOCHECKBOX, $BS_RADIOBUTTON, $BS_AUTORADIOBUTTON]&lt;br /&gt;
&lt;br /&gt;
        Local Const $iLong = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)&lt;br /&gt;
&lt;br /&gt;
		For $i = 1 To $aStyle[0]&lt;br /&gt;
            If BitAND($iLong, $aStyle[$i]) = $aStyle[$i] Then&lt;br /&gt;
                Return False&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
&lt;br /&gt;
        Return True&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return False&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsButton&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsControlID ==&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 if a Control ID is a native AutoIt control.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;GUIListView.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    Local Const $iControlID = GUICtrlCreateLabel(&#039;&#039;, 0, 0, 500, 500)&lt;br /&gt;
    Local Const $hListView = _GUICtrlListView_Create($hGUI, &#039;Example&#039;, 0, 0, 500, 500)&lt;br /&gt;
&lt;br /&gt;
	GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;AutoIt ControlID: &#039; &amp;amp; _IsControlID($iControlID) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;Random Number: &#039; &amp;amp; _IsControlID(Random(42, 99, 1)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt ControlID Handle: &#039; &amp;amp; _IsControlID(GUICtrlGetHandle($iControlID)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;ListView UDF Handle: &#039; &amp;amp; _IsControlID($hListView) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;ListView UDF Handle: &#039; &amp;amp; _IsControlID(GUICtrlGetHandle($hListView)) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    _GUICtrlListView_Destroy($hListView)&lt;br /&gt;
&lt;br /&gt;
    Return GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _IsControlID($iControlID)&lt;br /&gt;
    If IsHWnd($iControlID) Then&lt;br /&gt;
        $iControlID = _WinAPI_GetDlgCtrlID($iControlID)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return IsHWnd(GUICtrlGetHandle($iControlID)) = 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsControlID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItIncludesFromSciTE ==&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;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetAutoItIncludesFromSciTE() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Retrieve the AutoIt includes path from the SciTE process.&lt;br /&gt;
Func _GetAutoItIncludesFromSciTE()&lt;br /&gt;
    Local $sRelativePath = &#039;..\Include&#039;&lt;br /&gt;
	Local Const $sWorkingDir = @WorkingDir&lt;br /&gt;
    FileChangeDir(_WinAPI_PathRemoveFileSpec(_WinAPI_GetProcessFileName(ProcessExists(&#039;SciTE.exe&#039;))))&lt;br /&gt;
    $sRelativePath = _WinAPI_GetFullPathName($sRelativePath)&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return _WinAPI_PathRemoveBackslash($sRelativePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItIncludesFromSciTE&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstall ==&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;
; Get the AutoIt installation folder.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetAutoItInstall() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetAutoItInstall()&lt;br /&gt;
    Return StringLeft(@AutoItExe, StringInStr(@AutoItExe, &amp;quot;\&amp;quot;, 2, -1) - 1)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstall&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstallEx ==&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(_GetAutoItInstallEx() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the installation of AutoIt. An improved version of _GetAutoItInstall.&lt;br /&gt;
Func _GetAutoItInstallEx()&lt;br /&gt;
    Local $aWow6432Node[2] = [&#039;&#039;, &#039;Wow6432Node\&#039;], $aFiles[4] = [3, @ProgramFilesDir, EnvGet(&amp;quot;PROGRAMFILES&amp;quot;), EnvGet(&amp;quot;PROGRAMFILES(X86)&amp;quot;)]&lt;br /&gt;
    Local $sFilePath = RegRead(&#039;HKEY_LOCAL_MACHINE\SOFTWARE\&#039; &amp;amp; $aWow6432Node[@AutoItX64] &amp;amp; &#039;AutoIt v3\AutoIt\&#039;, &#039;InstallDir&#039;)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        For $A = 1 To $aFiles[0]&lt;br /&gt;
            $aFiles[$A] &amp;amp;= &#039;\AutoIt&#039;&lt;br /&gt;
            If FileExists($aFiles[$A]) Then&lt;br /&gt;
                Return $aFiles[$A]&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
        Return SetError(1, 0, &#039;&#039;)&lt;br /&gt;
    Else&lt;br /&gt;
        Return $sFilePath&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstallEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstallFromSciTE ==&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(_GetAutoItInstallFromSciTE() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Retrieve the AutoIt installation path from the SciTE process.&lt;br /&gt;
Func _GetAutoItInstallFromSciTE()&lt;br /&gt;
    Local $sRelativePath = &#039;..\&#039;, $sWorkingDir = @WorkingDir&lt;br /&gt;
    FileChangeDir( _WinAPI_PathRemoveFileSpec(_WinAPI_GetProcessFileName(ProcessExists(&amp;quot;SciTE.exe&amp;quot;))))&lt;br /&gt;
    $sRelativePath = _WinAPI_GetFullPathName($sRelativePath)&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return _WinAPI_PathRemoveBackslash($sRelativePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstallFromSciTE&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetClasses ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 24-cyberslug&lt;br /&gt;
| AuthorName = CyberSlug&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Get ALL Controls Info&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
	; Run Calculator&lt;br /&gt;
	Run(&amp;quot;calc.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	; Wait 10 seconds for the Calculator window to appear.&lt;br /&gt;
	Local const $hWnd = WinWait(&amp;quot;[CLASS:CalcFrame]&amp;quot;, &#039;&#039;, 10)&lt;br /&gt;
&lt;br /&gt;
	; Retrieve a list of all the controls in the Calculator window using the handle returned by WinWait.&lt;br /&gt;
	MsgBox(4096, &#039;&#039;, _GetClasses($hWnd))&lt;br /&gt;
&lt;br /&gt;
	; Close the Calculator window using the handle returned by WinWait.&lt;br /&gt;
	WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; This function returns an @LF-separated list of controls on the specified window.&lt;br /&gt;
Func _GetClasses($sTitle, $sText = &#039;&#039;)&lt;br /&gt;
	Local $iCount_Button = 0, $iCount_Edit = 0, $iCount_Static = 0&lt;br /&gt;
	Local $aClasses = StringSplit(WinGetClassList($sTitle, $sText), @LF)&lt;br /&gt;
	Local $aClassID[$aClasses[0] + 1] = [$aClasses[0]]&lt;br /&gt;
&lt;br /&gt;
	For $i = 1 To $aClasses[0]&lt;br /&gt;
		Select&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Button&amp;quot;&lt;br /&gt;
				$iCount_Button += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Button&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Edit&amp;quot;&lt;br /&gt;
				$iCount_Edit += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Edit&lt;br /&gt;
				$aClasses[$i] = &amp;quot;Input&amp;quot;&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Static&amp;quot;&lt;br /&gt;
				$iCount_Static += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Static&lt;br /&gt;
				$aClasses[$i] = &amp;quot;Label&amp;quot;&lt;br /&gt;
			Case Else&lt;br /&gt;
				If $aClasses[$i] &amp;lt;&amp;gt; &amp;quot;&amp;quot; Then&lt;br /&gt;
					$aClassID[$i] = $aClasses[$i] &amp;amp; &amp;quot;?&amp;quot;&lt;br /&gt;
				EndIf&lt;br /&gt;
		EndSelect&lt;br /&gt;
	Next&lt;br /&gt;
&lt;br /&gt;
	; Combine the results.&lt;br /&gt;
	Local $sReturn = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	For $i = 1 To $aClassID[0]&lt;br /&gt;
		$sReturn &amp;amp;= $aClassID[$i] &amp;amp; @LF&lt;br /&gt;
	Next&lt;br /&gt;
&lt;br /&gt;
	Return $sReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetClasses&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFile ==&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;
; FileRead Alternative&lt;br /&gt;
&lt;br /&gt;
Func _GetFile($sFile, $iFormat = 0)&lt;br /&gt;
    Local $hFileOpen = FileOpen($sFile, $iFormat)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(1, 0, &amp;quot;&amp;quot;)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $sData = FileRead($hFileOpen)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
    Return $sData&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetTitle ==&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;
; Get the title of your program.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetTitle(&#039;Example&#039;) &amp;amp; @CRLF)&lt;br /&gt;
; The second parameter would normally be @ScriptDir &amp;amp; &#039;\Uninstall.exe&#039; for example, but for this demonstration I&#039;m using the full path.&lt;br /&gt;
ConsoleWrite(_GetTitle(&#039;Example&#039;, @ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetTitle($sProgramName, $sInstallPath = &#039;&#039;)&lt;br /&gt;
    Local $aOSArch[2] = [&#039;&#039;, &#039; (64-bit)&#039;], $aPortable[2] = [&#039; (Portable)&#039;, &#039;&#039;]&lt;br /&gt;
    Return $sProgramName &amp;amp; $aOSArch[@AutoItX64] &amp;amp; $aPortable[FileExists($sInstallPath)]&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetTitle&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetXML ==&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;
; Simple Way Of Parsing XML Data.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $aReturn, $sXMLData&lt;br /&gt;
&lt;br /&gt;
$sXMLData = &amp;quot;&amp;lt;data&amp;gt;This is a Simple example of XML&amp;lt;/data&amp;gt;&amp;lt;data&amp;gt;This is a Simple example of XML and is the Second String.&amp;lt;/data&amp;gt;&amp;quot;&lt;br /&gt;
$aReturn = _GetXML($sXMLData, &amp;quot;data&amp;quot;)&lt;br /&gt;
_ArrayDisplay($aReturn, &amp;quot;_GetXML()&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _GetXML($sString, $sData)&lt;br /&gt;
    Local $aError[2] = [1, $sString], $aReturn&lt;br /&gt;
    $aReturn = StringRegExp(&#039;&amp;lt;&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&amp;lt;/&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&#039; &amp;amp; $sString, &#039;(?s)(?i)&amp;lt;&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;(.*?)&amp;lt;/&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&#039;, 3)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $aError)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aReturn[0] = UBound($aReturn, 1) - 1&lt;br /&gt;
    Return SetError(0, 0, $aReturn)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetXML&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Include Source With Exe ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 54985-jlogan3o13&lt;br /&gt;
| AuthorName = JLogan3o13&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;recover source .au3 file with /Extract switch&lt;br /&gt;
; The above code would be copied into the top of your script. The source location (C:\Test.au3 in my example) is the full path to your script file.&lt;br /&gt;
;Once compiled, if you run the script from the Run line with the /Extract switch, it will extact the original .au3 file into the Temp directory and will exit without actually executing the script.&lt;br /&gt;
If StringInStr($cmdlineRaw, &amp;quot;/Extract&amp;quot;) Then&lt;br /&gt;
	FileInstall(&amp;quot;C:\Test.au3&amp;quot;, @TempDir &amp;amp; &amp;quot;\Test.au3&amp;quot;, 1)&lt;br /&gt;
	Exit&lt;br /&gt;
EndIf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsANSIFile ==&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;FileConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_IsANSIFile(@ScriptFullPath) &amp;amp; @LF) ; Returns True.&lt;br /&gt;
&lt;br /&gt;
Func _IsANSIFile($sFilePath)&lt;br /&gt;
    Return FileGetEncoding($sFilePath) = $FO_READ&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsUnicodeFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsUnicodeFile ==&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;FileConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_IsUnicodeFile(@ScriptFullPath) &amp;amp; @LF) ; Returns False.&lt;br /&gt;
&lt;br /&gt;
Func _IsUnicodeFile($sFilePath)&lt;br /&gt;
    Return FileGetEncoding($sFilePath) = $FO_UNICODE&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsUnicodeFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsAu3File ==&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(_IsAu3File(@AutoItExe) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_IsAu3File(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Checks whether the filepath is an au3 file.&lt;br /&gt;
Func _IsAu3File($sFilePath)&lt;br /&gt;
    Return StringTrimLeft($sFilePath, StringInStr($sFilePath, &amp;quot;.&amp;quot;, 2, -1)) = &amp;quot;au3&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsAu3File&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsDefault ==&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;
If _IsDefault(Default) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 1&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
If _IsDefault(-1) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 2&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
If _IsDefault(&amp;quot;Other&amp;quot;) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 3&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
Func _IsDefault($sDefault)&lt;br /&gt;
    Return StringRegExp($sDefault, &amp;quot;(?-i)\s|Default|-1|0&amp;quot;)&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsDefault&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsInTrial ==&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;Date.au3&amp;gt; ; Required for _DateDiff()&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;Date trial started: &#039; &amp;amp; @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/01&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Today&#039;&#039;s date: &#039; &amp;amp; @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/&#039; &amp;amp; @MDAY &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Trial period: 30 days&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Is the trial period still valid: &#039; &amp;amp; _IsInTrial(@YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/01&#039;, 30) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a trial period date is still valid.&lt;br /&gt;
Func _IsInTrial($sDateString, $iDays) ; Based on the idea found here: http://www.autoitscript.com/forum/topic/...ial-time/page__view__findpost_&lt;br /&gt;
    Return (_DateDiff(&#039;D&#039;, $sDateString, @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/&#039; &amp;amp; @MDAY) &amp;lt; $iDays)&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsInTrial&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsVisible ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = none&lt;br /&gt;
| AuthorName = Multiple&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Check if the Notepad Window is visible.&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Run Notepad&lt;br /&gt;
    Run(&amp;quot;notepad.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    ; Wait 10 seconds for the Notepad window to appear.&lt;br /&gt;
    Local $hWnd = WinWait(&amp;quot;[CLASS:Notepad]&amp;quot;, &amp;quot;&amp;quot;, 10)&lt;br /&gt;
&lt;br /&gt;
    ; Check if the Notepad window is visible and display the appropriate message box.&lt;br /&gt;
    If _IsVisible($hWnd) Then&lt;br /&gt;
        MsgBox(4096, &amp;quot;&amp;quot;, &amp;quot;Notepad is visible.&amp;quot;)&lt;br /&gt;
    Else&lt;br /&gt;
        MsgBox(4096, &amp;quot;&amp;quot;, &amp;quot;Notepad isn&#039;t visible.&amp;quot;)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    ; Close the Notepad window using the handle returned by WinWait.&lt;br /&gt;
    WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Check if the window is visible.&lt;br /&gt;
Func _IsVisible($hWnd)&lt;br /&gt;
    Return BitAND(WinGetState($hWnd), 2) = 2&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsVisible&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Open Help File to Desired Page ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 1967-garyfrost&lt;br /&gt;
| AuthorName = GaryFrost&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Open help file / Open a desired page&lt;br /&gt;
&lt;br /&gt;
Global Const $sAutoItPath = RegRead(&amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt&amp;quot;, &amp;quot;InstallDir&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Run(@WindowsDir &amp;amp; &amp;quot;\hh.exe &amp;quot; &amp;amp; $sAutoItPath &amp;amp; &amp;quot;\AutoIt3.chm::/html/functions/GUICtrlCreateUpdown.htm&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _RunAU3 ==&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;
_RunAU3(&amp;quot;AU3_Example.txt&amp;quot;, &#039;&amp;quot;This is a commandline example!&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
Func _RunAU3($sFilePath,  $sCommandLine = &amp;quot;&amp;quot;, $sWorkingDir = &amp;quot;&amp;quot;, $iShowFlag = @SW_SHOW, $iOptFlag = 0)&lt;br /&gt;
    Return Run(&#039;&amp;quot;&#039; &amp;amp; @AutoItExe &amp;amp; &#039;&amp;quot; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; $sCommandLine, $sWorkingDir, $iShowFlag, $iOptFlag)&lt;br /&gt;
EndFunc   ;==&amp;gt;_RunAU3&lt;br /&gt;
&lt;br /&gt;
Func _RunWaitAU3($sFilePath, $sCommandLine = &amp;quot;&amp;quot;, $sWorkingDir = &amp;quot;&amp;quot;, $iShowFlag = @SW_SHOW, $iOptFlag = 0)&lt;br /&gt;
    Local $iPID&lt;br /&gt;
    $iPID = RunWait(&#039;&amp;quot;&#039; &amp;amp; @AutoItExe &amp;amp; &#039;&amp;quot; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; $sCommandLine, $sWorkingDir, $iShowFlag, $iOptFlag)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(@error, 1, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $iPID&lt;br /&gt;
EndFunc   ;==&amp;gt;_RunWaitAU3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Run Any au3 File From Your Program ==&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;
; Run Any Au3 File From Your Program&lt;br /&gt;
&lt;br /&gt;
Global Const $sFilePath = @ScriptDir &amp;amp; &amp;quot;\Test.au3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If @Compiled Then&lt;br /&gt;
	Global Const $sFileExe = FileGetShortName(@AutoItExe &amp;amp; &#039; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot;&#039;)&lt;br /&gt;
	Run($sFileExe)&lt;br /&gt;
Else&lt;br /&gt;
	Global Const $sFileAu3 = FileGetShortName($sFilePath)&lt;br /&gt;
	Run(@AutoItExe &amp;amp; &amp;quot; &amp;quot; &amp;amp; $sFileAu3, &amp;quot;&amp;quot;, @SW_HIDE)&lt;br /&gt;
EndIf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ScriptName ==&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(_ScriptName() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Return the @ScriptName minus the .exe or .au3 extension.&lt;br /&gt;
Func _ScriptName()&lt;br /&gt;
	Return StringLeft(@ScriptName, StringInStr(@ScriptName, &#039;.&#039;, 2, -1) - 1)&lt;br /&gt;
EndFunc   ;==&amp;gt;_ScriptName&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ScriptVersion ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 31149-milesahead&lt;br /&gt;
| AuthorName = MilesAhead&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#NoTrayIcon&lt;br /&gt;
&lt;br /&gt;
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****&lt;br /&gt;
#AutoIt3Wrapper_UseUpx=n&lt;br /&gt;
#AutoIt3Wrapper_Res_Fileversion=1.2.3.4&lt;br /&gt;
#AutoIt3Wrapper_Res_LegalCopyright=2012  www.favessoft.com&lt;br /&gt;
#AutoIt3Wrapper_Res_Language=1033&lt;br /&gt;
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&lt;br /&gt;
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****&lt;br /&gt;
&lt;br /&gt;
Global $version = _ScriptVersion()&lt;br /&gt;
&lt;br /&gt;
Global $msg = &amp;quot;ScriptVerDemo&amp;quot; &amp;amp; &amp;quot; &amp;quot; &amp;amp; $version &amp;amp; &amp;quot;  Copyright (c) 2012  www.favessoft.com&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF&lt;br /&gt;
&lt;br /&gt;
MsgBox(0x1040, &amp;quot;&amp;quot;, $msg)&lt;br /&gt;
&lt;br /&gt;
; return File Version string from compiled or .au3 script&lt;br /&gt;
; returns &amp;quot;&amp;quot; if no version info available&lt;br /&gt;
; Note: The .au3 script must contain #AutoItWrapper&lt;br /&gt;
; directives with file version or &amp;quot;&amp;quot; is returned.&lt;br /&gt;
Func _ScriptVersion(Const $Script = @ScriptFullPath)&lt;br /&gt;
    If StringRight($Script,4) = &amp;quot;.exe&amp;quot; Then&lt;br /&gt;
        Return FileGetVersion($Script)&lt;br /&gt;
    Else&lt;br /&gt;
        Local Const $scriptHandle = FileOpen($Script)&lt;br /&gt;
		Local $ver&lt;br /&gt;
		Local $found = False&lt;br /&gt;
		Local $pos&lt;br /&gt;
&lt;br /&gt;
        If $scriptHandle &amp;lt;&amp;gt; -1 Then&lt;br /&gt;
            Do&lt;br /&gt;
                $ver = FileReadLine($scriptHandle)&lt;br /&gt;
                $sPos = StringInStr($ver, &amp;quot;_Fileversion=&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
                If $sPos Then&lt;br /&gt;
                    $ver = StringMid($ver, $sPos + StringLen(&amp;quot;_Fileversion=&amp;quot;))&lt;br /&gt;
                    $found = True&lt;br /&gt;
                    ExitLoop&lt;br /&gt;
                EndIf&lt;br /&gt;
            Until StringLeft($ver, 1) &amp;lt;&amp;gt; &amp;quot;#&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            FileClose($scriptHandle)&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    If Not $found Then $ver = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    Return $ver&lt;br /&gt;
EndFunc   ;==&amp;gt;_ScriptVersion&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SetFile ==&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;
; FileWrite Alternative&lt;br /&gt;
&lt;br /&gt;
Func _SetFile(Const $sString, Const $sFile, Const $iOverwrite = 0)&lt;br /&gt;
    Local Const $hFileOpen = FileOpen($sFile, $iOverwrite + 1)&lt;br /&gt;
&lt;br /&gt;
    FileWrite($hFileOpen, $sString)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $sString)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return $sString&lt;br /&gt;
EndFunc   ;==&amp;gt;_SetFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ShowHelp ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 60350-chimaera&lt;br /&gt;
| AuthorName = Chimaera&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
HotKeySet(&amp;quot;{F1}&amp;quot;, &amp;quot;_ShowHelp&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _ShowHelp()&lt;br /&gt;
	Return ShellExecute(@ProgramFilesDir &amp;amp; &amp;quot;\AutoIt3\AutoIt3Help.exe&amp;quot;) ; change this to the location of your own helpfile.&lt;br /&gt;
EndFunc   ;==&amp;gt;_ShowHelp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SingletonPID ==&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;
Local $iSingleton = _SingletonPID(&#039;RandomName&#039;, 1)&lt;br /&gt;
&lt;br /&gt;
If $iSingleton = 0 Then&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;This is the first instance of the program running: &#039; &amp;amp; $iSingleton)&lt;br /&gt;
Else&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;There is another instance running. This PID is: &#039; &amp;amp; $iSingleton)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name ..........: _SingletonPID&lt;br /&gt;
; Description ...: Enforce a design paradigm where only one instance of the script may be running.&lt;br /&gt;
; Syntax ........: _SingletonPID($sOccurenceName[, $iFlag = 0])&lt;br /&gt;
; Parameters ....: $sOccurenceName      - String to identify the occurrence of the script.&lt;br /&gt;
;                  $iFlag               - [optional] Optional parameters. Default is 0.&lt;br /&gt;
;                  0 - Exit the script with the exit code -1 if another instance already exists.&lt;br /&gt;
;                  1 - Return the PID of the main executable and without exiting the script too.&lt;br /&gt;
; Return values .: Success - 0 No other process is running.&lt;br /&gt;
;                  Failure - The PID of the main executable.&lt;br /&gt;
; Author ........: guinness with initial ideas by Valik for _Singleton &amp;amp; KaFu for _EnforceSingleInstance.&lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _SingletonPID(Const $sOccurenceName, Const $iFlag = 0)&lt;br /&gt;
    Local $hHandle = WinGetHandle($sOccurenceName)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        AutoItWinSetTitle($sOccurenceName)&lt;br /&gt;
        $hHandle = WinGetHandle($sOccurenceName)&lt;br /&gt;
        ControlSetText($hHandle, &#039;&#039;, ControlGetHandle($hHandle, &#039;&#039;, &#039;Edit1&#039;), @AutoItPID)&lt;br /&gt;
    Else&lt;br /&gt;
        If BitAND($iFlag, 1) Then&lt;br /&gt;
            Return Number(ControlGetText($hHandle, &#039;&#039;, ControlGetHandle($hHandle, &#039;&#039;, &#039;Edit1&#039;)))&lt;br /&gt;
        Else&lt;br /&gt;
            Exit -1&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_SingletonPID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _Sort ==&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(_Sort(&amp;quot;$sVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$iVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$tVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$pVariable&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
Func _Sort(Const $sSortList)&lt;br /&gt;
    Local Const $iPID = Run(&amp;quot;sort.exe&amp;quot;, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD), $sOutput = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    StdinWrite($iPID, $sSortList)&lt;br /&gt;
    StdinWrite($iPID)&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;_Sort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Speak Object and Save to WAV File ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 52278-solidsnake26&lt;br /&gt;
| AuthorName = SolidSnake26&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Speak Object and save to wav file&lt;br /&gt;
&lt;br /&gt;
_SpeakToWAV(&amp;quot;AutoIt Snippets&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\SavedFile.wav&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _SpeakToWAV(Const $sText, Const $sFilePath)&lt;br /&gt;
	Local $ObjVoice = ObjCreate(&amp;quot;Sapi.SpVoice&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	Local $ObjFile = ObjCreate(&amp;quot;Sapi.SpFileStream.1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	$ObjVoice.Speak($sText)&lt;br /&gt;
&lt;br /&gt;
	$ObjFile.Open($sFilePath, 3)&lt;br /&gt;
&lt;br /&gt;
	$ObjVoice.AudioOutputStream = $ObjFile&lt;br /&gt;
EndFunc   ;==&amp;gt;_SpeakToWAV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _VariableSwap ==&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;
Global $sString_1 = &#039;This is string 1.&#039;&lt;br /&gt;
Global $sString_2 = &#039;This is string 2.&#039;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;$sString_1: &#039; &amp;amp; $sString_1 &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(&#039;$sString_2: &#039; &amp;amp; $sString_2 &amp;amp; @CRLF &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
_VariableSwap($sString_1, $sString_2)&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;$sString_1: &#039; &amp;amp; $sString_1 &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(&#039;$sString_2: &#039; &amp;amp; $sString_2 &amp;amp; @CRLF &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Swap the contents of two variables.&lt;br /&gt;
Func _VariableSwap(ByRef $vVariable_1, ByRef $vVariable_2) ; Similar to _ArraySwap though not obvious to some this isn&#039;t limited to arrays.&lt;br /&gt;
    Local Const $vTemp = $vVariable_1&lt;br /&gt;
    $vVariable_1 = $vVariable_2&lt;br /&gt;
    $vVariable_2 = $vTemp&lt;br /&gt;
EndFunc   ;==&amp;gt;_VariableSwap&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_CharLower ==&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(_WinAPI_CharLower(&amp;quot;EXAMPLE&amp;quot;) &amp;amp; @CRLF) ; Similar to StringLower.&lt;br /&gt;
&lt;br /&gt;
; Convert characters to lowercase.&lt;br /&gt;
Func _WinAPI_CharLower($sString)&lt;br /&gt;
    Local $aReturn = DllCall(&#039;user32.dll&#039;, &#039;wstr&#039;, &#039;CharLowerW&#039;, &#039;wstr&#039;, $sString)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $sString)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_CharLower&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_CharUpper ==&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(_WinAPI_CharUpper(&amp;quot;example&amp;quot;) &amp;amp; @CRLF) ; Similar to StringUpper.&lt;br /&gt;
&lt;br /&gt;
; Convert characters to uppercase.&lt;br /&gt;
Func _WinAPI_CharUpper($sString)&lt;br /&gt;
	Local $aReturn = DllCall(&#039;user32.dll&#039;, &#039;wstr&#039;, &#039;CharUpperW&#039;, &#039;wstr&#039;, $sString)&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Return SetError(1, 0, $sString)&lt;br /&gt;
	EndIf&lt;br /&gt;
	Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_CharUpper&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_PathFileExists ==&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;
; An API Alternative To FileExist.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(@ScriptFullPath) &amp;amp; @LF) ; File.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(&amp;quot;C:\&amp;quot;) &amp;amp; @LF) ; Drive.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(@ProgramFilesDir) &amp;amp; @LF) ; Directory.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(&amp;quot;Z:\File.txt&amp;quot;) &amp;amp; @LF) ; Shouldn&#039;t exist!&lt;br /&gt;
&lt;br /&gt;
Func _WinAPI_PathFileExists($sFilePath)&lt;br /&gt;
    Local $aReturn = DllCall(&#039;shlwapi.dll&#039;, &#039;int&#039;, &#039;PathFileExistsW&#039;, &#039;wstr&#039;, $sFilePath)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_PathFileExists&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinActiveByExe ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 4813-smoke-n&lt;br /&gt;
| AuthorName = SmOke_N&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Window Active/Activate by Exe, Open Notepad whilst script is running&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
    If _WinActiveByExe(&#039;notepad.exe&#039;, False) Then MsgBox(64, &#039;info&#039;, &#039;true&#039;)&lt;br /&gt;
    Sleep(100)&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func _WinActiveByExe($sExe, $iActive = True);False to WinActivate, True to just see if it&#039;s active&lt;br /&gt;
    If Not ProcessExists($sExe) Then Return SetError(1, 0, 0)&lt;br /&gt;
    Local $aPL = ProcessList($sExe)&lt;br /&gt;
    Local $aWL = WinList()&lt;br /&gt;
    For $iCC = 1 To $aWL[0][0]&lt;br /&gt;
        For $xCC = 1 To $aPL[0][0]&lt;br /&gt;
            If $aWL[$iCC][0] &amp;lt;&amp;gt; &#039;&#039; And _&lt;br /&gt;
                WinGetProcess($aWL[$iCC][1]) = $aPL[$xCC][1] And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) Then&lt;br /&gt;
                If $iActive And WinActive($aWL[$iCC][1]) Then Return 1&lt;br /&gt;
                If Not $iActive And Not WinActive($aWL[$iCC][1]) Then&lt;br /&gt;
                    WinActivate($aWL[$iCC][1])&lt;br /&gt;
                    Return 1&lt;br /&gt;
                EndIf&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
    Next&lt;br /&gt;
    Return SetError(2, 0, 0)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WindowShake ==&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;
; Shake a window left to right.&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Run Notepad&lt;br /&gt;
    Run(&amp;quot;notepad.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    ; Wait 10 seconds for the Notepad window to appear.&lt;br /&gt;
    Local $hWnd = WinWait(&amp;quot;[CLASS:Notepad]&amp;quot;, &amp;quot;&amp;quot;, 10)&lt;br /&gt;
&lt;br /&gt;
    ; Wait for 1 second.&lt;br /&gt;
    Sleep(1000)&lt;br /&gt;
&lt;br /&gt;
    ; Shake the Notepad window left to right.&lt;br /&gt;
    _WindowShake($hWnd)&lt;br /&gt;
&lt;br /&gt;
    ; Wait for 1 second.&lt;br /&gt;
    Sleep(1000)&lt;br /&gt;
&lt;br /&gt;
    ; Close the Notepad window using the handle returned by WinWait.&lt;br /&gt;
    WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _WindowShake($sTitle, $sText = &#039;&#039;, $iDistance = 20)&lt;br /&gt;
    Local $hWnd = WinGetHandle($sTitle, $sText)&lt;br /&gt;
    Local $aWinGetPos = WinGetPos($hWnd)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $aArray[5] = [4, $aWinGetPos[0] + $iDistance, $aWinGetPos[0], $aWinGetPos[0] + $iDistance, $aWinGetPos[0]]&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To $aArray[0]&lt;br /&gt;
        WinMove($hWnd, &#039;&#039;, $aArray[$i], Default)&lt;br /&gt;
        Sleep(100)&lt;br /&gt;
    Next&lt;br /&gt;
EndFunc   ;==&amp;gt;_WindowShake&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetDetails ==&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;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $aArray = _WinGetDetails(&#039;[ACTIVE]&#039;) ; Returns the Window&#039;s title, PID, folder path filename.&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    Exit&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&lt;br /&gt;
Func _WinGetDetails($sTitle, $sText = &#039;&#039;) ; Based on code of _WinGetPath by GaryFrost.&lt;br /&gt;
    Local $aReturn[5] = [4, &#039;-WinTitle&#039;, &#039;-PID&#039;, &#039;-FolderPath&#039;, &#039;-FileName&#039;], $aStringSplit&lt;br /&gt;
&lt;br /&gt;
    If StringLen($sText) &amp;gt; 0 Then&lt;br /&gt;
        $aReturn[1] = WinGetTitle($sTitle, $sText)&lt;br /&gt;
    Else&lt;br /&gt;
        $aReturn[1] = WinGetTitle($sTitle)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aReturn[2] = WinGetProcess($aReturn[1])&lt;br /&gt;
&lt;br /&gt;
    Local $oWMIService = ObjGet(&#039;winmgmts:\\.\root\CIMV2&#039;)&lt;br /&gt;
    Local $oItems = $oWMIService.ExecQuery(&#039;Select * From Win32_Process Where ProcessId = &#039; &amp;amp; $aReturn[2], &#039;WQL&#039;, 0x30)&lt;br /&gt;
    If IsObj($oItems) Then&lt;br /&gt;
        For $oItem In $oItems&lt;br /&gt;
            If $oItem.ExecutablePath Then&lt;br /&gt;
                $aStringSplit = StringSplit($oItem.ExecutablePath, &#039;\&#039;)&lt;br /&gt;
                $aReturn[3] = &#039;&#039;&lt;br /&gt;
                For $A = 1 To $aStringSplit[0] - 1&lt;br /&gt;
                    $aReturn[3] &amp;amp;= $aStringSplit[$A] &amp;amp; &#039;\&#039;&lt;br /&gt;
                Next&lt;br /&gt;
                $aReturn[3] = StringTrimRight($aReturn[3], 1)&lt;br /&gt;
                $aReturn[4] = $aStringSplit[$aStringSplit[0]]&lt;br /&gt;
                Return $aReturn&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return SetError(1, 0, $aReturn)&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinGetPath&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetNumeratedClassList ==&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;
; Description: Retrieves the numerated classes from a window.&lt;br /&gt;
&lt;br /&gt;
Func _WinGetNumeratedClassList($sTitle)&lt;br /&gt;
    Local $sClassList = WinGetClassList($sTitle)&lt;br /&gt;
    Local $aClassList = StringSplit($sClassList, @LF)&lt;br /&gt;
    Local $sRetClassList = &amp;quot;&amp;quot;, $sHold_List = &amp;quot;|&amp;quot;&lt;br /&gt;
    Local $aiInHold, $iInHold&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To UBound($aClassList) - 1&lt;br /&gt;
        If $aClassList[$i] = &amp;quot;&amp;quot; Then ContinueLoop&lt;br /&gt;
&lt;br /&gt;
        If StringRegExp($sHold_List, &amp;quot;\|&amp;quot; &amp;amp; $aClassList[$i] &amp;amp; &amp;quot;~(\d+)\|&amp;quot;) Then&lt;br /&gt;
            $aiInHold = StringRegExp($sHold_List, &amp;quot;.*\|&amp;quot; &amp;amp; $aClassList[$i] &amp;amp; &amp;quot;~(\d+)\|.*&amp;quot;, 1)&lt;br /&gt;
            $iInHold = Number($aiInHold[UBound($aiInHold)-1])&lt;br /&gt;
&lt;br /&gt;
            If $iInHold = 0 Then $iInHold += 1&lt;br /&gt;
&lt;br /&gt;
            $aClassList[$i] &amp;amp;= &amp;quot;~&amp;quot; &amp;amp; $iInHold + 1&lt;br /&gt;
            $sHold_List &amp;amp;= $aClassList[$i] &amp;amp; &amp;quot;|&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            $sRetClassList &amp;amp;= $aClassList[$i] &amp;amp; @LF&lt;br /&gt;
        Else&lt;br /&gt;
            $aClassList[$i] &amp;amp;= &amp;quot;~1&amp;quot;&lt;br /&gt;
            $sHold_List &amp;amp;= $aClassList[$i] &amp;amp; &amp;quot;|&amp;quot;&lt;br /&gt;
            $sRetClassList &amp;amp;= $aClassList[$i] &amp;amp; @LF&lt;br /&gt;
        EndIf&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    Return StringReplace(StringStripWS($sRetClassList, 3), &amp;quot;~&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetHandleByPID ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 4813-smoke-n&lt;br /&gt;
| AuthorName = SmOke_N&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Get Window Handle by PID&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $a1 = _WinGetHandleByPID(232)&lt;br /&gt;
Global $a2 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, -1)&lt;br /&gt;
Global $a3 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, 0)&lt;br /&gt;
Global $a4 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, 1)&lt;br /&gt;
&lt;br /&gt;
_ArrayDisplay($a1, &amp;quot;1&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a2, &amp;quot;2&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a3, &amp;quot;3&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a4, &amp;quot;4&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
;$nVisible = -1 &amp;quot;All (Visble or not)&amp;quot;, $nVisible = 0 &amp;quot;Not Visible Only&amp;quot;, $nVisible = 1 &amp;quot;Visible Only&amp;quot;&lt;br /&gt;
Func _WinGetHandleByPID($vProc, $nVisible = 1)&lt;br /&gt;
    $vProc = ProcessExists($vProc);&lt;br /&gt;
&lt;br /&gt;
    If Not $vProc Then Return SetError(1, 0, 0)&lt;br /&gt;
&lt;br /&gt;
    Local $aWL = WinList()&lt;br /&gt;
&lt;br /&gt;
    Local $aTemp[UBound($aWL)][2]&lt;br /&gt;
&lt;br /&gt;
	Local $nAdd = 0&lt;br /&gt;
&lt;br /&gt;
    For $iCC = 1 To $aWL[0][0]&lt;br /&gt;
        If $nVisible = -1 And WinGetProcess($aWL[$iCC][1]) = $vProc Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        ElseIf $nVisible = 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) = 0 Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        ElseIf $nVisible &amp;gt; 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        EndIf&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    If $nAdd = 0 Then Return SetError(2, 0, 0) ; No windows found&lt;br /&gt;
&lt;br /&gt;
    ReDim $aTemp[$nAdd + 1][2]&lt;br /&gt;
&lt;br /&gt;
    $aTemp[0][0] = $nAdd&lt;br /&gt;
&lt;br /&gt;
    Return $aTemp&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_AutoIt_)&amp;diff=12758</id>
		<title>Snippets ( AutoIt )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_AutoIt_)&amp;diff=12758"/>
		<updated>2015-01-16T21:31:31Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* _WinAPI_CharLower */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
[[category:Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Snippet Credit Header}}&lt;br /&gt;
&lt;br /&gt;
== AutoItWinShow ==&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;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Display AutoIt&#039;s Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.&lt;br /&gt;
    AutoItWinShow()&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Display AutoIt&#039;s Hidden Window. Returns the handle of the window.&lt;br /&gt;
Func AutoItWinShow()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    WinMove($hWnd, &#039;&#039;, (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.&lt;br /&gt;
    WinSetState($hWnd, &#039;&#039;, @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I&#039;m displaying it.&lt;br /&gt;
    Return $hWnd&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinShow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== AutoItWinGetText ==&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;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Display AutoIt&#039;s Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.&lt;br /&gt;
    AutoItWinShow()&lt;br /&gt;
&lt;br /&gt;
    ; Add a text string to AutoIt&#039;s Hidden Window. Compile to see the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    AutoItWinSetText(&#039;Welcome to AutoIt V&#039; &amp;amp; @AutoItVersion &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Add a text string to AutoIt&#039;s Hidden Window. Compile to see the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    AutoItWinSetText(&#039;Windows Type: &#039; &amp;amp; @OSType &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Display the text stored in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, AutoItWinGetText())&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Retrieve the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
Func AutoItWinGetText()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    Return ControlGetText($hWnd, &#039;&#039;, ControlGetHandle($hWnd, &#039;&#039;, &#039;Edit1&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinGetText&lt;br /&gt;
&lt;br /&gt;
; Add text to AutoIt&#039;s Hidden Window.&lt;br /&gt;
Func AutoItWinSetText($sString)&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    Return ControlSetText($hWnd, &amp;quot;&amp;quot;, ControlGetHandle($hWnd, &amp;quot;&amp;quot;, &#039;Edit1&#039;), ControlGetText($hWnd, &#039;&#039;, ControlGetHandle($hWnd, &#039;&#039;, &#039;Edit1&#039;)) &amp;amp; $sString)&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinSetText&lt;br /&gt;
&lt;br /&gt;
; Display AutoIt&#039;s Hidden Window. Returns the handle of the window.&lt;br /&gt;
Func AutoItWinShow()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    WinMove($hWnd, &#039;&#039;, (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.&lt;br /&gt;
    WinSetState($hWnd, &#039;&#039;, @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I&#039;m displaying it.&lt;br /&gt;
    Return $hWnd&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinShow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _DockToWindow ==&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;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If (Not ProcessExists(&amp;quot;SciTE.exe&amp;quot;)) Then&lt;br /&gt;
    Exit MsgBox(4096, &#039;&#039;, &amp;quot;Please start SciTE.exe&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Create a GUI, similar to SciTE Jump&#039;s GUI.&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;, 215, 400, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    ; Dock the first window to left and adjust the width based on the width of the second GUI.&lt;br /&gt;
    _DockToWindow(WinGetHandle(&amp;quot;[CLASS:SciTEWindow]&amp;quot;), $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&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;
&lt;br /&gt;
Func _DockToWindow(Const $hHandle_1, Const $hHandle_2)&lt;br /&gt;
    ; Retrieve the working area, this is minus the taskbar dimensions so slightly different to @DesktopHeight and @DesktopWidth which is the&lt;br /&gt;
    ; monitors height and width.&lt;br /&gt;
    Local Const $SPI_GETWORKAREA = 48&lt;br /&gt;
    Local Const $tWorkArea = DllStructCreate($tagRECT)&lt;br /&gt;
    _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($tWorkArea))&lt;br /&gt;
&lt;br /&gt;
    ; Retieve the position of the second GUI.&lt;br /&gt;
    Local Const $aClientSize_2 = WinGetPos($hHandle_2)&lt;br /&gt;
&lt;br /&gt;
    ; Set the state of the windows to &#039;Restore&#039;.&lt;br /&gt;
    WinSetState($hHandle_1, &#039;&#039;, @SW_RESTORE)&lt;br /&gt;
    WinSetState($hHandle_2, &#039;&#039;, @SW_RESTORE)&lt;br /&gt;
&lt;br /&gt;
    ; Move the first to the far left of the screen and adjust the width to the total screen width minus the width of the second GUI. e.g. 1366 - 215&lt;br /&gt;
    WinMove($hHandle_1, &#039;&#039;, DllStructGetData($tWorkArea, &#039;Left&#039;), DllStructGetData($tWorkArea, &#039;Top&#039;), DllStructGetData($tWorkArea, &#039;Right&#039;) - DllStructGetData($tWorkArea, &#039;Left&#039;) - $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Bottom&#039;) - DllStructGetData($tWorkArea, &#039;Top&#039;))&lt;br /&gt;
&lt;br /&gt;
    ; Move the second window to the far right in between the remaining space and adjust the height of the GUI.&lt;br /&gt;
    WinMove($hHandle_2, &#039;&#039;, DllStructGetData($tWorkArea, &#039;Right&#039;) - DllStructGetData($tWorkArea, &#039;Left&#039;) - $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Top&#039;), $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Bottom&#039;) - DllStructGetData($tWorkArea, &#039;Top&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;_DockToWindow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FuncExists ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 52-geosoft&lt;br /&gt;
| AuthorName = GEOSoft&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox(0, &amp;quot;TEST&amp;quot;, &amp;quot;Function Exists = &amp;quot; &amp;amp; _FuncExists(&amp;quot;_FuncExists&amp;quot;, @ScriptFullPath))&lt;br /&gt;
&lt;br /&gt;
Func _FuncExists($sFunc, $sPath)&lt;br /&gt;
   If Not FileExists($sPath) Then Return SetError(1)&lt;br /&gt;
   Local Const $sStr = FileRead($sPath)&lt;br /&gt;
   Local Const $sRegEx = &amp;quot;(?i)(?m:^|\n)\s*Func\s+(&amp;quot; &amp;amp; $sFunc &amp;amp; &amp;quot;)\s*\(&amp;quot;&lt;br /&gt;
   Local Const $aRegEx = StringRegExp($sStr, $sRegEx, 1)&lt;br /&gt;
   If IsArray($aRegEx) Then Return 1&lt;br /&gt;
   Return 0&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FunctionSort ==&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;
; Get the list of Functions in a script and sort by alphabetical order.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;String.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local $sFile = FileOpenDialog(@ScriptName, &amp;quot;Select an AutoIt file.&amp;quot;, &amp;quot;Au3 (*.au3)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    Exit&lt;br /&gt;
EndIf&lt;br /&gt;
ClipPut(_FunctionSort($sFile))&lt;br /&gt;
&lt;br /&gt;
Func _FunctionSort($sFilePath)&lt;br /&gt;
    Local Const $sRead = FileRead($sFilePath)&lt;br /&gt;
&lt;br /&gt;
	Local $aReturn = StringRegExp(&amp;quot;Func _Count()&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;EndFunc ;==&amp;gt;_Count&amp;quot; &amp;amp; $sRead, &#039;(?s)(?i)Func(.*?)EndFunc&#039;, 3)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    $aReturn[0] = UBound($aReturn, 1) - 1&lt;br /&gt;
&lt;br /&gt;
    _ArraySort($aReturn, 0, 1)&lt;br /&gt;
&lt;br /&gt;
    Local $sReturn&lt;br /&gt;
&lt;br /&gt;
    For $A = 1 To $aReturn[0]&lt;br /&gt;
        $sReturn &amp;amp;= &amp;quot;Func&amp;quot; &amp;amp; $aReturn[$A] &amp;amp; &amp;quot;EndFunc&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    Return $sReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_FunctionSort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsBeta ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 10673-mlipok&lt;br /&gt;
| AuthorName = mLipok&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;
#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;
    Local $aTest[10]&lt;br /&gt;
    _ArrayUnique($aTest, 0, 5)&lt;br /&gt;
    Local $iError = @error&lt;br /&gt;
    ConsoleWrite(&#039;$iError = &#039; &amp;amp; $iError &amp;amp; @CRLF)&lt;br /&gt;
    If _IsBeta() Then&lt;br /&gt;
        If $iError = 3 Then&lt;br /&gt;
            MsgBox($MB_SYSTEMMODAL, &#039;@error&#039;, &#039;3 - $iBase or $iCase contains an invalid value&#039; &amp;amp; @CRLF &amp;amp; @AutoItVersion)&lt;br /&gt;
        EndIf&lt;br /&gt;
    Else&lt;br /&gt;
        If $iError = 2 Then&lt;br /&gt;
            MsgBox($MB_SYSTEMMODAL, &#039;@error&#039;, &#039;2 - $iBase or $iCase contains an invalid value&#039; &amp;amp; @CRLF &amp;amp; @AutoItVersion)&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _IsBeta()&lt;br /&gt;
       Return Mod(StringSplit(@AutoItVersion, &#039;.&#039;)[3], 2) == 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsBeta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsButton ==&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;ButtonConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;Constants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    Local Const $iLabel = GUICtrlCreateButton(&#039;&#039;, 0, 0, 50, 50)&lt;br /&gt;
    Local Const $iCheckbox = GUICtrlCreateCheckbox(&#039;&#039;, 0, 0, 100, 20) ; This is considered a &#039;Button&#039; by _WinAPI_GetClassName too.&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;AutoIt Button ID: &#039; &amp;amp; _IsButton($iLabel) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Button Handle: &#039; &amp;amp; _IsButton(GUICtrlGetHandle($iLabel)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Checkbox ID: &#039; &amp;amp; _IsButton($iCheckbox) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Checkbox Handle: &#039; &amp;amp; _IsButton(GUICtrlGetHandle($iCheckbox)) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    Return GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Check if a variable is referencing a Button control.&lt;br /&gt;
Func _IsButton($hWnd)&lt;br /&gt;
    If IsHWnd($hWnd) = 0 Then&lt;br /&gt;
        $hWnd = GUICtrlGetHandle($hWnd)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Local Const $sClassName = _WinAPI_GetClassName($hWnd)&lt;br /&gt;
&lt;br /&gt;
    If $sClassName = &#039;Button&#039; Then&lt;br /&gt;
        Local Const $aStyle[5] = [4, $BS_CHECKBOX, $BS_AUTOCHECKBOX, $BS_RADIOBUTTON, $BS_AUTORADIOBUTTON]&lt;br /&gt;
&lt;br /&gt;
        Local Const $iLong = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)&lt;br /&gt;
&lt;br /&gt;
		For $i = 1 To $aStyle[0]&lt;br /&gt;
            If BitAND($iLong, $aStyle[$i]) = $aStyle[$i] Then&lt;br /&gt;
                Return False&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
&lt;br /&gt;
        Return True&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return False&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsButton&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsControlID ==&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 if a Control ID is a native AutoIt control.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;GUIListView.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    Local Const $iControlID = GUICtrlCreateLabel(&#039;&#039;, 0, 0, 500, 500)&lt;br /&gt;
    Local Const $hListView = _GUICtrlListView_Create($hGUI, &#039;Example&#039;, 0, 0, 500, 500)&lt;br /&gt;
&lt;br /&gt;
	GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;AutoIt ControlID: &#039; &amp;amp; _IsControlID($iControlID) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;Random Number: &#039; &amp;amp; _IsControlID(Random(42, 99, 1)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt ControlID Handle: &#039; &amp;amp; _IsControlID(GUICtrlGetHandle($iControlID)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;ListView UDF Handle: &#039; &amp;amp; _IsControlID($hListView) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;ListView UDF Handle: &#039; &amp;amp; _IsControlID(GUICtrlGetHandle($hListView)) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    _GUICtrlListView_Destroy($hListView)&lt;br /&gt;
&lt;br /&gt;
    Return GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _IsControlID($iControlID)&lt;br /&gt;
    If IsHWnd($iControlID) Then&lt;br /&gt;
        $iControlID = _WinAPI_GetDlgCtrlID($iControlID)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return IsHWnd(GUICtrlGetHandle($iControlID)) = 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsControlID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItIncludesFromSciTE ==&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;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetAutoItIncludesFromSciTE() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Retrieve the AutoIt includes path from the SciTE process.&lt;br /&gt;
Func _GetAutoItIncludesFromSciTE()&lt;br /&gt;
    Local $sRelativePath = &#039;..\Include&#039;&lt;br /&gt;
	Local Const $sWorkingDir = @WorkingDir&lt;br /&gt;
    FileChangeDir(_WinAPI_PathRemoveFileSpec(_WinAPI_GetProcessFileName(ProcessExists(&#039;SciTE.exe&#039;))))&lt;br /&gt;
    $sRelativePath = _WinAPI_GetFullPathName($sRelativePath)&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return _WinAPI_PathRemoveBackslash($sRelativePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItIncludesFromSciTE&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstall ==&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;
; Get the AutoIt installation folder.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetAutoItInstall() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetAutoItInstall()&lt;br /&gt;
    Return StringLeft(@AutoItExe, StringInStr(@AutoItExe, &amp;quot;\&amp;quot;, 2, -1) - 1)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstall&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstallEx ==&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(_GetAutoItInstallEx() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the installation of AutoIt. An improved version of _GetAutoItInstall.&lt;br /&gt;
Func _GetAutoItInstallEx()&lt;br /&gt;
    Local $aWow6432Node[2] = [&#039;&#039;, &#039;Wow6432Node\&#039;], $aFiles[4] = [3, @ProgramFilesDir, EnvGet(&amp;quot;PROGRAMFILES&amp;quot;), EnvGet(&amp;quot;PROGRAMFILES(X86)&amp;quot;)]&lt;br /&gt;
    Local $sFilePath = RegRead(&#039;HKEY_LOCAL_MACHINE\SOFTWARE\&#039; &amp;amp; $aWow6432Node[@AutoItX64] &amp;amp; &#039;AutoIt v3\AutoIt\&#039;, &#039;InstallDir&#039;)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        For $A = 1 To $aFiles[0]&lt;br /&gt;
            $aFiles[$A] &amp;amp;= &#039;\AutoIt&#039;&lt;br /&gt;
            If FileExists($aFiles[$A]) Then&lt;br /&gt;
                Return $aFiles[$A]&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
        Return SetError(1, 0, &#039;&#039;)&lt;br /&gt;
    Else&lt;br /&gt;
        Return $sFilePath&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstallEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstallFromSciTE ==&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(_GetAutoItInstallFromSciTE() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Retrieve the AutoIt installation path from the SciTE process.&lt;br /&gt;
Func _GetAutoItInstallFromSciTE()&lt;br /&gt;
    Local $sRelativePath = &#039;..\&#039;, $sWorkingDir = @WorkingDir&lt;br /&gt;
    FileChangeDir( _WinAPI_PathRemoveFileSpec(_WinAPI_GetProcessFileName(ProcessExists(&amp;quot;SciTE.exe&amp;quot;))))&lt;br /&gt;
    $sRelativePath = _WinAPI_GetFullPathName($sRelativePath)&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return _WinAPI_PathRemoveBackslash($sRelativePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstallFromSciTE&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetClasses ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 24-cyberslug&lt;br /&gt;
| AuthorName = CyberSlug&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Get ALL Controls Info&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
	; Run Calculator&lt;br /&gt;
	Run(&amp;quot;calc.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	; Wait 10 seconds for the Calculator window to appear.&lt;br /&gt;
	Local const $hWnd = WinWait(&amp;quot;[CLASS:CalcFrame]&amp;quot;, &#039;&#039;, 10)&lt;br /&gt;
&lt;br /&gt;
	; Retrieve a list of all the controls in the Calculator window using the handle returned by WinWait.&lt;br /&gt;
	MsgBox(4096, &#039;&#039;, _GetClasses($hWnd))&lt;br /&gt;
&lt;br /&gt;
	; Close the Calculator window using the handle returned by WinWait.&lt;br /&gt;
	WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; This function returns an @LF-separated list of controls on the specified window.&lt;br /&gt;
Func _GetClasses($sTitle, $sText = &#039;&#039;)&lt;br /&gt;
	Local $iCount_Button = 0, $iCount_Edit = 0, $iCount_Static = 0&lt;br /&gt;
	Local $aClasses = StringSplit(WinGetClassList($sTitle, $sText), @LF)&lt;br /&gt;
	Local $aClassID[$aClasses[0] + 1] = [$aClasses[0]]&lt;br /&gt;
&lt;br /&gt;
	For $i = 1 To $aClasses[0]&lt;br /&gt;
		Select&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Button&amp;quot;&lt;br /&gt;
				$iCount_Button += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Button&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Edit&amp;quot;&lt;br /&gt;
				$iCount_Edit += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Edit&lt;br /&gt;
				$aClasses[$i] = &amp;quot;Input&amp;quot;&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Static&amp;quot;&lt;br /&gt;
				$iCount_Static += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Static&lt;br /&gt;
				$aClasses[$i] = &amp;quot;Label&amp;quot;&lt;br /&gt;
			Case Else&lt;br /&gt;
				If $aClasses[$i] &amp;lt;&amp;gt; &amp;quot;&amp;quot; Then&lt;br /&gt;
					$aClassID[$i] = $aClasses[$i] &amp;amp; &amp;quot;?&amp;quot;&lt;br /&gt;
				EndIf&lt;br /&gt;
		EndSelect&lt;br /&gt;
	Next&lt;br /&gt;
&lt;br /&gt;
	; Combine the results.&lt;br /&gt;
	Local $sReturn = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	For $i = 1 To $aClassID[0]&lt;br /&gt;
		$sReturn &amp;amp;= $aClassID[$i] &amp;amp; @LF&lt;br /&gt;
	Next&lt;br /&gt;
&lt;br /&gt;
	Return $sReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetClasses&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFile ==&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;
; FileRead Alternative&lt;br /&gt;
&lt;br /&gt;
Func _GetFile($sFile, $iFormat = 0)&lt;br /&gt;
    Local $hFileOpen = FileOpen($sFile, $iFormat)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(1, 0, &amp;quot;&amp;quot;)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $sData = FileRead($hFileOpen)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
    Return $sData&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetTitle ==&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;
; Get the title of your program.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetTitle(&#039;Example&#039;) &amp;amp; @CRLF)&lt;br /&gt;
; The second parameter would normally be @ScriptDir &amp;amp; &#039;\Uninstall.exe&#039; for example, but for this demonstration I&#039;m using the full path.&lt;br /&gt;
ConsoleWrite(_GetTitle(&#039;Example&#039;, @ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetTitle($sProgramName, $sInstallPath = &#039;&#039;)&lt;br /&gt;
    Local $aOSArch[2] = [&#039;&#039;, &#039; (64-bit)&#039;], $aPortable[2] = [&#039; (Portable)&#039;, &#039;&#039;]&lt;br /&gt;
    Return $sProgramName &amp;amp; $aOSArch[@AutoItX64] &amp;amp; $aPortable[FileExists($sInstallPath)]&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetTitle&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetXML ==&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;
; Simple Way Of Parsing XML Data.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $aReturn, $sXMLData&lt;br /&gt;
&lt;br /&gt;
$sXMLData = &amp;quot;&amp;lt;data&amp;gt;This is a Simple example of XML&amp;lt;/data&amp;gt;&amp;lt;data&amp;gt;This is a Simple example of XML and is the Second String.&amp;lt;/data&amp;gt;&amp;quot;&lt;br /&gt;
$aReturn = _GetXML($sXMLData, &amp;quot;data&amp;quot;)&lt;br /&gt;
_ArrayDisplay($aReturn, &amp;quot;_GetXML()&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _GetXML($sString, $sData)&lt;br /&gt;
    Local $aError[2] = [1, $sString], $aReturn&lt;br /&gt;
    $aReturn = StringRegExp(&#039;&amp;lt;&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&amp;lt;/&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&#039; &amp;amp; $sString, &#039;(?s)(?i)&amp;lt;&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;(.*?)&amp;lt;/&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&#039;, 3)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $aError)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aReturn[0] = UBound($aReturn, 1) - 1&lt;br /&gt;
    Return SetError(0, 0, $aReturn)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetXML&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Include Source With Exe ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 54985-jlogan3o13&lt;br /&gt;
| AuthorName = JLogan3o13&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;recover source .au3 file with /Extract switch&lt;br /&gt;
; The above code would be copied into the top of your script. The source location (C:\Test.au3 in my example) is the full path to your script file.&lt;br /&gt;
;Once compiled, if you run the script from the Run line with the /Extract switch, it will extact the original .au3 file into the Temp directory and will exit without actually executing the script.&lt;br /&gt;
If StringInStr($cmdlineRaw, &amp;quot;/Extract&amp;quot;) Then&lt;br /&gt;
	FileInstall(&amp;quot;C:\Test.au3&amp;quot;, @TempDir &amp;amp; &amp;quot;\Test.au3&amp;quot;, 1)&lt;br /&gt;
	Exit&lt;br /&gt;
EndIf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsANSIFile ==&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;FileConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_IsANSIFile(@ScriptFullPath) &amp;amp; @LF) ; Returns True.&lt;br /&gt;
&lt;br /&gt;
Func _IsANSIFile($sFilePath)&lt;br /&gt;
    Return FileGetEncoding($sFilePath) = $FO_READ&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsUnicodeFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsUnicodeFile ==&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;FileConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_IsUnicodeFile(@ScriptFullPath) &amp;amp; @LF) ; Returns False.&lt;br /&gt;
&lt;br /&gt;
Func _IsUnicodeFile($sFilePath)&lt;br /&gt;
    Return FileGetEncoding($sFilePath) = $FO_UNICODE&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsUnicodeFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsAu3File ==&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(_IsAu3File(@AutoItExe) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_IsAu3File(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Checks whether the filepath is an au3 file.&lt;br /&gt;
Func _IsAu3File($sFilePath)&lt;br /&gt;
    Return StringTrimLeft($sFilePath, StringInStr($sFilePath, &amp;quot;.&amp;quot;, 2, -1)) = &amp;quot;au3&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsAu3File&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsDefault ==&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;
If _IsDefault(Default) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 1&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
If _IsDefault(-1) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 2&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
If _IsDefault(&amp;quot;Other&amp;quot;) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 3&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
Func _IsDefault($sDefault)&lt;br /&gt;
    Return StringRegExp($sDefault, &amp;quot;(?-i)\s|Default|-1|0&amp;quot;)&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsDefault&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsInTrial ==&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;Date.au3&amp;gt; ; Required for _DateDiff()&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;Date trial started: &#039; &amp;amp; @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/01&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Today&#039;&#039;s date: &#039; &amp;amp; @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/&#039; &amp;amp; @MDAY &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Trial period: 30 days&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Is the trial period still valid: &#039; &amp;amp; _IsInTrial(@YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/01&#039;, 30) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a trial period date is still valid.&lt;br /&gt;
Func _IsInTrial($sDateString, $iDays) ; Based on the idea found here: http://www.autoitscript.com/forum/topic/...ial-time/page__view__findpost_&lt;br /&gt;
    Return (_DateDiff(&#039;D&#039;, $sDateString, @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/&#039; &amp;amp; @MDAY) &amp;lt; $iDays)&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsInTrial&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsVisible ==&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 if the Notepad Window is visible.&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Run Notepad&lt;br /&gt;
    Run(&amp;quot;notepad.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    ; Wait 10 seconds for the Notepad window to appear.&lt;br /&gt;
    Local $hWnd = WinWait(&amp;quot;[CLASS:Notepad]&amp;quot;, &amp;quot;&amp;quot;, 10)&lt;br /&gt;
&lt;br /&gt;
    ; Check if the Notepad window is visible and display the appropriate message box.&lt;br /&gt;
    If _IsVisible($hWnd) Then&lt;br /&gt;
        MsgBox(4096, &amp;quot;&amp;quot;, &amp;quot;Notepad is visible.&amp;quot;)&lt;br /&gt;
    Else&lt;br /&gt;
        MsgBox(4096, &amp;quot;&amp;quot;, &amp;quot;Notepad isn&#039;t visible.&amp;quot;)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    ; Close the Notepad window using the handle returned by WinWait.&lt;br /&gt;
    WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Check if the window is visible.&lt;br /&gt;
Func _IsVisible($hWnd)&lt;br /&gt;
    Return BitAND(WinGetState($hWnd), 2) = 2&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsVisible&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Open Help File to Desired Page ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 1967-garyfrost&lt;br /&gt;
| AuthorName = GaryFrost&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Open help file / Open a desired page&lt;br /&gt;
&lt;br /&gt;
Global Const $sAutoItPath = RegRead(&amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt&amp;quot;, &amp;quot;InstallDir&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Run(@WindowsDir &amp;amp; &amp;quot;\hh.exe &amp;quot; &amp;amp; $sAutoItPath &amp;amp; &amp;quot;\AutoIt3.chm::/html/functions/GUICtrlCreateUpdown.htm&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _RunAU3 ==&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;
_RunAU3(&amp;quot;AU3_Example.txt&amp;quot;, &#039;&amp;quot;This is a commandline example!&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
Func _RunAU3($sFilePath,  $sCommandLine = &amp;quot;&amp;quot;, $sWorkingDir = &amp;quot;&amp;quot;, $iShowFlag = @SW_SHOW, $iOptFlag = 0)&lt;br /&gt;
    Return Run(&#039;&amp;quot;&#039; &amp;amp; @AutoItExe &amp;amp; &#039;&amp;quot; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; $sCommandLine, $sWorkingDir, $iShowFlag, $iOptFlag)&lt;br /&gt;
EndFunc   ;==&amp;gt;_RunAU3&lt;br /&gt;
&lt;br /&gt;
Func _RunWaitAU3($sFilePath, $sCommandLine = &amp;quot;&amp;quot;, $sWorkingDir = &amp;quot;&amp;quot;, $iShowFlag = @SW_SHOW, $iOptFlag = 0)&lt;br /&gt;
    Local $iPID&lt;br /&gt;
    $iPID = RunWait(&#039;&amp;quot;&#039; &amp;amp; @AutoItExe &amp;amp; &#039;&amp;quot; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; $sCommandLine, $sWorkingDir, $iShowFlag, $iOptFlag)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(@error, 1, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $iPID&lt;br /&gt;
EndFunc   ;==&amp;gt;_RunWaitAU3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Run Any au3 File From Your Program ==&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;
; Run Any Au3 File From Your Program&lt;br /&gt;
&lt;br /&gt;
Global Const $sFilePath = @ScriptDir &amp;amp; &amp;quot;\Test.au3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If @Compiled Then&lt;br /&gt;
	Global Const $sFileExe = FileGetShortName(@AutoItExe &amp;amp; &#039; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot;&#039;)&lt;br /&gt;
	Run($sFileExe)&lt;br /&gt;
Else&lt;br /&gt;
	Global Const $sFileAu3 = FileGetShortName($sFilePath)&lt;br /&gt;
	Run(@AutoItExe &amp;amp; &amp;quot; &amp;quot; &amp;amp; $sFileAu3, &amp;quot;&amp;quot;, @SW_HIDE)&lt;br /&gt;
EndIf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ScriptName ==&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(_ScriptName() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Return the @ScriptName minus the .exe or .au3 extension.&lt;br /&gt;
Func _ScriptName()&lt;br /&gt;
	Return StringLeft(@ScriptName, StringInStr(@ScriptName, &#039;.&#039;, 2, -1) - 1)&lt;br /&gt;
EndFunc   ;==&amp;gt;_ScriptName&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ScriptVersion ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 31149-milesahead&lt;br /&gt;
| AuthorName = MilesAhead&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#NoTrayIcon&lt;br /&gt;
&lt;br /&gt;
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****&lt;br /&gt;
#AutoIt3Wrapper_UseUpx=n&lt;br /&gt;
#AutoIt3Wrapper_Res_Fileversion=1.2.3.4&lt;br /&gt;
#AutoIt3Wrapper_Res_LegalCopyright=2012  www.favessoft.com&lt;br /&gt;
#AutoIt3Wrapper_Res_Language=1033&lt;br /&gt;
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&lt;br /&gt;
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****&lt;br /&gt;
&lt;br /&gt;
Global $version = _ScriptVersion()&lt;br /&gt;
&lt;br /&gt;
Global $msg = &amp;quot;ScriptVerDemo&amp;quot; &amp;amp; &amp;quot; &amp;quot; &amp;amp; $version &amp;amp; &amp;quot;  Copyright (c) 2012  www.favessoft.com&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF&lt;br /&gt;
&lt;br /&gt;
MsgBox(0x1040, &amp;quot;&amp;quot;, $msg)&lt;br /&gt;
&lt;br /&gt;
; return File Version string from compiled or .au3 script&lt;br /&gt;
; returns &amp;quot;&amp;quot; if no version info available&lt;br /&gt;
; Note: The .au3 script must contain #AutoItWrapper&lt;br /&gt;
; directives with file version or &amp;quot;&amp;quot; is returned.&lt;br /&gt;
Func _ScriptVersion(Const $Script = @ScriptFullPath)&lt;br /&gt;
    If StringRight($Script,4) = &amp;quot;.exe&amp;quot; Then&lt;br /&gt;
        Return FileGetVersion($Script)&lt;br /&gt;
    Else&lt;br /&gt;
        Local Const $scriptHandle = FileOpen($Script)&lt;br /&gt;
		Local $ver&lt;br /&gt;
		Local $found = False&lt;br /&gt;
		Local $pos&lt;br /&gt;
&lt;br /&gt;
        If $scriptHandle &amp;lt;&amp;gt; -1 Then&lt;br /&gt;
            Do&lt;br /&gt;
                $ver = FileReadLine($scriptHandle)&lt;br /&gt;
                $sPos = StringInStr($ver, &amp;quot;_Fileversion=&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
                If $sPos Then&lt;br /&gt;
                    $ver = StringMid($ver, $sPos + StringLen(&amp;quot;_Fileversion=&amp;quot;))&lt;br /&gt;
                    $found = True&lt;br /&gt;
                    ExitLoop&lt;br /&gt;
                EndIf&lt;br /&gt;
            Until StringLeft($ver, 1) &amp;lt;&amp;gt; &amp;quot;#&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            FileClose($scriptHandle)&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    If Not $found Then $ver = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    Return $ver&lt;br /&gt;
EndFunc   ;==&amp;gt;_ScriptVersion&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SetFile ==&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;
; FileWrite Alternative&lt;br /&gt;
&lt;br /&gt;
Func _SetFile(Const $sString, Const $sFile, Const $iOverwrite = 0)&lt;br /&gt;
    Local Const $hFileOpen = FileOpen($sFile, $iOverwrite + 1)&lt;br /&gt;
&lt;br /&gt;
    FileWrite($hFileOpen, $sString)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $sString)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return $sString&lt;br /&gt;
EndFunc   ;==&amp;gt;_SetFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ShowHelp ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 60350-chimaera&lt;br /&gt;
| AuthorName = Chimaera&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
HotKeySet(&amp;quot;{F1}&amp;quot;, &amp;quot;_ShowHelp&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _ShowHelp()&lt;br /&gt;
	Return ShellExecute(@ProgramFilesDir &amp;amp; &amp;quot;\AutoIt3\AutoIt3Help.exe&amp;quot;) ; change this to the location of your own helpfile.&lt;br /&gt;
EndFunc   ;==&amp;gt;_ShowHelp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SingletonPID ==&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;
Local $iSingleton = _SingletonPID(&#039;RandomName&#039;, 1)&lt;br /&gt;
&lt;br /&gt;
If $iSingleton = 0 Then&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;This is the first instance of the program running: &#039; &amp;amp; $iSingleton)&lt;br /&gt;
Else&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;There is another instance running. This PID is: &#039; &amp;amp; $iSingleton)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name ..........: _SingletonPID&lt;br /&gt;
; Description ...: Enforce a design paradigm where only one instance of the script may be running.&lt;br /&gt;
; Syntax ........: _SingletonPID($sOccurenceName[, $iFlag = 0])&lt;br /&gt;
; Parameters ....: $sOccurenceName      - String to identify the occurrence of the script.&lt;br /&gt;
;                  $iFlag               - [optional] Optional parameters. Default is 0.&lt;br /&gt;
;                  0 - Exit the script with the exit code -1 if another instance already exists.&lt;br /&gt;
;                  1 - Return the PID of the main executable and without exiting the script too.&lt;br /&gt;
; Return values .: Success - 0 No other process is running.&lt;br /&gt;
;                  Failure - The PID of the main executable.&lt;br /&gt;
; Author ........: guinness with initial ideas by Valik for _Singleton &amp;amp; KaFu for _EnforceSingleInstance.&lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _SingletonPID(Const $sOccurenceName, Const $iFlag = 0)&lt;br /&gt;
    Local $hHandle = WinGetHandle($sOccurenceName)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        AutoItWinSetTitle($sOccurenceName)&lt;br /&gt;
        $hHandle = WinGetHandle($sOccurenceName)&lt;br /&gt;
        ControlSetText($hHandle, &#039;&#039;, ControlGetHandle($hHandle, &#039;&#039;, &#039;Edit1&#039;), @AutoItPID)&lt;br /&gt;
    Else&lt;br /&gt;
        If BitAND($iFlag, 1) Then&lt;br /&gt;
            Return Number(ControlGetText($hHandle, &#039;&#039;, ControlGetHandle($hHandle, &#039;&#039;, &#039;Edit1&#039;)))&lt;br /&gt;
        Else&lt;br /&gt;
            Exit -1&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_SingletonPID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _Sort ==&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(_Sort(&amp;quot;$sVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$iVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$tVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$pVariable&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
Func _Sort(Const $sSortList)&lt;br /&gt;
    Local Const $iPID = Run(&amp;quot;sort.exe&amp;quot;, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD), $sOutput = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    StdinWrite($iPID, $sSortList)&lt;br /&gt;
    StdinWrite($iPID)&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;_Sort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Speak Object and Save to WAV File ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 52278-solidsnake26&lt;br /&gt;
| AuthorName = SolidSnake26&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Speak Object and save to wav file&lt;br /&gt;
&lt;br /&gt;
_SpeakToWAV(&amp;quot;AutoIt Snippets&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\SavedFile.wav&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _SpeakToWAV(Const $sText, Const $sFilePath)&lt;br /&gt;
	Local $ObjVoice = ObjCreate(&amp;quot;Sapi.SpVoice&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	Local $ObjFile = ObjCreate(&amp;quot;Sapi.SpFileStream.1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	$ObjVoice.Speak($sText)&lt;br /&gt;
&lt;br /&gt;
	$ObjFile.Open($sFilePath, 3)&lt;br /&gt;
&lt;br /&gt;
	$ObjVoice.AudioOutputStream = $ObjFile&lt;br /&gt;
EndFunc   ;==&amp;gt;_SpeakToWAV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _VariableSwap ==&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;
Global $sString_1 = &#039;This is string 1.&#039;&lt;br /&gt;
Global $sString_2 = &#039;This is string 2.&#039;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;$sString_1: &#039; &amp;amp; $sString_1 &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(&#039;$sString_2: &#039; &amp;amp; $sString_2 &amp;amp; @CRLF &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
_VariableSwap($sString_1, $sString_2)&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;$sString_1: &#039; &amp;amp; $sString_1 &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(&#039;$sString_2: &#039; &amp;amp; $sString_2 &amp;amp; @CRLF &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Swap the contents of two variables.&lt;br /&gt;
Func _VariableSwap(ByRef $vVariable_1, ByRef $vVariable_2) ; Similar to _ArraySwap though not obvious to some this isn&#039;t limited to arrays.&lt;br /&gt;
    Local Const $vTemp = $vVariable_1&lt;br /&gt;
    $vVariable_1 = $vVariable_2&lt;br /&gt;
    $vVariable_2 = $vTemp&lt;br /&gt;
EndFunc   ;==&amp;gt;_VariableSwap&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_CharLower ==&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(_WinAPI_CharLower(&amp;quot;EXAMPLE&amp;quot;) &amp;amp; @CRLF) ; Similar to StringLower.&lt;br /&gt;
&lt;br /&gt;
; Convert characters to lowercase.&lt;br /&gt;
Func _WinAPI_CharLower($sString)&lt;br /&gt;
    Local $aReturn = DllCall(&#039;user32.dll&#039;, &#039;wstr&#039;, &#039;CharLowerW&#039;, &#039;wstr&#039;, $sString)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $sString)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_CharLower&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_CharUpper ==&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(_WinAPI_CharUpper(&amp;quot;example&amp;quot;) &amp;amp; @CRLF) ; Similar to StringUpper.&lt;br /&gt;
&lt;br /&gt;
; Convert characters to uppercase.&lt;br /&gt;
Func _WinAPI_CharUpper($sString)&lt;br /&gt;
	Local $aReturn = DllCall(&#039;user32.dll&#039;, &#039;wstr&#039;, &#039;CharUpperW&#039;, &#039;wstr&#039;, $sString)&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Return SetError(1, 0, $sString)&lt;br /&gt;
	EndIf&lt;br /&gt;
	Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_CharUpper&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_PathFileExists ==&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;
; An API Alternative To FileExist.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(@ScriptFullPath) &amp;amp; @LF) ; File.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(&amp;quot;C:\&amp;quot;) &amp;amp; @LF) ; Drive.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(@ProgramFilesDir) &amp;amp; @LF) ; Directory.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(&amp;quot;Z:\File.txt&amp;quot;) &amp;amp; @LF) ; Shouldn&#039;t exist!&lt;br /&gt;
&lt;br /&gt;
Func _WinAPI_PathFileExists($sFilePath)&lt;br /&gt;
    Local $aReturn = DllCall(&#039;shlwapi.dll&#039;, &#039;int&#039;, &#039;PathFileExistsW&#039;, &#039;wstr&#039;, $sFilePath)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_PathFileExists&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinActiveByExe ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 4813-smoke-n&lt;br /&gt;
| AuthorName = SmOke_N&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Window Active/Activate by Exe, Open Notepad whilst script is running&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
    If _WinActiveByExe(&#039;notepad.exe&#039;, False) Then MsgBox(64, &#039;info&#039;, &#039;true&#039;)&lt;br /&gt;
    Sleep(100)&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func _WinActiveByExe($sExe, $iActive = True);False to WinActivate, True to just see if it&#039;s active&lt;br /&gt;
    If Not ProcessExists($sExe) Then Return SetError(1, 0, 0)&lt;br /&gt;
    Local $aPL = ProcessList($sExe)&lt;br /&gt;
    Local $aWL = WinList()&lt;br /&gt;
    For $iCC = 1 To $aWL[0][0]&lt;br /&gt;
        For $xCC = 1 To $aPL[0][0]&lt;br /&gt;
            If $aWL[$iCC][0] &amp;lt;&amp;gt; &#039;&#039; And _&lt;br /&gt;
                WinGetProcess($aWL[$iCC][1]) = $aPL[$xCC][1] And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) Then&lt;br /&gt;
                If $iActive And WinActive($aWL[$iCC][1]) Then Return 1&lt;br /&gt;
                If Not $iActive And Not WinActive($aWL[$iCC][1]) Then&lt;br /&gt;
                    WinActivate($aWL[$iCC][1])&lt;br /&gt;
                    Return 1&lt;br /&gt;
                EndIf&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
    Next&lt;br /&gt;
    Return SetError(2, 0, 0)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WindowShake ==&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;
; Shake a window left to right.&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Run Notepad&lt;br /&gt;
    Run(&amp;quot;notepad.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    ; Wait 10 seconds for the Notepad window to appear.&lt;br /&gt;
    Local $hWnd = WinWait(&amp;quot;[CLASS:Notepad]&amp;quot;, &amp;quot;&amp;quot;, 10)&lt;br /&gt;
&lt;br /&gt;
    ; Wait for 1 second.&lt;br /&gt;
    Sleep(1000)&lt;br /&gt;
&lt;br /&gt;
    ; Shake the Notepad window left to right.&lt;br /&gt;
    _WindowShake($hWnd)&lt;br /&gt;
&lt;br /&gt;
    ; Wait for 1 second.&lt;br /&gt;
    Sleep(1000)&lt;br /&gt;
&lt;br /&gt;
    ; Close the Notepad window using the handle returned by WinWait.&lt;br /&gt;
    WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _WindowShake($sTitle, $sText = &#039;&#039;, $iDistance = 20)&lt;br /&gt;
    Local $hWnd = WinGetHandle($sTitle, $sText)&lt;br /&gt;
    Local $aWinGetPos = WinGetPos($hWnd)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $aArray[5] = [4, $aWinGetPos[0] + $iDistance, $aWinGetPos[0], $aWinGetPos[0] + $iDistance, $aWinGetPos[0]]&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To $aArray[0]&lt;br /&gt;
        WinMove($hWnd, &#039;&#039;, $aArray[$i], Default)&lt;br /&gt;
        Sleep(100)&lt;br /&gt;
    Next&lt;br /&gt;
EndFunc   ;==&amp;gt;_WindowShake&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetDetails ==&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;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $aArray = _WinGetDetails(&#039;[ACTIVE]&#039;) ; Returns the Window&#039;s title, PID, folder path filename.&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    Exit&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&lt;br /&gt;
Func _WinGetDetails($sTitle, $sText = &#039;&#039;) ; Based on code of _WinGetPath by GaryFrost.&lt;br /&gt;
    Local $aReturn[5] = [4, &#039;-WinTitle&#039;, &#039;-PID&#039;, &#039;-FolderPath&#039;, &#039;-FileName&#039;], $aStringSplit&lt;br /&gt;
&lt;br /&gt;
    If StringLen($sText) &amp;gt; 0 Then&lt;br /&gt;
        $aReturn[1] = WinGetTitle($sTitle, $sText)&lt;br /&gt;
    Else&lt;br /&gt;
        $aReturn[1] = WinGetTitle($sTitle)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aReturn[2] = WinGetProcess($aReturn[1])&lt;br /&gt;
&lt;br /&gt;
    Local $oWMIService = ObjGet(&#039;winmgmts:\\.\root\CIMV2&#039;)&lt;br /&gt;
    Local $oItems = $oWMIService.ExecQuery(&#039;Select * From Win32_Process Where ProcessId = &#039; &amp;amp; $aReturn[2], &#039;WQL&#039;, 0x30)&lt;br /&gt;
    If IsObj($oItems) Then&lt;br /&gt;
        For $oItem In $oItems&lt;br /&gt;
            If $oItem.ExecutablePath Then&lt;br /&gt;
                $aStringSplit = StringSplit($oItem.ExecutablePath, &#039;\&#039;)&lt;br /&gt;
                $aReturn[3] = &#039;&#039;&lt;br /&gt;
                For $A = 1 To $aStringSplit[0] - 1&lt;br /&gt;
                    $aReturn[3] &amp;amp;= $aStringSplit[$A] &amp;amp; &#039;\&#039;&lt;br /&gt;
                Next&lt;br /&gt;
                $aReturn[3] = StringTrimRight($aReturn[3], 1)&lt;br /&gt;
                $aReturn[4] = $aStringSplit[$aStringSplit[0]]&lt;br /&gt;
                Return $aReturn&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return SetError(1, 0, $aReturn)&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinGetPath&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetNumeratedClassList ==&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;
; Description: Retrieves the numerated classes from a window.&lt;br /&gt;
&lt;br /&gt;
Func _WinGetNumeratedClassList($sTitle)&lt;br /&gt;
    Local $sClassList = WinGetClassList($sTitle)&lt;br /&gt;
    Local $aClassList = StringSplit($sClassList, @LF)&lt;br /&gt;
    Local $sRetClassList = &amp;quot;&amp;quot;, $sHold_List = &amp;quot;|&amp;quot;&lt;br /&gt;
    Local $aiInHold, $iInHold&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To UBound($aClassList) - 1&lt;br /&gt;
        If $aClassList[$i] = &amp;quot;&amp;quot; Then ContinueLoop&lt;br /&gt;
&lt;br /&gt;
        If StringRegExp($sHold_List, &amp;quot;\|&amp;quot; &amp;amp; $aClassList[$i] &amp;amp; &amp;quot;~(\d+)\|&amp;quot;) Then&lt;br /&gt;
            $aiInHold = StringRegExp($sHold_List, &amp;quot;.*\|&amp;quot; &amp;amp; $aClassList[$i] &amp;amp; &amp;quot;~(\d+)\|.*&amp;quot;, 1)&lt;br /&gt;
            $iInHold = Number($aiInHold[UBound($aiInHold)-1])&lt;br /&gt;
&lt;br /&gt;
            If $iInHold = 0 Then $iInHold += 1&lt;br /&gt;
&lt;br /&gt;
            $aClassList[$i] &amp;amp;= &amp;quot;~&amp;quot; &amp;amp; $iInHold + 1&lt;br /&gt;
            $sHold_List &amp;amp;= $aClassList[$i] &amp;amp; &amp;quot;|&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            $sRetClassList &amp;amp;= $aClassList[$i] &amp;amp; @LF&lt;br /&gt;
        Else&lt;br /&gt;
            $aClassList[$i] &amp;amp;= &amp;quot;~1&amp;quot;&lt;br /&gt;
            $sHold_List &amp;amp;= $aClassList[$i] &amp;amp; &amp;quot;|&amp;quot;&lt;br /&gt;
            $sRetClassList &amp;amp;= $aClassList[$i] &amp;amp; @LF&lt;br /&gt;
        EndIf&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    Return StringReplace(StringStripWS($sRetClassList, 3), &amp;quot;~&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetHandleByPID ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 4813-smoke-n&lt;br /&gt;
| AuthorName = SmOke_N&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Get Window Handle by PID&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $a1 = _WinGetHandleByPID(232)&lt;br /&gt;
Global $a2 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, -1)&lt;br /&gt;
Global $a3 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, 0)&lt;br /&gt;
Global $a4 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, 1)&lt;br /&gt;
&lt;br /&gt;
_ArrayDisplay($a1, &amp;quot;1&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a2, &amp;quot;2&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a3, &amp;quot;3&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a4, &amp;quot;4&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
;$nVisible = -1 &amp;quot;All (Visble or not)&amp;quot;, $nVisible = 0 &amp;quot;Not Visible Only&amp;quot;, $nVisible = 1 &amp;quot;Visible Only&amp;quot;&lt;br /&gt;
Func _WinGetHandleByPID($vProc, $nVisible = 1)&lt;br /&gt;
    $vProc = ProcessExists($vProc);&lt;br /&gt;
&lt;br /&gt;
    If Not $vProc Then Return SetError(1, 0, 0)&lt;br /&gt;
&lt;br /&gt;
    Local $aWL = WinList()&lt;br /&gt;
&lt;br /&gt;
    Local $aTemp[UBound($aWL)][2]&lt;br /&gt;
&lt;br /&gt;
	Local $nAdd = 0&lt;br /&gt;
&lt;br /&gt;
    For $iCC = 1 To $aWL[0][0]&lt;br /&gt;
        If $nVisible = -1 And WinGetProcess($aWL[$iCC][1]) = $vProc Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        ElseIf $nVisible = 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) = 0 Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        ElseIf $nVisible &amp;gt; 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        EndIf&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    If $nAdd = 0 Then Return SetError(2, 0, 0) ; No windows found&lt;br /&gt;
&lt;br /&gt;
    ReDim $aTemp[$nAdd + 1][2]&lt;br /&gt;
&lt;br /&gt;
    $aTemp[0][0] = $nAdd&lt;br /&gt;
&lt;br /&gt;
    Return $aTemp&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_AutoIt_)&amp;diff=12757</id>
		<title>Snippets ( AutoIt )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_AutoIt_)&amp;diff=12757"/>
		<updated>2015-01-16T21:31:02Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* _WinAPI_CharUpper */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
[[category:Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Snippet Credit Header}}&lt;br /&gt;
&lt;br /&gt;
== AutoItWinShow ==&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;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Display AutoIt&#039;s Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.&lt;br /&gt;
    AutoItWinShow()&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Display AutoIt&#039;s Hidden Window. Returns the handle of the window.&lt;br /&gt;
Func AutoItWinShow()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    WinMove($hWnd, &#039;&#039;, (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.&lt;br /&gt;
    WinSetState($hWnd, &#039;&#039;, @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I&#039;m displaying it.&lt;br /&gt;
    Return $hWnd&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinShow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== AutoItWinGetText ==&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;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Display AutoIt&#039;s Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.&lt;br /&gt;
    AutoItWinShow()&lt;br /&gt;
&lt;br /&gt;
    ; Add a text string to AutoIt&#039;s Hidden Window. Compile to see the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    AutoItWinSetText(&#039;Welcome to AutoIt V&#039; &amp;amp; @AutoItVersion &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Add a text string to AutoIt&#039;s Hidden Window. Compile to see the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    AutoItWinSetText(&#039;Windows Type: &#039; &amp;amp; @OSType &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    ; Display the text stored in AutoIt&#039;s Hidden Window.&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, AutoItWinGetText())&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Retrieve the text in AutoIt&#039;s Hidden Window.&lt;br /&gt;
Func AutoItWinGetText()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    Return ControlGetText($hWnd, &#039;&#039;, ControlGetHandle($hWnd, &#039;&#039;, &#039;Edit1&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinGetText&lt;br /&gt;
&lt;br /&gt;
; Add text to AutoIt&#039;s Hidden Window.&lt;br /&gt;
Func AutoItWinSetText($sString)&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    Return ControlSetText($hWnd, &amp;quot;&amp;quot;, ControlGetHandle($hWnd, &amp;quot;&amp;quot;, &#039;Edit1&#039;), ControlGetText($hWnd, &#039;&#039;, ControlGetHandle($hWnd, &#039;&#039;, &#039;Edit1&#039;)) &amp;amp; $sString)&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinSetText&lt;br /&gt;
&lt;br /&gt;
; Display AutoIt&#039;s Hidden Window. Returns the handle of the window.&lt;br /&gt;
Func AutoItWinShow()&lt;br /&gt;
    Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.&lt;br /&gt;
    WinMove($hWnd, &#039;&#039;, (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.&lt;br /&gt;
    WinSetState($hWnd, &#039;&#039;, @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I&#039;m displaying it.&lt;br /&gt;
    Return $hWnd&lt;br /&gt;
EndFunc   ;==&amp;gt;AutoItWinShow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _DockToWindow ==&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;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If (Not ProcessExists(&amp;quot;SciTE.exe&amp;quot;)) Then&lt;br /&gt;
    Exit MsgBox(4096, &#039;&#039;, &amp;quot;Please start SciTE.exe&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Create a GUI, similar to SciTE Jump&#039;s GUI.&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;, 215, 400, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    ; Dock the first window to left and adjust the width based on the width of the second GUI.&lt;br /&gt;
    _DockToWindow(WinGetHandle(&amp;quot;[CLASS:SciTEWindow]&amp;quot;), $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&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;
&lt;br /&gt;
Func _DockToWindow(Const $hHandle_1, Const $hHandle_2)&lt;br /&gt;
    ; Retrieve the working area, this is minus the taskbar dimensions so slightly different to @DesktopHeight and @DesktopWidth which is the&lt;br /&gt;
    ; monitors height and width.&lt;br /&gt;
    Local Const $SPI_GETWORKAREA = 48&lt;br /&gt;
    Local Const $tWorkArea = DllStructCreate($tagRECT)&lt;br /&gt;
    _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($tWorkArea))&lt;br /&gt;
&lt;br /&gt;
    ; Retieve the position of the second GUI.&lt;br /&gt;
    Local Const $aClientSize_2 = WinGetPos($hHandle_2)&lt;br /&gt;
&lt;br /&gt;
    ; Set the state of the windows to &#039;Restore&#039;.&lt;br /&gt;
    WinSetState($hHandle_1, &#039;&#039;, @SW_RESTORE)&lt;br /&gt;
    WinSetState($hHandle_2, &#039;&#039;, @SW_RESTORE)&lt;br /&gt;
&lt;br /&gt;
    ; Move the first to the far left of the screen and adjust the width to the total screen width minus the width of the second GUI. e.g. 1366 - 215&lt;br /&gt;
    WinMove($hHandle_1, &#039;&#039;, DllStructGetData($tWorkArea, &#039;Left&#039;), DllStructGetData($tWorkArea, &#039;Top&#039;), DllStructGetData($tWorkArea, &#039;Right&#039;) - DllStructGetData($tWorkArea, &#039;Left&#039;) - $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Bottom&#039;) - DllStructGetData($tWorkArea, &#039;Top&#039;))&lt;br /&gt;
&lt;br /&gt;
    ; Move the second window to the far right in between the remaining space and adjust the height of the GUI.&lt;br /&gt;
    WinMove($hHandle_2, &#039;&#039;, DllStructGetData($tWorkArea, &#039;Right&#039;) - DllStructGetData($tWorkArea, &#039;Left&#039;) - $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Top&#039;), $aClientSize_2[2], DllStructGetData($tWorkArea, &#039;Bottom&#039;) - DllStructGetData($tWorkArea, &#039;Top&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;_DockToWindow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FuncExists ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 52-geosoft&lt;br /&gt;
| AuthorName = GEOSoft&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox(0, &amp;quot;TEST&amp;quot;, &amp;quot;Function Exists = &amp;quot; &amp;amp; _FuncExists(&amp;quot;_FuncExists&amp;quot;, @ScriptFullPath))&lt;br /&gt;
&lt;br /&gt;
Func _FuncExists($sFunc, $sPath)&lt;br /&gt;
   If Not FileExists($sPath) Then Return SetError(1)&lt;br /&gt;
   Local Const $sStr = FileRead($sPath)&lt;br /&gt;
   Local Const $sRegEx = &amp;quot;(?i)(?m:^|\n)\s*Func\s+(&amp;quot; &amp;amp; $sFunc &amp;amp; &amp;quot;)\s*\(&amp;quot;&lt;br /&gt;
   Local Const $aRegEx = StringRegExp($sStr, $sRegEx, 1)&lt;br /&gt;
   If IsArray($aRegEx) Then Return 1&lt;br /&gt;
   Return 0&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FunctionSort ==&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;
; Get the list of Functions in a script and sort by alphabetical order.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;String.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local $sFile = FileOpenDialog(@ScriptName, &amp;quot;Select an AutoIt file.&amp;quot;, &amp;quot;Au3 (*.au3)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    Exit&lt;br /&gt;
EndIf&lt;br /&gt;
ClipPut(_FunctionSort($sFile))&lt;br /&gt;
&lt;br /&gt;
Func _FunctionSort($sFilePath)&lt;br /&gt;
    Local Const $sRead = FileRead($sFilePath)&lt;br /&gt;
&lt;br /&gt;
	Local $aReturn = StringRegExp(&amp;quot;Func _Count()&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;EndFunc ;==&amp;gt;_Count&amp;quot; &amp;amp; $sRead, &#039;(?s)(?i)Func(.*?)EndFunc&#039;, 3)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    $aReturn[0] = UBound($aReturn, 1) - 1&lt;br /&gt;
&lt;br /&gt;
    _ArraySort($aReturn, 0, 1)&lt;br /&gt;
&lt;br /&gt;
    Local $sReturn&lt;br /&gt;
&lt;br /&gt;
    For $A = 1 To $aReturn[0]&lt;br /&gt;
        $sReturn &amp;amp;= &amp;quot;Func&amp;quot; &amp;amp; $aReturn[$A] &amp;amp; &amp;quot;EndFunc&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    Return $sReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_FunctionSort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsBeta ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 10673-mlipok&lt;br /&gt;
| AuthorName = mLipok&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;
#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;
    Local $aTest[10]&lt;br /&gt;
    _ArrayUnique($aTest, 0, 5)&lt;br /&gt;
    Local $iError = @error&lt;br /&gt;
    ConsoleWrite(&#039;$iError = &#039; &amp;amp; $iError &amp;amp; @CRLF)&lt;br /&gt;
    If _IsBeta() Then&lt;br /&gt;
        If $iError = 3 Then&lt;br /&gt;
            MsgBox($MB_SYSTEMMODAL, &#039;@error&#039;, &#039;3 - $iBase or $iCase contains an invalid value&#039; &amp;amp; @CRLF &amp;amp; @AutoItVersion)&lt;br /&gt;
        EndIf&lt;br /&gt;
    Else&lt;br /&gt;
        If $iError = 2 Then&lt;br /&gt;
            MsgBox($MB_SYSTEMMODAL, &#039;@error&#039;, &#039;2 - $iBase or $iCase contains an invalid value&#039; &amp;amp; @CRLF &amp;amp; @AutoItVersion)&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _IsBeta()&lt;br /&gt;
       Return Mod(StringSplit(@AutoItVersion, &#039;.&#039;)[3], 2) == 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsBeta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsButton ==&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;ButtonConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;Constants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    Local Const $iLabel = GUICtrlCreateButton(&#039;&#039;, 0, 0, 50, 50)&lt;br /&gt;
    Local Const $iCheckbox = GUICtrlCreateCheckbox(&#039;&#039;, 0, 0, 100, 20) ; This is considered a &#039;Button&#039; by _WinAPI_GetClassName too.&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;AutoIt Button ID: &#039; &amp;amp; _IsButton($iLabel) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Button Handle: &#039; &amp;amp; _IsButton(GUICtrlGetHandle($iLabel)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Checkbox ID: &#039; &amp;amp; _IsButton($iCheckbox) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Checkbox Handle: &#039; &amp;amp; _IsButton(GUICtrlGetHandle($iCheckbox)) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    Return GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Check if a variable is referencing a Button control.&lt;br /&gt;
Func _IsButton($hWnd)&lt;br /&gt;
    If IsHWnd($hWnd) = 0 Then&lt;br /&gt;
        $hWnd = GUICtrlGetHandle($hWnd)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Local Const $sClassName = _WinAPI_GetClassName($hWnd)&lt;br /&gt;
&lt;br /&gt;
    If $sClassName = &#039;Button&#039; Then&lt;br /&gt;
        Local Const $aStyle[5] = [4, $BS_CHECKBOX, $BS_AUTOCHECKBOX, $BS_RADIOBUTTON, $BS_AUTORADIOBUTTON]&lt;br /&gt;
&lt;br /&gt;
        Local Const $iLong = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)&lt;br /&gt;
&lt;br /&gt;
		For $i = 1 To $aStyle[0]&lt;br /&gt;
            If BitAND($iLong, $aStyle[$i]) = $aStyle[$i] Then&lt;br /&gt;
                Return False&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
&lt;br /&gt;
        Return True&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return False&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsButton&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsControlID ==&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 if a Control ID is a native AutoIt control.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;GUIListView.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
    Local Const $iControlID = GUICtrlCreateLabel(&#039;&#039;, 0, 0, 500, 500)&lt;br /&gt;
    Local Const $hListView = _GUICtrlListView_Create($hGUI, &#039;Example&#039;, 0, 0, 500, 500)&lt;br /&gt;
&lt;br /&gt;
	GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;AutoIt ControlID: &#039; &amp;amp; _IsControlID($iControlID) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;Random Number: &#039; &amp;amp; _IsControlID(Random(42, 99, 1)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt ControlID Handle: &#039; &amp;amp; _IsControlID(GUICtrlGetHandle($iControlID)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;ListView UDF Handle: &#039; &amp;amp; _IsControlID($hListView) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;ListView UDF Handle: &#039; &amp;amp; _IsControlID(GUICtrlGetHandle($hListView)) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    _GUICtrlListView_Destroy($hListView)&lt;br /&gt;
&lt;br /&gt;
    Return GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _IsControlID($iControlID)&lt;br /&gt;
    If IsHWnd($iControlID) Then&lt;br /&gt;
        $iControlID = _WinAPI_GetDlgCtrlID($iControlID)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return IsHWnd(GUICtrlGetHandle($iControlID)) = 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsControlID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItIncludesFromSciTE ==&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;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetAutoItIncludesFromSciTE() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Retrieve the AutoIt includes path from the SciTE process.&lt;br /&gt;
Func _GetAutoItIncludesFromSciTE()&lt;br /&gt;
    Local $sRelativePath = &#039;..\Include&#039;&lt;br /&gt;
	Local Const $sWorkingDir = @WorkingDir&lt;br /&gt;
    FileChangeDir(_WinAPI_PathRemoveFileSpec(_WinAPI_GetProcessFileName(ProcessExists(&#039;SciTE.exe&#039;))))&lt;br /&gt;
    $sRelativePath = _WinAPI_GetFullPathName($sRelativePath)&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return _WinAPI_PathRemoveBackslash($sRelativePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItIncludesFromSciTE&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstall ==&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;
; Get the AutoIt installation folder.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetAutoItInstall() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetAutoItInstall()&lt;br /&gt;
    Return StringLeft(@AutoItExe, StringInStr(@AutoItExe, &amp;quot;\&amp;quot;, 2, -1) - 1)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstall&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstallEx ==&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(_GetAutoItInstallEx() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the installation of AutoIt. An improved version of _GetAutoItInstall.&lt;br /&gt;
Func _GetAutoItInstallEx()&lt;br /&gt;
    Local $aWow6432Node[2] = [&#039;&#039;, &#039;Wow6432Node\&#039;], $aFiles[4] = [3, @ProgramFilesDir, EnvGet(&amp;quot;PROGRAMFILES&amp;quot;), EnvGet(&amp;quot;PROGRAMFILES(X86)&amp;quot;)]&lt;br /&gt;
    Local $sFilePath = RegRead(&#039;HKEY_LOCAL_MACHINE\SOFTWARE\&#039; &amp;amp; $aWow6432Node[@AutoItX64] &amp;amp; &#039;AutoIt v3\AutoIt\&#039;, &#039;InstallDir&#039;)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        For $A = 1 To $aFiles[0]&lt;br /&gt;
            $aFiles[$A] &amp;amp;= &#039;\AutoIt&#039;&lt;br /&gt;
            If FileExists($aFiles[$A]) Then&lt;br /&gt;
                Return $aFiles[$A]&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
        Return SetError(1, 0, &#039;&#039;)&lt;br /&gt;
    Else&lt;br /&gt;
        Return $sFilePath&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstallEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetAutoItInstallFromSciTE ==&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(_GetAutoItInstallFromSciTE() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Retrieve the AutoIt installation path from the SciTE process.&lt;br /&gt;
Func _GetAutoItInstallFromSciTE()&lt;br /&gt;
    Local $sRelativePath = &#039;..\&#039;, $sWorkingDir = @WorkingDir&lt;br /&gt;
    FileChangeDir( _WinAPI_PathRemoveFileSpec(_WinAPI_GetProcessFileName(ProcessExists(&amp;quot;SciTE.exe&amp;quot;))))&lt;br /&gt;
    $sRelativePath = _WinAPI_GetFullPathName($sRelativePath)&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return _WinAPI_PathRemoveBackslash($sRelativePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetAutoItInstallFromSciTE&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetClasses ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 24-cyberslug&lt;br /&gt;
| AuthorName = CyberSlug&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Get ALL Controls Info&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
	; Run Calculator&lt;br /&gt;
	Run(&amp;quot;calc.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	; Wait 10 seconds for the Calculator window to appear.&lt;br /&gt;
	Local const $hWnd = WinWait(&amp;quot;[CLASS:CalcFrame]&amp;quot;, &#039;&#039;, 10)&lt;br /&gt;
&lt;br /&gt;
	; Retrieve a list of all the controls in the Calculator window using the handle returned by WinWait.&lt;br /&gt;
	MsgBox(4096, &#039;&#039;, _GetClasses($hWnd))&lt;br /&gt;
&lt;br /&gt;
	; Close the Calculator window using the handle returned by WinWait.&lt;br /&gt;
	WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; This function returns an @LF-separated list of controls on the specified window.&lt;br /&gt;
Func _GetClasses($sTitle, $sText = &#039;&#039;)&lt;br /&gt;
	Local $iCount_Button = 0, $iCount_Edit = 0, $iCount_Static = 0&lt;br /&gt;
	Local $aClasses = StringSplit(WinGetClassList($sTitle, $sText), @LF)&lt;br /&gt;
	Local $aClassID[$aClasses[0] + 1] = [$aClasses[0]]&lt;br /&gt;
&lt;br /&gt;
	For $i = 1 To $aClasses[0]&lt;br /&gt;
		Select&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Button&amp;quot;&lt;br /&gt;
				$iCount_Button += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Button&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Edit&amp;quot;&lt;br /&gt;
				$iCount_Edit += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Edit&lt;br /&gt;
				$aClasses[$i] = &amp;quot;Input&amp;quot;&lt;br /&gt;
			Case $aClasses[$i] = &amp;quot;Static&amp;quot;&lt;br /&gt;
				$iCount_Static += 1&lt;br /&gt;
				$aClassID[$i] = $aClasses[$i] &amp;amp; $iCount_Static&lt;br /&gt;
				$aClasses[$i] = &amp;quot;Label&amp;quot;&lt;br /&gt;
			Case Else&lt;br /&gt;
				If $aClasses[$i] &amp;lt;&amp;gt; &amp;quot;&amp;quot; Then&lt;br /&gt;
					$aClassID[$i] = $aClasses[$i] &amp;amp; &amp;quot;?&amp;quot;&lt;br /&gt;
				EndIf&lt;br /&gt;
		EndSelect&lt;br /&gt;
	Next&lt;br /&gt;
&lt;br /&gt;
	; Combine the results.&lt;br /&gt;
	Local $sReturn = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	For $i = 1 To $aClassID[0]&lt;br /&gt;
		$sReturn &amp;amp;= $aClassID[$i] &amp;amp; @LF&lt;br /&gt;
	Next&lt;br /&gt;
&lt;br /&gt;
	Return $sReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetClasses&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFile ==&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;
; FileRead Alternative&lt;br /&gt;
&lt;br /&gt;
Func _GetFile($sFile, $iFormat = 0)&lt;br /&gt;
    Local $hFileOpen = FileOpen($sFile, $iFormat)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(1, 0, &amp;quot;&amp;quot;)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $sData = FileRead($hFileOpen)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
    Return $sData&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetTitle ==&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;
; Get the title of your program.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_GetTitle(&#039;Example&#039;) &amp;amp; @CRLF)&lt;br /&gt;
; The second parameter would normally be @ScriptDir &amp;amp; &#039;\Uninstall.exe&#039; for example, but for this demonstration I&#039;m using the full path.&lt;br /&gt;
ConsoleWrite(_GetTitle(&#039;Example&#039;, @ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetTitle($sProgramName, $sInstallPath = &#039;&#039;)&lt;br /&gt;
    Local $aOSArch[2] = [&#039;&#039;, &#039; (64-bit)&#039;], $aPortable[2] = [&#039; (Portable)&#039;, &#039;&#039;]&lt;br /&gt;
    Return $sProgramName &amp;amp; $aOSArch[@AutoItX64] &amp;amp; $aPortable[FileExists($sInstallPath)]&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetTitle&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetXML ==&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;
; Simple Way Of Parsing XML Data.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $aReturn, $sXMLData&lt;br /&gt;
&lt;br /&gt;
$sXMLData = &amp;quot;&amp;lt;data&amp;gt;This is a Simple example of XML&amp;lt;/data&amp;gt;&amp;lt;data&amp;gt;This is a Simple example of XML and is the Second String.&amp;lt;/data&amp;gt;&amp;quot;&lt;br /&gt;
$aReturn = _GetXML($sXMLData, &amp;quot;data&amp;quot;)&lt;br /&gt;
_ArrayDisplay($aReturn, &amp;quot;_GetXML()&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _GetXML($sString, $sData)&lt;br /&gt;
    Local $aError[2] = [1, $sString], $aReturn&lt;br /&gt;
    $aReturn = StringRegExp(&#039;&amp;lt;&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&amp;lt;/&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&#039; &amp;amp; $sString, &#039;(?s)(?i)&amp;lt;&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;(.*?)&amp;lt;/&#039; &amp;amp; $sData &amp;amp; &#039;&amp;gt;&#039;, 3)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $aError)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aReturn[0] = UBound($aReturn, 1) - 1&lt;br /&gt;
    Return SetError(0, 0, $aReturn)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetXML&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Include Source With Exe ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 54985-jlogan3o13&lt;br /&gt;
| AuthorName = JLogan3o13&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;recover source .au3 file with /Extract switch&lt;br /&gt;
; The above code would be copied into the top of your script. The source location (C:\Test.au3 in my example) is the full path to your script file.&lt;br /&gt;
;Once compiled, if you run the script from the Run line with the /Extract switch, it will extact the original .au3 file into the Temp directory and will exit without actually executing the script.&lt;br /&gt;
If StringInStr($cmdlineRaw, &amp;quot;/Extract&amp;quot;) Then&lt;br /&gt;
	FileInstall(&amp;quot;C:\Test.au3&amp;quot;, @TempDir &amp;amp; &amp;quot;\Test.au3&amp;quot;, 1)&lt;br /&gt;
	Exit&lt;br /&gt;
EndIf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsANSIFile ==&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;FileConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_IsANSIFile(@ScriptFullPath) &amp;amp; @LF) ; Returns True.&lt;br /&gt;
&lt;br /&gt;
Func _IsANSIFile($sFilePath)&lt;br /&gt;
    Return FileGetEncoding($sFilePath) = $FO_READ&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsUnicodeFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsUnicodeFile ==&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;FileConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_IsUnicodeFile(@ScriptFullPath) &amp;amp; @LF) ; Returns False.&lt;br /&gt;
&lt;br /&gt;
Func _IsUnicodeFile($sFilePath)&lt;br /&gt;
    Return FileGetEncoding($sFilePath) = $FO_UNICODE&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsUnicodeFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsAu3File ==&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(_IsAu3File(@AutoItExe) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_IsAu3File(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Checks whether the filepath is an au3 file.&lt;br /&gt;
Func _IsAu3File($sFilePath)&lt;br /&gt;
    Return StringTrimLeft($sFilePath, StringInStr($sFilePath, &amp;quot;.&amp;quot;, 2, -1)) = &amp;quot;au3&amp;quot;&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsAu3File&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsDefault ==&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;
If _IsDefault(Default) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 1&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
If _IsDefault(-1) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 2&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
If _IsDefault(&amp;quot;Other&amp;quot;) Then&lt;br /&gt;
    MsgBox(0, &amp;quot;_IsDefault() - 3&amp;quot;, &amp;quot;This was a Default variable.&amp;quot;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
Func _IsDefault($sDefault)&lt;br /&gt;
    Return StringRegExp($sDefault, &amp;quot;(?-i)\s|Default|-1|0&amp;quot;)&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsDefault&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsInTrial ==&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;Date.au3&amp;gt; ; Required for _DateDiff()&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;Date trial started: &#039; &amp;amp; @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/01&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Today&#039;&#039;s date: &#039; &amp;amp; @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/&#039; &amp;amp; @MDAY &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Trial period: 30 days&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
        &#039;Is the trial period still valid: &#039; &amp;amp; _IsInTrial(@YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/01&#039;, 30) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a trial period date is still valid.&lt;br /&gt;
Func _IsInTrial($sDateString, $iDays) ; Based on the idea found here: http://www.autoitscript.com/forum/topic/...ial-time/page__view__findpost_&lt;br /&gt;
    Return (_DateDiff(&#039;D&#039;, $sDateString, @YEAR &amp;amp; &#039;/&#039; &amp;amp; @MON &amp;amp; &#039;/&#039; &amp;amp; @MDAY) &amp;lt; $iDays)&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsInTrial&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsVisible ==&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 if the Notepad Window is visible.&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Run Notepad&lt;br /&gt;
    Run(&amp;quot;notepad.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    ; Wait 10 seconds for the Notepad window to appear.&lt;br /&gt;
    Local $hWnd = WinWait(&amp;quot;[CLASS:Notepad]&amp;quot;, &amp;quot;&amp;quot;, 10)&lt;br /&gt;
&lt;br /&gt;
    ; Check if the Notepad window is visible and display the appropriate message box.&lt;br /&gt;
    If _IsVisible($hWnd) Then&lt;br /&gt;
        MsgBox(4096, &amp;quot;&amp;quot;, &amp;quot;Notepad is visible.&amp;quot;)&lt;br /&gt;
    Else&lt;br /&gt;
        MsgBox(4096, &amp;quot;&amp;quot;, &amp;quot;Notepad isn&#039;t visible.&amp;quot;)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    ; Close the Notepad window using the handle returned by WinWait.&lt;br /&gt;
    WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Check if the window is visible.&lt;br /&gt;
Func _IsVisible($hWnd)&lt;br /&gt;
    Return BitAND(WinGetState($hWnd), 2) = 2&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsVisible&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Open Help File to Desired Page ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 1967-garyfrost&lt;br /&gt;
| AuthorName = GaryFrost&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Open help file / Open a desired page&lt;br /&gt;
&lt;br /&gt;
Global Const $sAutoItPath = RegRead(&amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt&amp;quot;, &amp;quot;InstallDir&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Run(@WindowsDir &amp;amp; &amp;quot;\hh.exe &amp;quot; &amp;amp; $sAutoItPath &amp;amp; &amp;quot;\AutoIt3.chm::/html/functions/GUICtrlCreateUpdown.htm&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _RunAU3 ==&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;
_RunAU3(&amp;quot;AU3_Example.txt&amp;quot;, &#039;&amp;quot;This is a commandline example!&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
Func _RunAU3($sFilePath,  $sCommandLine = &amp;quot;&amp;quot;, $sWorkingDir = &amp;quot;&amp;quot;, $iShowFlag = @SW_SHOW, $iOptFlag = 0)&lt;br /&gt;
    Return Run(&#039;&amp;quot;&#039; &amp;amp; @AutoItExe &amp;amp; &#039;&amp;quot; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; $sCommandLine, $sWorkingDir, $iShowFlag, $iOptFlag)&lt;br /&gt;
EndFunc   ;==&amp;gt;_RunAU3&lt;br /&gt;
&lt;br /&gt;
Func _RunWaitAU3($sFilePath, $sCommandLine = &amp;quot;&amp;quot;, $sWorkingDir = &amp;quot;&amp;quot;, $iShowFlag = @SW_SHOW, $iOptFlag = 0)&lt;br /&gt;
    Local $iPID&lt;br /&gt;
    $iPID = RunWait(&#039;&amp;quot;&#039; &amp;amp; @AutoItExe &amp;amp; &#039;&amp;quot; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; $sCommandLine, $sWorkingDir, $iShowFlag, $iOptFlag)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(@error, 1, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $iPID&lt;br /&gt;
EndFunc   ;==&amp;gt;_RunWaitAU3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Run Any au3 File From Your Program ==&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;
; Run Any Au3 File From Your Program&lt;br /&gt;
&lt;br /&gt;
Global Const $sFilePath = @ScriptDir &amp;amp; &amp;quot;\Test.au3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If @Compiled Then&lt;br /&gt;
	Global Const $sFileExe = FileGetShortName(@AutoItExe &amp;amp; &#039; /AutoIt3ExecuteScript &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot;&#039;)&lt;br /&gt;
	Run($sFileExe)&lt;br /&gt;
Else&lt;br /&gt;
	Global Const $sFileAu3 = FileGetShortName($sFilePath)&lt;br /&gt;
	Run(@AutoItExe &amp;amp; &amp;quot; &amp;quot; &amp;amp; $sFileAu3, &amp;quot;&amp;quot;, @SW_HIDE)&lt;br /&gt;
EndIf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ScriptName ==&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(_ScriptName() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Return the @ScriptName minus the .exe or .au3 extension.&lt;br /&gt;
Func _ScriptName()&lt;br /&gt;
	Return StringLeft(@ScriptName, StringInStr(@ScriptName, &#039;.&#039;, 2, -1) - 1)&lt;br /&gt;
EndFunc   ;==&amp;gt;_ScriptName&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ScriptVersion ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 31149-milesahead&lt;br /&gt;
| AuthorName = MilesAhead&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#NoTrayIcon&lt;br /&gt;
&lt;br /&gt;
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****&lt;br /&gt;
#AutoIt3Wrapper_UseUpx=n&lt;br /&gt;
#AutoIt3Wrapper_Res_Fileversion=1.2.3.4&lt;br /&gt;
#AutoIt3Wrapper_Res_LegalCopyright=2012  www.favessoft.com&lt;br /&gt;
#AutoIt3Wrapper_Res_Language=1033&lt;br /&gt;
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7&lt;br /&gt;
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****&lt;br /&gt;
&lt;br /&gt;
Global $version = _ScriptVersion()&lt;br /&gt;
&lt;br /&gt;
Global $msg = &amp;quot;ScriptVerDemo&amp;quot; &amp;amp; &amp;quot; &amp;quot; &amp;amp; $version &amp;amp; &amp;quot;  Copyright (c) 2012  www.favessoft.com&amp;quot; &amp;amp; @CRLF &amp;amp; @CRLF&lt;br /&gt;
&lt;br /&gt;
MsgBox(0x1040, &amp;quot;&amp;quot;, $msg)&lt;br /&gt;
&lt;br /&gt;
; return File Version string from compiled or .au3 script&lt;br /&gt;
; returns &amp;quot;&amp;quot; if no version info available&lt;br /&gt;
; Note: The .au3 script must contain #AutoItWrapper&lt;br /&gt;
; directives with file version or &amp;quot;&amp;quot; is returned.&lt;br /&gt;
Func _ScriptVersion(Const $Script = @ScriptFullPath)&lt;br /&gt;
    If StringRight($Script,4) = &amp;quot;.exe&amp;quot; Then&lt;br /&gt;
        Return FileGetVersion($Script)&lt;br /&gt;
    Else&lt;br /&gt;
        Local Const $scriptHandle = FileOpen($Script)&lt;br /&gt;
		Local $ver&lt;br /&gt;
		Local $found = False&lt;br /&gt;
		Local $pos&lt;br /&gt;
&lt;br /&gt;
        If $scriptHandle &amp;lt;&amp;gt; -1 Then&lt;br /&gt;
            Do&lt;br /&gt;
                $ver = FileReadLine($scriptHandle)&lt;br /&gt;
                $sPos = StringInStr($ver, &amp;quot;_Fileversion=&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
                If $sPos Then&lt;br /&gt;
                    $ver = StringMid($ver, $sPos + StringLen(&amp;quot;_Fileversion=&amp;quot;))&lt;br /&gt;
                    $found = True&lt;br /&gt;
                    ExitLoop&lt;br /&gt;
                EndIf&lt;br /&gt;
            Until StringLeft($ver, 1) &amp;lt;&amp;gt; &amp;quot;#&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            FileClose($scriptHandle)&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    If Not $found Then $ver = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    Return $ver&lt;br /&gt;
EndFunc   ;==&amp;gt;_ScriptVersion&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SetFile ==&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;
; FileWrite Alternative&lt;br /&gt;
&lt;br /&gt;
Func _SetFile(Const $sString, Const $sFile, Const $iOverwrite = 0)&lt;br /&gt;
    Local Const $hFileOpen = FileOpen($sFile, $iOverwrite + 1)&lt;br /&gt;
&lt;br /&gt;
    FileWrite($hFileOpen, $sString)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $sString)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return $sString&lt;br /&gt;
EndFunc   ;==&amp;gt;_SetFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ShowHelp ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 60350-chimaera&lt;br /&gt;
| AuthorName = Chimaera&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
HotKeySet(&amp;quot;{F1}&amp;quot;, &amp;quot;_ShowHelp&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _ShowHelp()&lt;br /&gt;
	Return ShellExecute(@ProgramFilesDir &amp;amp; &amp;quot;\AutoIt3\AutoIt3Help.exe&amp;quot;) ; change this to the location of your own helpfile.&lt;br /&gt;
EndFunc   ;==&amp;gt;_ShowHelp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SingletonPID ==&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;
Local $iSingleton = _SingletonPID(&#039;RandomName&#039;, 1)&lt;br /&gt;
&lt;br /&gt;
If $iSingleton = 0 Then&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;This is the first instance of the program running: &#039; &amp;amp; $iSingleton)&lt;br /&gt;
Else&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;There is another instance running. This PID is: &#039; &amp;amp; $iSingleton)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name ..........: _SingletonPID&lt;br /&gt;
; Description ...: Enforce a design paradigm where only one instance of the script may be running.&lt;br /&gt;
; Syntax ........: _SingletonPID($sOccurenceName[, $iFlag = 0])&lt;br /&gt;
; Parameters ....: $sOccurenceName      - String to identify the occurrence of the script.&lt;br /&gt;
;                  $iFlag               - [optional] Optional parameters. Default is 0.&lt;br /&gt;
;                  0 - Exit the script with the exit code -1 if another instance already exists.&lt;br /&gt;
;                  1 - Return the PID of the main executable and without exiting the script too.&lt;br /&gt;
; Return values .: Success - 0 No other process is running.&lt;br /&gt;
;                  Failure - The PID of the main executable.&lt;br /&gt;
; Author ........: guinness with initial ideas by Valik for _Singleton &amp;amp; KaFu for _EnforceSingleInstance.&lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _SingletonPID(Const $sOccurenceName, Const $iFlag = 0)&lt;br /&gt;
    Local $hHandle = WinGetHandle($sOccurenceName)&lt;br /&gt;
&lt;br /&gt;
    If @error Then&lt;br /&gt;
        AutoItWinSetTitle($sOccurenceName)&lt;br /&gt;
        $hHandle = WinGetHandle($sOccurenceName)&lt;br /&gt;
        ControlSetText($hHandle, &#039;&#039;, ControlGetHandle($hHandle, &#039;&#039;, &#039;Edit1&#039;), @AutoItPID)&lt;br /&gt;
    Else&lt;br /&gt;
        If BitAND($iFlag, 1) Then&lt;br /&gt;
            Return Number(ControlGetText($hHandle, &#039;&#039;, ControlGetHandle($hHandle, &#039;&#039;, &#039;Edit1&#039;)))&lt;br /&gt;
        Else&lt;br /&gt;
            Exit -1&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_SingletonPID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _Sort ==&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(_Sort(&amp;quot;$sVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$iVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$tVariable&amp;quot; &amp;amp; @CRLF &amp;amp; &amp;quot;$pVariable&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
Func _Sort(Const $sSortList)&lt;br /&gt;
    Local Const $iPID = Run(&amp;quot;sort.exe&amp;quot;, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD), $sOutput = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    StdinWrite($iPID, $sSortList)&lt;br /&gt;
    StdinWrite($iPID)&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;_Sort&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Speak Object and Save to WAV File ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 52278-solidsnake26&lt;br /&gt;
| AuthorName = SolidSnake26&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Speak Object and save to wav file&lt;br /&gt;
&lt;br /&gt;
_SpeakToWAV(&amp;quot;AutoIt Snippets&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\SavedFile.wav&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _SpeakToWAV(Const $sText, Const $sFilePath)&lt;br /&gt;
	Local $ObjVoice = ObjCreate(&amp;quot;Sapi.SpVoice&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	Local $ObjFile = ObjCreate(&amp;quot;Sapi.SpFileStream.1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	$ObjVoice.Speak($sText)&lt;br /&gt;
&lt;br /&gt;
	$ObjFile.Open($sFilePath, 3)&lt;br /&gt;
&lt;br /&gt;
	$ObjVoice.AudioOutputStream = $ObjFile&lt;br /&gt;
EndFunc   ;==&amp;gt;_SpeakToWAV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _VariableSwap ==&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;
Global $sString_1 = &#039;This is string 1.&#039;&lt;br /&gt;
Global $sString_2 = &#039;This is string 2.&#039;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;$sString_1: &#039; &amp;amp; $sString_1 &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(&#039;$sString_2: &#039; &amp;amp; $sString_2 &amp;amp; @CRLF &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
_VariableSwap($sString_1, $sString_2)&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;$sString_1: &#039; &amp;amp; $sString_1 &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(&#039;$sString_2: &#039; &amp;amp; $sString_2 &amp;amp; @CRLF &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Swap the contents of two variables.&lt;br /&gt;
Func _VariableSwap(ByRef $vVariable_1, ByRef $vVariable_2) ; Similar to _ArraySwap though not obvious to some this isn&#039;t limited to arrays.&lt;br /&gt;
    Local Const $vTemp = $vVariable_1&lt;br /&gt;
    $vVariable_1 = $vVariable_2&lt;br /&gt;
    $vVariable_2 = $vTemp&lt;br /&gt;
EndFunc   ;==&amp;gt;_VariableSwap&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_CharLower ==&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;
;Convert characters to upper or lower case&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_WinAPI_CharLower(&amp;quot;EXAMPLE&amp;quot;) &amp;amp; @CRLF) ; Similar to StringLower.&lt;br /&gt;
&lt;br /&gt;
; Convert characters to lowercase.&lt;br /&gt;
Func _WinAPI_CharLower($sString)&lt;br /&gt;
    Local $aReturn = DllCall(&#039;user32.dll&#039;, &#039;wstr&#039;, &#039;CharLowerW&#039;, &#039;wstr&#039;, $sString)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $sString)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_CharLower&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_CharUpper ==&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(_WinAPI_CharUpper(&amp;quot;example&amp;quot;) &amp;amp; @CRLF) ; Similar to StringUpper.&lt;br /&gt;
&lt;br /&gt;
; Convert characters to uppercase.&lt;br /&gt;
Func _WinAPI_CharUpper($sString)&lt;br /&gt;
	Local $aReturn = DllCall(&#039;user32.dll&#039;, &#039;wstr&#039;, &#039;CharUpperW&#039;, &#039;wstr&#039;, $sString)&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Return SetError(1, 0, $sString)&lt;br /&gt;
	EndIf&lt;br /&gt;
	Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_CharUpper&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinAPI_PathFileExists ==&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;
; An API Alternative To FileExist.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(@ScriptFullPath) &amp;amp; @LF) ; File.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(&amp;quot;C:\&amp;quot;) &amp;amp; @LF) ; Drive.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(@ProgramFilesDir) &amp;amp; @LF) ; Directory.&lt;br /&gt;
ConsoleWrite(_WinAPI_PathFileExists(&amp;quot;Z:\File.txt&amp;quot;) &amp;amp; @LF) ; Shouldn&#039;t exist!&lt;br /&gt;
&lt;br /&gt;
Func _WinAPI_PathFileExists($sFilePath)&lt;br /&gt;
    Local $aReturn = DllCall(&#039;shlwapi.dll&#039;, &#039;int&#039;, &#039;PathFileExistsW&#039;, &#039;wstr&#039;, $sFilePath)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinAPI_PathFileExists&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinActiveByExe ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 4813-smoke-n&lt;br /&gt;
| AuthorName = SmOke_N&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Window Active/Activate by Exe, Open Notepad whilst script is running&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
    If _WinActiveByExe(&#039;notepad.exe&#039;, False) Then MsgBox(64, &#039;info&#039;, &#039;true&#039;)&lt;br /&gt;
    Sleep(100)&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func _WinActiveByExe($sExe, $iActive = True);False to WinActivate, True to just see if it&#039;s active&lt;br /&gt;
    If Not ProcessExists($sExe) Then Return SetError(1, 0, 0)&lt;br /&gt;
    Local $aPL = ProcessList($sExe)&lt;br /&gt;
    Local $aWL = WinList()&lt;br /&gt;
    For $iCC = 1 To $aWL[0][0]&lt;br /&gt;
        For $xCC = 1 To $aPL[0][0]&lt;br /&gt;
            If $aWL[$iCC][0] &amp;lt;&amp;gt; &#039;&#039; And _&lt;br /&gt;
                WinGetProcess($aWL[$iCC][1]) = $aPL[$xCC][1] And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) Then&lt;br /&gt;
                If $iActive And WinActive($aWL[$iCC][1]) Then Return 1&lt;br /&gt;
                If Not $iActive And Not WinActive($aWL[$iCC][1]) Then&lt;br /&gt;
                    WinActivate($aWL[$iCC][1])&lt;br /&gt;
                    Return 1&lt;br /&gt;
                EndIf&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
    Next&lt;br /&gt;
    Return SetError(2, 0, 0)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WindowShake ==&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;
; Shake a window left to right.&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Run Notepad&lt;br /&gt;
    Run(&amp;quot;notepad.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    ; Wait 10 seconds for the Notepad window to appear.&lt;br /&gt;
    Local $hWnd = WinWait(&amp;quot;[CLASS:Notepad]&amp;quot;, &amp;quot;&amp;quot;, 10)&lt;br /&gt;
&lt;br /&gt;
    ; Wait for 1 second.&lt;br /&gt;
    Sleep(1000)&lt;br /&gt;
&lt;br /&gt;
    ; Shake the Notepad window left to right.&lt;br /&gt;
    _WindowShake($hWnd)&lt;br /&gt;
&lt;br /&gt;
    ; Wait for 1 second.&lt;br /&gt;
    Sleep(1000)&lt;br /&gt;
&lt;br /&gt;
    ; Close the Notepad window using the handle returned by WinWait.&lt;br /&gt;
    WinClose($hWnd)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _WindowShake($sTitle, $sText = &#039;&#039;, $iDistance = 20)&lt;br /&gt;
    Local $hWnd = WinGetHandle($sTitle, $sText)&lt;br /&gt;
    Local $aWinGetPos = WinGetPos($hWnd)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $aArray[5] = [4, $aWinGetPos[0] + $iDistance, $aWinGetPos[0], $aWinGetPos[0] + $iDistance, $aWinGetPos[0]]&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To $aArray[0]&lt;br /&gt;
        WinMove($hWnd, &#039;&#039;, $aArray[$i], Default)&lt;br /&gt;
        Sleep(100)&lt;br /&gt;
    Next&lt;br /&gt;
EndFunc   ;==&amp;gt;_WindowShake&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetDetails ==&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;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $aArray = _WinGetDetails(&#039;[ACTIVE]&#039;) ; Returns the Window&#039;s title, PID, folder path filename.&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    Exit&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&lt;br /&gt;
Func _WinGetDetails($sTitle, $sText = &#039;&#039;) ; Based on code of _WinGetPath by GaryFrost.&lt;br /&gt;
    Local $aReturn[5] = [4, &#039;-WinTitle&#039;, &#039;-PID&#039;, &#039;-FolderPath&#039;, &#039;-FileName&#039;], $aStringSplit&lt;br /&gt;
&lt;br /&gt;
    If StringLen($sText) &amp;gt; 0 Then&lt;br /&gt;
        $aReturn[1] = WinGetTitle($sTitle, $sText)&lt;br /&gt;
    Else&lt;br /&gt;
        $aReturn[1] = WinGetTitle($sTitle)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aReturn[2] = WinGetProcess($aReturn[1])&lt;br /&gt;
&lt;br /&gt;
    Local $oWMIService = ObjGet(&#039;winmgmts:\\.\root\CIMV2&#039;)&lt;br /&gt;
    Local $oItems = $oWMIService.ExecQuery(&#039;Select * From Win32_Process Where ProcessId = &#039; &amp;amp; $aReturn[2], &#039;WQL&#039;, 0x30)&lt;br /&gt;
    If IsObj($oItems) Then&lt;br /&gt;
        For $oItem In $oItems&lt;br /&gt;
            If $oItem.ExecutablePath Then&lt;br /&gt;
                $aStringSplit = StringSplit($oItem.ExecutablePath, &#039;\&#039;)&lt;br /&gt;
                $aReturn[3] = &#039;&#039;&lt;br /&gt;
                For $A = 1 To $aStringSplit[0] - 1&lt;br /&gt;
                    $aReturn[3] &amp;amp;= $aStringSplit[$A] &amp;amp; &#039;\&#039;&lt;br /&gt;
                Next&lt;br /&gt;
                $aReturn[3] = StringTrimRight($aReturn[3], 1)&lt;br /&gt;
                $aReturn[4] = $aStringSplit[$aStringSplit[0]]&lt;br /&gt;
                Return $aReturn&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return SetError(1, 0, $aReturn)&lt;br /&gt;
EndFunc   ;==&amp;gt;_WinGetPath&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetNumeratedClassList ==&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;
; Description: Retrieves the numerated classes from a window.&lt;br /&gt;
&lt;br /&gt;
Func _WinGetNumeratedClassList($sTitle)&lt;br /&gt;
    Local $sClassList = WinGetClassList($sTitle)&lt;br /&gt;
    Local $aClassList = StringSplit($sClassList, @LF)&lt;br /&gt;
    Local $sRetClassList = &amp;quot;&amp;quot;, $sHold_List = &amp;quot;|&amp;quot;&lt;br /&gt;
    Local $aiInHold, $iInHold&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To UBound($aClassList) - 1&lt;br /&gt;
        If $aClassList[$i] = &amp;quot;&amp;quot; Then ContinueLoop&lt;br /&gt;
&lt;br /&gt;
        If StringRegExp($sHold_List, &amp;quot;\|&amp;quot; &amp;amp; $aClassList[$i] &amp;amp; &amp;quot;~(\d+)\|&amp;quot;) Then&lt;br /&gt;
            $aiInHold = StringRegExp($sHold_List, &amp;quot;.*\|&amp;quot; &amp;amp; $aClassList[$i] &amp;amp; &amp;quot;~(\d+)\|.*&amp;quot;, 1)&lt;br /&gt;
            $iInHold = Number($aiInHold[UBound($aiInHold)-1])&lt;br /&gt;
&lt;br /&gt;
            If $iInHold = 0 Then $iInHold += 1&lt;br /&gt;
&lt;br /&gt;
            $aClassList[$i] &amp;amp;= &amp;quot;~&amp;quot; &amp;amp; $iInHold + 1&lt;br /&gt;
            $sHold_List &amp;amp;= $aClassList[$i] &amp;amp; &amp;quot;|&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            $sRetClassList &amp;amp;= $aClassList[$i] &amp;amp; @LF&lt;br /&gt;
        Else&lt;br /&gt;
            $aClassList[$i] &amp;amp;= &amp;quot;~1&amp;quot;&lt;br /&gt;
            $sHold_List &amp;amp;= $aClassList[$i] &amp;amp; &amp;quot;|&amp;quot;&lt;br /&gt;
            $sRetClassList &amp;amp;= $aClassList[$i] &amp;amp; @LF&lt;br /&gt;
        EndIf&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    Return StringReplace(StringStripWS($sRetClassList, 3), &amp;quot;~&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WinGetHandleByPID ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 4813-smoke-n&lt;br /&gt;
| AuthorName = SmOke_N&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Get Window Handle by PID&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $a1 = _WinGetHandleByPID(232)&lt;br /&gt;
Global $a2 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, -1)&lt;br /&gt;
Global $a3 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, 0)&lt;br /&gt;
Global $a4 = _WinGetHandleByPID(&amp;quot;notepad.exe&amp;quot;, 1)&lt;br /&gt;
&lt;br /&gt;
_ArrayDisplay($a1, &amp;quot;1&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a2, &amp;quot;2&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a3, &amp;quot;3&amp;quot;)&lt;br /&gt;
_ArrayDisplay($a4, &amp;quot;4&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
;$nVisible = -1 &amp;quot;All (Visble or not)&amp;quot;, $nVisible = 0 &amp;quot;Not Visible Only&amp;quot;, $nVisible = 1 &amp;quot;Visible Only&amp;quot;&lt;br /&gt;
Func _WinGetHandleByPID($vProc, $nVisible = 1)&lt;br /&gt;
    $vProc = ProcessExists($vProc);&lt;br /&gt;
&lt;br /&gt;
    If Not $vProc Then Return SetError(1, 0, 0)&lt;br /&gt;
&lt;br /&gt;
    Local $aWL = WinList()&lt;br /&gt;
&lt;br /&gt;
    Local $aTemp[UBound($aWL)][2]&lt;br /&gt;
&lt;br /&gt;
	Local $nAdd = 0&lt;br /&gt;
&lt;br /&gt;
    For $iCC = 1 To $aWL[0][0]&lt;br /&gt;
        If $nVisible = -1 And WinGetProcess($aWL[$iCC][1]) = $vProc Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        ElseIf $nVisible = 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) = 0 Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        ElseIf $nVisible &amp;gt; 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _&lt;br /&gt;
                BitAND(WinGetState($aWL[$iCC][1]), 2) Then&lt;br /&gt;
            $nAdd += 1&lt;br /&gt;
            $aTemp[$nAdd][0] = $aWL[$iCC][0]&lt;br /&gt;
            $aTemp[$nAdd][1] = $aWL[$iCC][1]&lt;br /&gt;
        EndIf&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    If $nAdd = 0 Then Return SetError(2, 0, 0) ; No windows found&lt;br /&gt;
&lt;br /&gt;
    ReDim $aTemp[$nAdd + 1][2]&lt;br /&gt;
&lt;br /&gt;
    $aTemp[0][0] = $nAdd&lt;br /&gt;
&lt;br /&gt;
    Return $aTemp&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12548</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=12548"/>
		<updated>2014-06-27T09:37:43Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Names of Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
* You must use the latest version of 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;
== Names of Variables ==&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation] is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&lt;br /&gt;
&lt;br /&gt;
Variables are initialized with the &amp;quot;default&amp;quot; value (or the most efficient value) of their type. See below in the table for specific value.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! initialization&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $f = 0.0&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $n = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $a = 0 or $a[0]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot; or $s = Null&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $b = False or $b = True &lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $d = Binary(&amp;quot;&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlid || $id = 0&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| fu || Functions || $fu = Null&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = 0&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0 or $o = Null&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $v = 0 or $v = &amp;quot;&amp;quot; (or $v = Null)&lt;br /&gt;
|-&lt;br /&gt;
| e || Enumerations || N/A&lt;br /&gt;
|-&lt;br /&gt;
| k || Keywords || $k = Default&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
;Good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
Example2:&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;
Local $vValue ; Bad, this is initially blank.&lt;br /&gt;
Local $vVal = 0 ; Good&lt;br /&gt;
&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$vValue: &#039; &amp;amp; $vValue &amp;amp; @CRLF &amp;amp; &#039;$vVal: &#039; &amp;amp; $vVal)&lt;br /&gt;
&lt;br /&gt;
; In C++ $vValue would display the previous value that was residing in the memory address $vValue points to. AutoIt&lt;br /&gt;
; is a little less forgiving in that it initialises the variable as being blank and doesn&#039;t throw any error, unlike some moder C++ compilers.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
&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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&lt;br /&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;
&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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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;
&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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;
&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;
&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 $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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 $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 $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;, $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 $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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;
&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 efficent 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;
&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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&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;
;Good&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;
&lt;br /&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;
&lt;br /&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;
&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;
&lt;br /&gt;
&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;
&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=UDF-spec&amp;diff=12547</id>
		<title>UDF-spec</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=UDF-spec&amp;diff=12547"/>
		<updated>2014-06-27T09:32:54Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Basic Requirements */&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;
* Not use any magic numbers. Ever. None. At all. No excuses.&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;
* Not make any permanent changes to the users computer. For example, if demonstrating a File function, be sure to delete the file after it has been used. The same applies for any function that makes a change to the environment: the changes MUST be undone.&lt;br /&gt;
&lt;br /&gt;
Always remember, the readability of code in an example is MORE important than the readability of code inside the UDF itself.&lt;br /&gt;
&lt;br /&gt;
Examples are stored in script 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;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;#include &amp;lt;Constants.au3&amp;gt;&lt;br /&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($MB_SYSTEMMODAL, &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;
=== Multiple Examples ===&lt;br /&gt;
The helpfile now supports multiple examples per function. In order to maintain backwards compatibility with any other tools that use examples, the first file is still named &amp;lt;code&amp;gt;&amp;amp;lt;FUNCTION&amp;amp;gt;.au3&amp;lt;/code&amp;gt;, but any additional examples are named &amp;lt;code&amp;gt;&amp;amp;lt;FUNCTION&amp;amp;gt;[n].au3&amp;lt;/code&amp;gt; where n is an integer counter starting at 2.&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12546</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=12546"/>
		<updated>2014-06-27T09:31:28Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Scopes of Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
* You must use the latest version of 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;
== Names of Variables ==&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation] is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&lt;br /&gt;
&lt;br /&gt;
Variables are initialized with the &amp;quot;default&amp;quot; value (or the most efficient value) of their type. See below in the table for specific value.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! initialization&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $f = 0.0&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $n = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $a = 0 or $a[0]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot; or $s = Null&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $b = False or $b = True &lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $d = Binary(&amp;quot;&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlid || $id = 0&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| fu || Functions || $fu = Null&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = 0&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $v = 0 or $v = &amp;quot;&amp;quot; (or $v = Null)&lt;br /&gt;
|-&lt;br /&gt;
| e || Enumerations || N/A&lt;br /&gt;
|-&lt;br /&gt;
| k || Keywords || $k = Default&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
;Good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
Example2:&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;
Local $vValue ; Bad, this is initially blank.&lt;br /&gt;
Local $vVal = 0 ; Good&lt;br /&gt;
&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$vValue: &#039; &amp;amp; $vValue &amp;amp; @CRLF &amp;amp; &#039;$vVal: &#039; &amp;amp; $vVal)&lt;br /&gt;
&lt;br /&gt;
; In C++ $vValue would display the previous value that was residing in the memory address $vValue points to. AutoIt&lt;br /&gt;
; is a little less forgiving in that it initialises the variable as being blank and doesn&#039;t throw any error, unlike some moder C++ compilers.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
&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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&lt;br /&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;
&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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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;
&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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;
&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;
&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 $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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 $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 $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;, $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 $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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;
&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 efficent 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;
&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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&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;
;Good&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;
&lt;br /&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;
&lt;br /&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;
&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;
&lt;br /&gt;
&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;
&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12545</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=12545"/>
		<updated>2014-06-27T08:24:59Z</updated>

		<summary type="html">&lt;p&gt;Guinness: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
* You must use the latest version of 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;
== Names of Variables ==&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation] is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&lt;br /&gt;
&lt;br /&gt;
Variables are initialized with the &amp;quot;default&amp;quot; value (or the most efficient value) of their type. See below in the table for specific value.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! initialization&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $f = 0.0&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $n = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $a = 0 or $a[0]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot; or $s = Null&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $b = False or $b = True &lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $d = Binary(&amp;quot;&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlid || $id = 0&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| fu || Functions || $fu = Null&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = 0&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $v = 0 or $v = &amp;quot;&amp;quot; (or $v = Null)&lt;br /&gt;
|-&lt;br /&gt;
| e || Enumerations || N/A&lt;br /&gt;
|-&lt;br /&gt;
| k || Keywords || $k = Default&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
;Good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
Example2:&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;
Local $vValue ; Bad, this is initially blank.&lt;br /&gt;
Local $vVal = 0 ; Good&lt;br /&gt;
&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$vValue: &#039; &amp;amp; $vValue &amp;amp; @CRLF &amp;amp; &#039;$vVal: &#039; &amp;amp; $vVal)&lt;br /&gt;
&lt;br /&gt;
; In C++ $vValue would display the previous value that was residing in the memory address $vValue points to. AutoIt&lt;br /&gt;
; is a little less forgiving in that it initialises the variable as being blank and doesn&#039;t throw any error, unlike some moder C++ compilers.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
| $__iSomeVar or $g__iSomeVar || $_iSomeVar or $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;
&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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&lt;br /&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;
&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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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;
&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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;
&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;
&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 $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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 $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 $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;, $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 $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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;
&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 efficent 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;
&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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&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;
;Good&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;
&lt;br /&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;
&lt;br /&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;
&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;
&lt;br /&gt;
&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;
&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12544</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=12544"/>
		<updated>2014-06-27T08:24:18Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Scopes of Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
* You must use the latest version of 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;
== Names of Variables ==&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation] is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&lt;br /&gt;
&lt;br /&gt;
Variables are initialized with the &amp;quot;default&amp;quot; value (or the most efficient value) of their type. See below in the table for specific value.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! initialization&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $f = 0.0&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $n = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $a = 0 or $a[0]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot; or $s = Null&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $b = False or $b = True &lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $d = Binary(&amp;quot;&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlid || $id = 0&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| fu || Functions || $fu = Null&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = 0&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $v = 0 or $v = &amp;quot;&amp;quot; (or $v = Null)&lt;br /&gt;
|-&lt;br /&gt;
| e || Enumerations || N/A&lt;br /&gt;
|-&lt;br /&gt;
| k || Keywords || $k = Default&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
;Good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
Example2:&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;
Local $vValue ; Bad, this is initially blank.&lt;br /&gt;
Local $vVal = 0 ; Good&lt;br /&gt;
&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$vValue: &#039; &amp;amp; $vValue &amp;amp; @CRLF &amp;amp; &#039;$vVal: &#039; &amp;amp; $vVal)&lt;br /&gt;
&lt;br /&gt;
; In C++ $vValue would display the previous value that was residing in the memory address $vValue points to. AutoIt&lt;br /&gt;
; is a little less forgiving in that it initialises the variable as being blank and doesn&#039;t throw any error, unlike some moder C++ compilers.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
| $__iSomeVar or $g__iSomeVar || $_iSomeVar or $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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MessageBoxConstants.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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&lt;br /&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;
&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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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;
&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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;
&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;
&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 $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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 $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 $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;, $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 $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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;
&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 efficent 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;
&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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&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;
;Good&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;MessageBoxConstants.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;
&lt;br /&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;
&lt;br /&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;
&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;
&lt;br /&gt;
&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;
&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12543</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=12543"/>
		<updated>2014-06-27T08:23:14Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Names of Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
* You must use the latest version of 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;
== Names of Variables ==&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation] is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&lt;br /&gt;
&lt;br /&gt;
Variables are initialized with the &amp;quot;default&amp;quot; value (or the most efficient value) of their type. See below in the table for specific value.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! initialization&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $f = 0.0&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $n = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $a = 0 or $a[0]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot; or $s = Null&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $b = False or $b = True &lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $d = Binary(&amp;quot;&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlid || $id = 0&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| fu || Functions || $fu = Null&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = 0&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $v = 0 or $v = &amp;quot;&amp;quot; (or $v = Null)&lt;br /&gt;
|-&lt;br /&gt;
| e || Enumerations || N/A&lt;br /&gt;
|-&lt;br /&gt;
| k || Keywords || $k = Default&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
;Good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
Example2:&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;
Local $vValue ; Bad, this is initially blank.&lt;br /&gt;
Local $vVal = 0 ; Good&lt;br /&gt;
&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$vValue: &#039; &amp;amp; $vValue &amp;amp; @CRLF &amp;amp; &#039;$vVal: &#039; &amp;amp; $vVal)&lt;br /&gt;
&lt;br /&gt;
; In C++ $vValue would display the previous value that was residing in the memory address $vValue points to. AutoIt&lt;br /&gt;
; is a little less forgiving in that it initialises the variable as being blank and doesn&#039;t throw any error, unlike some moder C++ compilers.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
| $__iSomeVar or $g__iSomeVar || $_iSomeVar or $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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MessageBoxConstants.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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&lt;br /&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;
&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;MessageBoxConstants.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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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;
&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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;
&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;
&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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Dim $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling Example() first will initialise the Global variable $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 $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;, $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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling SomeFunc() first will bypass the Global variable $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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;
&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;MessageBoxConstants.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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables outside of loops is more efficent 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;
&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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&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;
;Good&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;MessageBoxConstants.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;
&lt;br /&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;
&lt;br /&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;
&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;
&lt;br /&gt;
&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;
&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12542</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=12542"/>
		<updated>2014-06-27T08:22:41Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Names of Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
* You must use the latest version of 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;
== Names of Variables ==&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation] is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&lt;br /&gt;
&lt;br /&gt;
Variables are initialized with the &amp;quot;default&amp;quot; value (or the most efficient value) of their type. See below in the table for specific value.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! initialization&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $f = 0.0&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $n = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $a = 0 or $a[0]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot; or $s = Null&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $b = False or $b = True &lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $d = Binary(&amp;quot;&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlid || $id = 0&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| fu || Functions || $fu = Null&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = 0&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $v = 0 or $v = &amp;quot;&amp;quot; (or $v = Null)&lt;br /&gt;
|-&lt;br /&gt;
| e || Enumerations || N/A&lt;br /&gt;
|-&lt;br /&gt;
| k || Keywords || $k = Default&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
;Good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
Example2:&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;
Local $vValue ; Bad, this is initially blank.&lt;br /&gt;
Local $vVal = 0 ; Good&lt;br /&gt;
&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$vValue: &#039; &amp;amp; $vValue &amp;amp; @CRLF &amp;amp; &#039;$vVal: &#039; &amp;amp; $vVal)&lt;br /&gt;
&lt;br /&gt;
; In C++ $vValue would display the previous value that was residing in the memory address $vValue points to. AutoIt&lt;br /&gt;
; is a little less forgiving in that it initialises the variable as being blank and doesn&#039;t throw any error, unlike some moder C++ compilers.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
| $__iSomeVar or $g__iSomeVar || $_iSomeVar or $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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MessageBoxConstants.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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&lt;br /&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;
&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;MessageBoxConstants.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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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;
&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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;
&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;
&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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Dim $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling Example() first will initialise the Global variable $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 $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;, $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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling SomeFunc() first will bypass the Global variable $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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;
&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;MessageBoxConstants.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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables outside of loops is more efficent 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;
&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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&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;
;Good&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;MessageBoxConstants.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;
&lt;br /&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;
&lt;br /&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;
&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;
&lt;br /&gt;
&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;
&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12541</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=12541"/>
		<updated>2014-06-27T08:21:57Z</updated>

		<summary type="html">&lt;p&gt;Guinness: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
* You must use the latest version of 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;
== Names of Variables ==&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation] is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&lt;br /&gt;
&lt;br /&gt;
Variables are initialized with the &amp;quot;default&amp;quot; value (or the most efficient value) of their type. See below in the table for specific value.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! initialization&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $f = 0.0&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $n = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $a = 0 or $a[0]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot; or $s = Null&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $b = False or $b = True &lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $d = Binary(&amp;quot;&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlid || $id = 0&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| k (ND) || Keywords || $k = Default&lt;br /&gt;
|-&lt;br /&gt;
| fu (ND) || Functions || $fu = Null&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = 0&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $v = 0 or $v = &amp;quot;&amp;quot; (or $v = Null)&lt;br /&gt;
|-&lt;br /&gt;
| e || Enumerations || N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
;Good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
Example2:&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;
Local $vValue ; Bad, this is initially blank.&lt;br /&gt;
Local $vVal = 0 ; Good&lt;br /&gt;
&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$vValue: &#039; &amp;amp; $vValue &amp;amp; @CRLF &amp;amp; &#039;$vVal: &#039; &amp;amp; $vVal)&lt;br /&gt;
&lt;br /&gt;
; In C++ $vValue would display the previous value that was residing in the memory address $vValue points to. AutoIt&lt;br /&gt;
; is a little less forgiving in that it initialises the variable as being blank and doesn&#039;t throw any error, unlike some moder C++ compilers.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
| $__iSomeVar or $g__iSomeVar || $_iSomeVar or $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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MessageBoxConstants.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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&lt;br /&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;
&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;MessageBoxConstants.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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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;
&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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;
&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;
&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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Dim $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling Example() first will initialise the Global variable $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 $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;, $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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling SomeFunc() first will bypass the Global variable $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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;
&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;MessageBoxConstants.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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables outside of loops is more efficent 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;
&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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&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;
;Good&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;MessageBoxConstants.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;
&lt;br /&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;
&lt;br /&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;
&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;
&lt;br /&gt;
&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;
&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12540</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=12540"/>
		<updated>2014-06-27T08:20:51Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Names of Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
* &amp;quot;(ND)&amp;quot; stands for &amp;quot;Not decided&amp;quot;, meaning that the writer decided himself the best coding practice and it has to be validated by another MVP/a Developer.&lt;br /&gt;
* You must use the latest beta to run the below examples.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Names of Variables ==&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation] is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&lt;br /&gt;
&lt;br /&gt;
Variables are initialized with the &amp;quot;default&amp;quot; value (or the most efficient value) of their type. See below in the table for specific value.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! initialization&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $f = 0.0&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no preference) || $n = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $a = 0 or $a[0]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot; or $s = Null&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $b = False or $b = True &lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $d = Binary(&amp;quot;&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlid || $id = 0&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| k (ND) || Keywords || $k = Default&lt;br /&gt;
|-&lt;br /&gt;
| fu (ND) || Functions || $fu = Null&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = 0&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $v = 0 or $v = &amp;quot;&amp;quot; (or $v = Null)&lt;br /&gt;
|-&lt;br /&gt;
| e || Enumerations || N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
;Good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
Example2:&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;
Local $vValue ; Bad, this is initially blank.&lt;br /&gt;
Local $vVal = 0 ; Good&lt;br /&gt;
&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$vValue: &#039; &amp;amp; $vValue &amp;amp; @CRLF &amp;amp; &#039;$vVal: &#039; &amp;amp; $vVal)&lt;br /&gt;
&lt;br /&gt;
; In C++ $vValue would display the previous value that was residing in the memory address $vValue points to. AutoIt&lt;br /&gt;
; is a little less forgiving in that it initialises the variable as being blank and doesn&#039;t throw any error, unlike some moder C++ compilers.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
| $__iSomeVar or $g__iSomeVar || $_iSomeVar or $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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MessageBoxConstants.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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&lt;br /&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;
&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;MessageBoxConstants.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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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;
&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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;
&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;
&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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Dim $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling Example() first will initialise the Global variable $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 $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;, $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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling SomeFunc() first will bypass the Global variable $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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;
&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;MessageBoxConstants.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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables outside of loops is more efficent 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;
&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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&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;
;Good&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;MessageBoxConstants.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;
&lt;br /&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;
&lt;br /&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;
&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;
&lt;br /&gt;
&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;
&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12539</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=12539"/>
		<updated>2014-06-27T08:18:30Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Names of Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
* &amp;quot;(ND)&amp;quot; stands for &amp;quot;Not decided&amp;quot;, meaning that the writer decided himself the best coding practice and it has to be validated by another MVP/a Developer.&lt;br /&gt;
* You must use the latest beta to run the below examples.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Names of Variables ==&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation] is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&lt;br /&gt;
&lt;br /&gt;
Variables are initialized with the &amp;quot;default&amp;quot; value (or the most efficient value) of their type. See below in the table for specific value.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! initialization&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $f = 0.0&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no pref) || $n = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $a = 0 or $a[0]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $b = False or $b = True &lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $d = Binary(&amp;quot;&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlid || $id = 0&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| k (ND) || Keywords || Null (ND)&lt;br /&gt;
|-&lt;br /&gt;
| fu (ND) || Functions || Null (ND)&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = 0&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $v = 0 or $v = &amp;quot;&amp;quot; (or $v = Null)&lt;br /&gt;
|-&lt;br /&gt;
| e || Enumerations || N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
;Good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
Example2:&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;
Local $vValue ; Bad, this is initially blank.&lt;br /&gt;
Local $vVal = 0 ; Good&lt;br /&gt;
&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$vValue: &#039; &amp;amp; $vValue &amp;amp; @CRLF &amp;amp; &#039;$vVal: &#039; &amp;amp; $vVal)&lt;br /&gt;
&lt;br /&gt;
; In C++ $vValue would display the previous value that was residing in the memory address $vValue points to. AutoIt&lt;br /&gt;
; is a little less forgiving in that it initialises the variable as being blank and doesn&#039;t throw any error, unlike some moder C++ compilers.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
| $__iSomeVar or $g__iSomeVar || $_iSomeVar or $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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MessageBoxConstants.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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&lt;br /&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;
&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;MessageBoxConstants.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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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;
&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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;
&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;
&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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Dim $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling Example() first will initialise the Global variable $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 $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;, $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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling SomeFunc() first will bypass the Global variable $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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;
&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;MessageBoxConstants.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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables outside of loops is more efficent 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;
&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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&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;
;Good&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;MessageBoxConstants.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;
&lt;br /&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;
&lt;br /&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;
&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;
&lt;br /&gt;
&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;
&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12538</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=12538"/>
		<updated>2014-06-27T08:14:52Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Scopes of Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
* &amp;quot;(ND)&amp;quot; stands for &amp;quot;Not decided&amp;quot;, meaning that the writer decided himself the best coding practice and it has to be validated by another MVP/a Developer.&lt;br /&gt;
* You must use the latest beta to run the below examples.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Names of Variables ==&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation] is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&lt;br /&gt;
&lt;br /&gt;
Variables are initialized with the &amp;quot;default&amp;quot; value (or the most efficient value) of their type. See below in the table for specific value.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! initialization&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $f = 0.0&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no pref) || $n = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $a = 0 or $a[0]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $b = False or $b = True &lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $d = Binary(&amp;quot;&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlid || $id = 0&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| k (ND) || Keywords || Null (ND)&lt;br /&gt;
|-&lt;br /&gt;
| fu (ND) || Functions || Null (ND)&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = &amp;quot;somedef&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $v = 0 or $v = &amp;quot;&amp;quot; (or $v = Null)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
;Good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
Example2:&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;
Local $vValue ; Bad, this is initially blank.&lt;br /&gt;
Local $vVal = 0 ; Good&lt;br /&gt;
&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$vValue: &#039; &amp;amp; $vValue &amp;amp; @CRLF &amp;amp; &#039;$vVal: &#039; &amp;amp; $vVal)&lt;br /&gt;
&lt;br /&gt;
; In C++ $vValue would display the previous value that was residing in the memory address $vValue points to. AutoIt&lt;br /&gt;
; is a little less forgiving in that it initialises the variable as being blank and doesn&#039;t throw any error, unlike some moder C++ compilers.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
| $__iSomeVar or $g__iSomeVar || $_iSomeVar or $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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MessageBoxConstants.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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&lt;br /&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;
&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;MessageBoxConstants.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 $_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 $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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;
&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 IsArray($vParam1) = 0 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;
&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;
&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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Dim $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling Example() first will initialise the Global variable $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 $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;, $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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling SomeFunc() first will bypass the Global variable $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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;
&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;MessageBoxConstants.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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables outside of loops is more efficent 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;
&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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&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;
;Good&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;MessageBoxConstants.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;
&lt;br /&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;
&lt;br /&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;
&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;
&lt;br /&gt;
&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;
&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12537</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=12537"/>
		<updated>2014-06-27T08:10:38Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Names of Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
* &amp;quot;(ND)&amp;quot; stands for &amp;quot;Not decided&amp;quot;, meaning that the writer decided himself the best coding practice and it has to be validated by another MVP/a Developer.&lt;br /&gt;
* You must use the latest beta to run the below examples.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Names of Variables ==&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation] is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&lt;br /&gt;
&lt;br /&gt;
Variables are initialized with the &amp;quot;default&amp;quot; value (or the most efficient value) of their type. See below in the table for specific value.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! initialization&lt;br /&gt;
|-&lt;br /&gt;
| i || Integer || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| f || Floating point || $f = 0.0&lt;br /&gt;
|-&lt;br /&gt;
| n || General number (no pref) || $n = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $a = 0 or $a[0]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| b || Booleans || $b = False or $b = True &lt;br /&gt;
|-&lt;br /&gt;
| d || Binaries || $d = Binary(&amp;quot;&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| id || An AutoIt controlid || $id = 0&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| k (ND) || Keywords || Null (ND)&lt;br /&gt;
|-&lt;br /&gt;
| fu (ND) || Functions || Null (ND)&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = &amp;quot;somedef&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0&lt;br /&gt;
|-&lt;br /&gt;
| v || Variant || $v = 0 or $v = &amp;quot;&amp;quot; (or $v = Null)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&lt;br /&gt;
;Good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
Example2:&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;
Local $vValue ; Bad, this is initially blank.&lt;br /&gt;
Local $vVal = 0 ; Good&lt;br /&gt;
&lt;br /&gt;
MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;$vValue: &#039; &amp;amp; $vValue &amp;amp; @CRLF &amp;amp; &#039;$vVal: &#039; &amp;amp; $vVal)&lt;br /&gt;
&lt;br /&gt;
; In C++ $vValue would display the previous value that was residing in the memory address $vValue points to. AutoIt&lt;br /&gt;
; is a little less forgiving in that it initialises the variable as being blank and doesn&#039;t throw any error, unlike some moder C++ compilers.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scopes of Variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
| $__iSomeVar or $g__iSomeVar || $_iSomeVar or $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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;MessageBoxConstants.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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* A variable declared globally (with the Global keyword) is visible anywhere in the script.&lt;br /&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;
&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;MessageBoxConstants.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 $_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 MyFunc1.&lt;br /&gt;
$_sVar2 = MyFunc1()&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 MyFunc1()&lt;br /&gt;
	; Local scope.&lt;br /&gt;
&lt;br /&gt;
	; Display the content of $_iVar1.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iVar1: &amp;quot; &amp;amp; $_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&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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 $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;
; Empty the array (and keep its size).&lt;br /&gt;
Dim $aArray[5]&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;
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 MyFunc1 with default parameters ($vParam1 = 0).&lt;br /&gt;
MyFunc1()&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 MyFunc1 with $aiArray as parameter ($vParam1 = $aiArray).&lt;br /&gt;
MyFunc1($aiArray)&lt;br /&gt;
&lt;br /&gt;
Func MyFunc1($vParam1 = 0)&lt;br /&gt;
    ; If $vParam1 is NOT an array then redeclare it to an array.&lt;br /&gt;
    If IsArray($vParam1) = 0 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;MyFunc1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Dim $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;, $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, $vVariableThatIsGlobal) ; The Global variable ($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 $vVariableThatIsGlobal = &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	For $i = 1 To 10&lt;br /&gt;
		$vVariableThatIsGlobal &amp;amp;= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.&lt;br /&gt;
	Next&lt;br /&gt;
	Return $vVariableThatIsGlobal&lt;br /&gt;
EndFunc   ;==&amp;gt;SomeFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling Example() first will initialise the Global variable $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 $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;, $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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Calling SomeFunc() first will bypass the Global variable $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable&lt;br /&gt;
; $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 $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;, $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;
&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;MessageBoxConstants.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;MessageBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Declaring variables outside of loops is more efficent 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;
&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;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Bad&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;
;Good&lt;br /&gt;
Local Const $iMyAge = 19&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&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;
&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;MessageBoxConstants.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;
&lt;br /&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;
&lt;br /&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;
&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;
&lt;br /&gt;
&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;
&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>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_Hardware_Information_)&amp;diff=12412</id>
		<title>Snippets ( Hardware Information )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_Hardware_Information_)&amp;diff=12412"/>
		<updated>2014-05-12T19:47:00Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* _GetUnusedDrives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
[[category:Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Snippet Credit Header}}&lt;br /&gt;
&lt;br /&gt;
== _ComputerNameAndModel ==&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;
; Can return nothing relevant if machine is not a factory build&lt;br /&gt;
Global $aArray = _ComputerNameAndModel() ; Returns an Array with 2 indexes.&lt;br /&gt;
MsgBox(64, &amp;quot;_ComputerNameAndModel()&amp;quot;, &#039;The Product is a &amp;quot;&#039; &amp;amp; $aArray[0] &amp;amp; &#039;&amp;quot; and the Serial Number is &amp;quot;&#039; &amp;amp; $aArray[1] &amp;amp; &#039;&amp;quot;.&#039;)&lt;br /&gt;
&lt;br /&gt;
Func _ComputerNameAndModel()&lt;br /&gt;
    Local $aReturn[2] = [&amp;quot;(Unknown)&amp;quot;, &amp;quot;(Unknown)&amp;quot;], $oColItems, $oWMIService&lt;br /&gt;
&lt;br /&gt;
    $oWMIService = ObjGet(&amp;quot;winmgmts:\\.\root\cimv2&amp;quot;)&lt;br /&gt;
    $oColItems = $oWMIService.ExecQuery(&amp;quot;Select * From Win32_ComputerSystemProduct&amp;quot;, &amp;quot;WQL&amp;quot;, 0x30)&lt;br /&gt;
    If IsObj($oColItems) Then&lt;br /&gt;
        For $oObjectItem In $oColItems&lt;br /&gt;
            $aReturn[0] = $oObjectItem.Name&lt;br /&gt;
            $aReturn[1] = $oObjectItem.IdentifyingNumber&lt;br /&gt;
        Next&lt;br /&gt;
        Return $aReturn&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return SetError(1, 0, $aReturn)&lt;br /&gt;
EndFunc   ;==&amp;gt;_ComputerNameAndModel&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _GetComputerModel ==&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;
; Can return nothing relevant if machine is not a factory build&lt;br /&gt;
ConsoleWrite(_GetComputerModel() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetComputerModel()&lt;br /&gt;
    Local $oWMIService = ObjGet(&amp;quot;winmgmts:\\.\&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    Local $oColItems = $oWMIService.ExecQuery(&amp;quot;Select * From Win32_ComputerSystem&amp;quot;, &amp;quot;WQL&amp;quot;, 0x30)&lt;br /&gt;
	Local $sDescription&lt;br /&gt;
&lt;br /&gt;
    If IsObj($oColItems) Then&lt;br /&gt;
        For $oObjectItem In $oColItems&lt;br /&gt;
            $sDescription &amp;amp;= $oObjectItem.Model&lt;br /&gt;
        Next&lt;br /&gt;
&lt;br /&gt;
        Return $sDescription&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return SetError(1, 1, 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetComputerModel&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _GetComputerModel_2 ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 84272-rindeal&lt;br /&gt;
| AuthorName = rindeal&lt;br /&gt;
| Desc=Faster version of the snippet above&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Can return nothing relevant if machine is not a factory build&lt;br /&gt;
ConsoleWrite(_GetComputerModel() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetComputerModel()&lt;br /&gt;
	Return RegRead(&amp;quot;HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\BIOS&amp;quot;, &amp;quot;SystemProductName&amp;quot;)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetComputerModel&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _GetDriveBusType ==&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;APIConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local $aDrive = DriveGetDrive(&#039;ALL&#039;)&lt;br /&gt;
For $i = 1 To $aDrive[0]&lt;br /&gt;
	ConsoleWrite(StringUpper($aDrive[$i]) &amp;amp; &#039; =&amp;gt; &#039; &amp;amp; _GetDriveBusType($aDrive[$i]) &amp;amp; @CRLF)&lt;br /&gt;
Next&lt;br /&gt;
&lt;br /&gt;
; Get a string representation of a drive&#039;s bus type.&lt;br /&gt;
Func _GetDriveBusType($sDrive)&lt;br /&gt;
	Local $aArray[14][2] = [[$DRIVE_BUS_TYPE_UNKNOWN, &#039;UNKNOWN&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_SCSI, &#039;SCSI&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_ATAPI, &#039;ATAPI&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_ATA, &#039;ATA&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_1394, &#039;1394&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_SSA, &#039;SSA&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_FIBRE, &#039;FIBRE&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_USB, &#039;USB&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_RAID, &#039;RAID&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_ISCSI, &#039;ISCSI&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_SAS, &#039;SAS&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_SATA, &#039;SATA&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_SD, &#039;SD&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_MMC, &#039;MMC&#039;]]&lt;br /&gt;
	Local $iDriveType = _WinAPI_GetDriveBusType($sDrive)&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Return $aArray[0][1]&lt;br /&gt;
	EndIf&lt;br /&gt;
	Return $aArray[$iDriveType][1]&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetDriveBusType&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _GetUnusedDrives ==&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;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;~ Retrieve unused drive letters.&lt;br /&gt;
Local $aDrives = _GetUnusedDrives()&lt;br /&gt;
_ArrayDisplay($aDrives)&lt;br /&gt;
&lt;br /&gt;
Func _GetUnusedDrives()&lt;br /&gt;
	Local $sReturn = &#039;B:|C:|D:|E:|F:|G:|H:|I:|J:|K:|L:|M:|N:|O:|P:|Q:|R:|S:|T:|U:|V:|W:|X:|Y:|Z:|&#039;&lt;br /&gt;
	Local $aArray = DriveGetDrive(&#039;ALL&#039;)&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Local $aError = [0]&lt;br /&gt;
		$aArray = $aError&lt;br /&gt;
		$aError = 0&lt;br /&gt;
	EndIf&lt;br /&gt;
&lt;br /&gt;
	For $i = 1 To $aArray[0]&lt;br /&gt;
		$sReturn = StringReplace($sReturn, $aArray[$i] &amp;amp; &#039;|&#039;, &#039;&#039;)&lt;br /&gt;
	Next&lt;br /&gt;
	Return StringSplit(StringTrimRight($sReturn, StringLen(&#039;|&#039;)), &#039;|&#039;)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetUnusedDrives&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _IsSubst ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 35302-guinness&lt;br /&gt;
| AuthorName = guinness&lt;br /&gt;
| Desc=Checks if a drive is a subst drive.&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;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_IsSubst(@HomeDrive) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Checks if a drive is a subst drive.&lt;br /&gt;
Func _IsSubst($sDrive)&lt;br /&gt;
    Return _WinAPI_PathIsDirectory(StringReplace(_WinAPI_QueryDosDevice(StringLeft($sDrive, 1) &amp;amp; &amp;quot;:&amp;quot;), &amp;quot;\??\&amp;quot;, &amp;quot;&amp;quot;))&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsSubst&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _IsTrueCrypt ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 35302-guinness&lt;br /&gt;
| AuthorName = guinness&lt;br /&gt;
| Desc=Check if a drive is a TrueCrypt drive.&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;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&amp;quot;Is &amp;quot; &amp;amp; @HomeDrive &amp;amp; &amp;quot;\ a TrueCrypt drive?: &amp;quot; &amp;amp; _IsTrueCrypt(@HomePath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a drive is a TrueCrypt drive.&lt;br /&gt;
Func _IsTrueCrypt($sDrive)&lt;br /&gt;
    Return StringInStr(_WinAPI_QueryDosDevice(StringLeft($sDrive, StringLen(&#039;A&#039;)) &amp;amp; &#039;:&#039;), &#039;TrueCrypt&#039;) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsTrueCrypt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _MonitorToggle ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 7688-greenmachine&lt;br /&gt;
| AuthorName = greenmachine&lt;br /&gt;
| Desc = Toggle Monitor 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;
#include &amp;lt;SendMessage.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
_MonitorToggle(1)&lt;br /&gt;
Sleep(1000)&lt;br /&gt;
_MonitorToggle(0)&lt;br /&gt;
&lt;br /&gt;
; Toggle Monitor On/Off.&lt;br /&gt;
Func _MonitorToggle($iTurnOff = 1)&lt;br /&gt;
	Local $hWnd = WinGetHandle(&amp;quot;[CLASS:Progman]&amp;quot;), $SC_MONITORPOWER = 61808&lt;br /&gt;
	If $iTurnOff Then&lt;br /&gt;
		Return _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_MONITORPOWER, 2)&lt;br /&gt;
	Else&lt;br /&gt;
		Return _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_MONITORPOWER, -1)&lt;br /&gt;
	EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;_MonitorToggle&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _GetTotalScreenResolution ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 28010-larrydalooza&lt;br /&gt;
| AuthorName = LarryDalooza&lt;br /&gt;
| ModifierURL = 16404-brettf&lt;br /&gt;
| ModifierName = BrettF&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
 Global Const $aTSR = _GetTotalScreenResolution()&lt;br /&gt;
&lt;br /&gt;
 MsgBox(0, &amp;quot;Total Screen Resolution&amp;quot;, &amp;quot;Width = &amp;quot; &amp;amp; $aTSR[0] &amp;amp; @TAB &amp;amp; &amp;quot;Height = &amp;quot; &amp;amp; $aTSR[1])&lt;br /&gt;
&lt;br /&gt;
 Func _GetTotalScreenResolution()&lt;br /&gt;
     Local Const $SM_VIRTUALWIDTH = 78&lt;br /&gt;
     Local Const $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;
&lt;br /&gt;
     Local Const $SM_VIRTUALHEIGHT = 79&lt;br /&gt;
     Local Const $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;
&lt;br /&gt;
     Local Const $aRet[2] = [$VirtualDesktopWidth[0], $VirtualDesktopHeight[0]]&lt;br /&gt;
&lt;br /&gt;
     Return $aRet&lt;br /&gt;
 EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_Hardware_Information_)&amp;diff=12411</id>
		<title>Snippets ( Hardware Information )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_Hardware_Information_)&amp;diff=12411"/>
		<updated>2014-05-12T19:43:06Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* _IsTrueCrypt */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
[[category:Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Snippet Credit Header}}&lt;br /&gt;
&lt;br /&gt;
== _ComputerNameAndModel ==&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;
; Can return nothing relevant if machine is not a factory build&lt;br /&gt;
Global $aArray = _ComputerNameAndModel() ; Returns an Array with 2 indexes.&lt;br /&gt;
MsgBox(64, &amp;quot;_ComputerNameAndModel()&amp;quot;, &#039;The Product is a &amp;quot;&#039; &amp;amp; $aArray[0] &amp;amp; &#039;&amp;quot; and the Serial Number is &amp;quot;&#039; &amp;amp; $aArray[1] &amp;amp; &#039;&amp;quot;.&#039;)&lt;br /&gt;
&lt;br /&gt;
Func _ComputerNameAndModel()&lt;br /&gt;
    Local $aReturn[2] = [&amp;quot;(Unknown)&amp;quot;, &amp;quot;(Unknown)&amp;quot;], $oColItems, $oWMIService&lt;br /&gt;
&lt;br /&gt;
    $oWMIService = ObjGet(&amp;quot;winmgmts:\\.\root\cimv2&amp;quot;)&lt;br /&gt;
    $oColItems = $oWMIService.ExecQuery(&amp;quot;Select * From Win32_ComputerSystemProduct&amp;quot;, &amp;quot;WQL&amp;quot;, 0x30)&lt;br /&gt;
    If IsObj($oColItems) Then&lt;br /&gt;
        For $oObjectItem In $oColItems&lt;br /&gt;
            $aReturn[0] = $oObjectItem.Name&lt;br /&gt;
            $aReturn[1] = $oObjectItem.IdentifyingNumber&lt;br /&gt;
        Next&lt;br /&gt;
        Return $aReturn&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return SetError(1, 0, $aReturn)&lt;br /&gt;
EndFunc   ;==&amp;gt;_ComputerNameAndModel&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _GetComputerModel ==&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;
; Can return nothing relevant if machine is not a factory build&lt;br /&gt;
ConsoleWrite(_GetComputerModel() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetComputerModel()&lt;br /&gt;
    Local $oWMIService = ObjGet(&amp;quot;winmgmts:\\.\&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    Local $oColItems = $oWMIService.ExecQuery(&amp;quot;Select * From Win32_ComputerSystem&amp;quot;, &amp;quot;WQL&amp;quot;, 0x30)&lt;br /&gt;
	Local $sDescription&lt;br /&gt;
&lt;br /&gt;
    If IsObj($oColItems) Then&lt;br /&gt;
        For $oObjectItem In $oColItems&lt;br /&gt;
            $sDescription &amp;amp;= $oObjectItem.Model&lt;br /&gt;
        Next&lt;br /&gt;
&lt;br /&gt;
        Return $sDescription&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return SetError(1, 1, 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetComputerModel&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _GetComputerModel_2 ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 84272-rindeal&lt;br /&gt;
| AuthorName = rindeal&lt;br /&gt;
| Desc=Faster version of the snippet above&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Can return nothing relevant if machine is not a factory build&lt;br /&gt;
ConsoleWrite(_GetComputerModel() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetComputerModel()&lt;br /&gt;
	Return RegRead(&amp;quot;HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\BIOS&amp;quot;, &amp;quot;SystemProductName&amp;quot;)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetComputerModel&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _GetDriveBusType ==&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;APIConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local $aDrive = DriveGetDrive(&#039;ALL&#039;)&lt;br /&gt;
For $i = 1 To $aDrive[0]&lt;br /&gt;
	ConsoleWrite(StringUpper($aDrive[$i]) &amp;amp; &#039; =&amp;gt; &#039; &amp;amp; _GetDriveBusType($aDrive[$i]) &amp;amp; @CRLF)&lt;br /&gt;
Next&lt;br /&gt;
&lt;br /&gt;
; Get a string representation of a drive&#039;s bus type.&lt;br /&gt;
Func _GetDriveBusType($sDrive)&lt;br /&gt;
	Local $aArray[14][2] = [[$DRIVE_BUS_TYPE_UNKNOWN, &#039;UNKNOWN&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_SCSI, &#039;SCSI&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_ATAPI, &#039;ATAPI&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_ATA, &#039;ATA&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_1394, &#039;1394&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_SSA, &#039;SSA&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_FIBRE, &#039;FIBRE&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_USB, &#039;USB&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_RAID, &#039;RAID&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_ISCSI, &#039;ISCSI&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_SAS, &#039;SAS&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_SATA, &#039;SATA&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_SD, &#039;SD&#039;], _&lt;br /&gt;
			[$DRIVE_BUS_TYPE_MMC, &#039;MMC&#039;]]&lt;br /&gt;
	Local $iDriveType = _WinAPI_GetDriveBusType($sDrive)&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Return $aArray[0][1]&lt;br /&gt;
	EndIf&lt;br /&gt;
	Return $aArray[$iDriveType][1]&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetDriveBusType&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _GetUnusedDrives ==&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;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;~ Retrieve unused drive letters.&lt;br /&gt;
Local $aDrives = _GetUnusedDrives()&lt;br /&gt;
_ArrayDisplay($aDrives)&lt;br /&gt;
&lt;br /&gt;
Func _GetUnusedDrives()&lt;br /&gt;
	Local $aReturn[1] = [0], $sReturn = &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
	For $i = 1 To 26&lt;br /&gt;
		$sReturn &amp;amp;= Chr($i + 64) &amp;amp; &#039;:|&#039;&lt;br /&gt;
	Next&lt;br /&gt;
&lt;br /&gt;
	Local $aArray = DriveGetDrive(&#039;ALL&#039;)&lt;br /&gt;
	If @error Then&lt;br /&gt;
		$aArray = $aReturn&lt;br /&gt;
	EndIf&lt;br /&gt;
&lt;br /&gt;
	For $i = 1 To $aArray[0]&lt;br /&gt;
		$sReturn = StringReplace($sReturn, StringLeft($aArray[$i], 1) &amp;amp; &#039;:|&#039;, &#039;&#039;)&lt;br /&gt;
	Next&lt;br /&gt;
	Return StringSplit(StringTrimRight($sReturn, 1), &#039;|&#039;)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetUnusedDrives&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _IsSubst ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 35302-guinness&lt;br /&gt;
| AuthorName = guinness&lt;br /&gt;
| Desc=Checks if a drive is a subst drive.&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;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_IsSubst(@HomeDrive) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Checks if a drive is a subst drive.&lt;br /&gt;
Func _IsSubst($sDrive)&lt;br /&gt;
    Return _WinAPI_PathIsDirectory(StringReplace(_WinAPI_QueryDosDevice(StringLeft($sDrive, 1) &amp;amp; &amp;quot;:&amp;quot;), &amp;quot;\??\&amp;quot;, &amp;quot;&amp;quot;))&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsSubst&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _IsTrueCrypt ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 35302-guinness&lt;br /&gt;
| AuthorName = guinness&lt;br /&gt;
| Desc=Check if a drive is a TrueCrypt drive.&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;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&amp;quot;Is &amp;quot; &amp;amp; @HomeDrive &amp;amp; &amp;quot;\ a TrueCrypt drive?: &amp;quot; &amp;amp; _IsTrueCrypt(@HomePath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a drive is a TrueCrypt drive.&lt;br /&gt;
Func _IsTrueCrypt($sDrive)&lt;br /&gt;
    Return StringInStr(_WinAPI_QueryDosDevice(StringLeft($sDrive, StringLen(&#039;A&#039;)) &amp;amp; &#039;:&#039;), &#039;TrueCrypt&#039;) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsTrueCrypt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _MonitorToggle ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 7688-greenmachine&lt;br /&gt;
| AuthorName = greenmachine&lt;br /&gt;
| Desc = Toggle Monitor 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;
#include &amp;lt;SendMessage.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
_MonitorToggle(1)&lt;br /&gt;
Sleep(1000)&lt;br /&gt;
_MonitorToggle(0)&lt;br /&gt;
&lt;br /&gt;
; Toggle Monitor On/Off.&lt;br /&gt;
Func _MonitorToggle($iTurnOff = 1)&lt;br /&gt;
	Local $hWnd = WinGetHandle(&amp;quot;[CLASS:Progman]&amp;quot;), $SC_MONITORPOWER = 61808&lt;br /&gt;
	If $iTurnOff Then&lt;br /&gt;
		Return _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_MONITORPOWER, 2)&lt;br /&gt;
	Else&lt;br /&gt;
		Return _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_MONITORPOWER, -1)&lt;br /&gt;
	EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;_MonitorToggle&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
== _GetTotalScreenResolution ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
| AuthorURL = 28010-larrydalooza&lt;br /&gt;
| AuthorName = LarryDalooza&lt;br /&gt;
| ModifierURL = 16404-brettf&lt;br /&gt;
| ModifierName = BrettF&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
 Global Const $aTSR = _GetTotalScreenResolution()&lt;br /&gt;
&lt;br /&gt;
 MsgBox(0, &amp;quot;Total Screen Resolution&amp;quot;, &amp;quot;Width = &amp;quot; &amp;amp; $aTSR[0] &amp;amp; @TAB &amp;amp; &amp;quot;Height = &amp;quot; &amp;amp; $aTSR[1])&lt;br /&gt;
&lt;br /&gt;
 Func _GetTotalScreenResolution()&lt;br /&gt;
     Local Const $SM_VIRTUALWIDTH = 78&lt;br /&gt;
     Local Const $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;
&lt;br /&gt;
     Local Const $SM_VIRTUALHEIGHT = 79&lt;br /&gt;
     Local Const $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;
&lt;br /&gt;
     Local Const $aRet[2] = [$VirtualDesktopWidth[0], $VirtualDesktopHeight[0]]&lt;br /&gt;
&lt;br /&gt;
     Return $aRet&lt;br /&gt;
 EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_Windows_OS_)&amp;diff=12410</id>
		<title>Snippets ( Windows OS )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_Windows_OS_)&amp;diff=12410"/>
		<updated>2014-05-12T19:41:59Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* _ProcessCloseFromPath() */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
{{Snippet Credit Header}}&lt;br /&gt;
&lt;br /&gt;
===== _CancelPrinterJobs() =====&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;
; Cancel printer jobs for the default printer or the printer name provided.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_CancelPrinterJobs() &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_CancelPrinterJobs(&#039;HP Printer 1234&#039;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _CancelPrinterJobs($sPrinterName = &#039;&#039;)&lt;br /&gt;
    If StringStripWS($sPrinterName, 8) = &#039;&#039; Then&lt;br /&gt;
        $sPrinterName = &#039;Default = True&#039;&lt;br /&gt;
    Else&lt;br /&gt;
        $sPrinterName = &#039;Name = &amp;quot;&#039; &amp;amp; $sPrinterName &amp;amp; &#039;&amp;quot;&#039;&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $iResult = 0, $oWMIService = ObjGet(&#039;winmgmts:\\&#039; &amp;amp; &#039;.&#039; &amp;amp; &#039;\root\cimv2&#039;)&lt;br /&gt;
    Local $oColItems = $oWMIService.ExecQuery(&#039;Select * From Win32_Printer Where &#039; &amp;amp; $sPrinterName)&lt;br /&gt;
    If IsObj($oColItems) Then&lt;br /&gt;
        For $oObjectItem In $oColItems&lt;br /&gt;
            $iResult = $oObjectItem.CancelAllJobs()&lt;br /&gt;
        Next&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $iResult&lt;br /&gt;
EndFunc   ;==&amp;gt;_CancelPrinterJobs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
===== _CheckElevationEnabled() =====&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
|AuthorURL=52374-johnone&lt;br /&gt;
|AuthorName=JohnOne&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang = &amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; OS dependent = Vista, server 2008 SP1 and WIN7&lt;br /&gt;
;#### Example ####&lt;br /&gt;
Local $bUAC = _CheckElevationEnabled()&lt;br /&gt;
If @error Then&lt;br /&gt;
   Exit MsgBox(0,&amp;quot;Error&amp;quot;,@error)&lt;br /&gt;
EndIf&lt;br /&gt;
MsgBox(0,&amp;quot;UAC Enabled&amp;quot;,$bUAC)&lt;br /&gt;
&lt;br /&gt;
;Checks if Use Access Control (UAC) is Enabled.&lt;br /&gt;
Func _CheckElevationEnabled()&lt;br /&gt;
   Local $struct = DllStructCreate(&amp;quot;BOOL&amp;quot;)&lt;br /&gt;
   Local $aRtn = DllCall(&amp;quot;kernel32.dll&amp;quot;,&amp;quot;DWORD&amp;quot;,&amp;quot;CheckElevationEnabled&amp;quot;,&amp;quot;ptr&amp;quot;, DllStructGetPtr($struct))&lt;br /&gt;
   If @error Then&lt;br /&gt;
     Return SetError(@error)&lt;br /&gt;
   EndIf&lt;br /&gt;
   Return SetError($aRtn[0],0,DllStructGetData($struct,1))&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
===== _IsDeskTopLocked() =====&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
|AuthorURL=1967-garyfrost&lt;br /&gt;
|AuthorName=GaryFrost&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Detect if System is Locked&lt;br /&gt;
&lt;br /&gt;
Global Const $DESKTOP_ENUMERATE = 0x40&lt;br /&gt;
Global Const $SPI_GETSCREENSAVERRUNNING = 114&lt;br /&gt;
Global Const $DESKTOP_SWITCHDESKTOP = 0x100&lt;br /&gt;
&lt;br /&gt;
HotKeySet(&amp;quot;{ESC}&amp;quot;, &amp;quot;_Terminate&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
AdlibEnable(&amp;quot;IsDeskTopLocked&amp;quot;, 500)&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
    Sleep(10)&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func _IsDeskTopLocked()&lt;br /&gt;
    Local $p_lngHwnd, $p_lngRtn, $p_lngErr, $p_lngScreenSaver, $p_blnIsScreenSaver&lt;br /&gt;
   ;~    &#039; ------------------------------------------&lt;br /&gt;
;~    &#039; First check for screen saver one of 2 ways,&lt;br /&gt;
;~    &#039;     based of OS&lt;br /&gt;
;~    &#039; ------------------------------------------&lt;br /&gt;
    If @OSTYPE = &amp;quot;WIN32_WINDOWS&amp;quot;  Then&lt;br /&gt;
;~       &#039; ---------------------------------------&lt;br /&gt;
;~       &#039; Pre W2K -- Note, will only be TRUE if&lt;br /&gt;
;~       &#039;     the &amp;quot;Password Protected&amp;quot; box is&lt;br /&gt;
;~       &#039;     checked.&lt;br /&gt;
;~       &#039; ---------------------------------------&lt;br /&gt;
        $p_lngHwnd = DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;OpenDesktopA&amp;quot;, &amp;quot;str&amp;quot;, &amp;quot;screen-saver&amp;quot;, &amp;quot;int&amp;quot;, 0, &amp;quot;int&amp;quot;, False, &amp;quot;int&amp;quot;, $DESKTOP_ENUMERATE)&lt;br /&gt;
        If $p_lngHwnd[0] &amp;lt;&amp;gt; 0 Then&lt;br /&gt;
            $p_blnIsScreenSaver = True&lt;br /&gt;
        Else&lt;br /&gt;
            $p_blnIsScreenSaver = False&lt;br /&gt;
        EndIf&lt;br /&gt;
    Else&lt;br /&gt;
;~       &#039; ---------------------------------------&lt;br /&gt;
;~       &#039; W2K+ -- Will determine if screen saver&lt;br /&gt;
;~       &#039;     is running whether or not the&lt;br /&gt;
;~       &#039;     &amp;quot;Password Protected&amp;quot; box is checked&lt;br /&gt;
;~       &#039; ---------------------------------------&lt;br /&gt;
        $p_lngRtn = DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;SystemParametersInfoA&amp;quot;, &amp;quot;int&amp;quot;, $SPI_GETSCREENSAVERRUNNING, &amp;quot;int&amp;quot;, 0, &amp;quot;int&amp;quot;, $p_lngScreenSaver, &amp;quot;int&amp;quot;, 0)&lt;br /&gt;
        If $p_lngRtn[0] = 0 Then&lt;br /&gt;
            ConsoleWrite(&amp;quot;Error detecting screen saver&amp;quot; &amp;amp; @LF)&lt;br /&gt;
        Else&lt;br /&gt;
            $p_blnIsScreenSaver = $p_lngScreenSaver&lt;br /&gt;
        EndIf&lt;br /&gt;
&lt;br /&gt;
    EndIf&lt;br /&gt;
;~    &#039; ------------------------------------------&lt;br /&gt;
;~    &#039; If screen saver is *not* running, then&lt;br /&gt;
;~    &#039;     check for locked workstation&lt;br /&gt;
;~    &#039; ------------------------------------------&lt;br /&gt;
    If $p_blnIsScreenSaver Then&lt;br /&gt;
        If @OSTYPE = &amp;quot;WIN32_WINDOWS&amp;quot;  Then&lt;br /&gt;
            ConsoleWrite(&amp;quot;Screen saver is running..., Handle #&amp;quot; &amp;amp; $p_lngHwnd[0] &amp;amp; @LF)&lt;br /&gt;
            $p_lngHwnd = DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;CloseDesktop&amp;quot;, &amp;quot;int&amp;quot;, $p_lngHwnd[0])&lt;br /&gt;
        Else&lt;br /&gt;
            ConsoleWrite(&amp;quot;Screen saver is running on W2K+&amp;quot; &amp;amp; @LF)&lt;br /&gt;
        EndIf&lt;br /&gt;
    Else&lt;br /&gt;
        $p_lngHwnd = DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;OpenDesktopA&amp;quot;, &amp;quot;str&amp;quot;, &amp;quot;Default&amp;quot;, &amp;quot;int&amp;quot;, 0, &amp;quot;int&amp;quot;, False, &amp;quot;int&amp;quot;, $DESKTOP_SWITCHDESKTOP)&lt;br /&gt;
&lt;br /&gt;
        If $p_lngHwnd[0] = 0 Then&lt;br /&gt;
            ConsoleWrite(&amp;quot;Error with OpenDesktop&amp;quot; &amp;amp; @LF)&lt;br /&gt;
        Else&lt;br /&gt;
            $p_lngRtn = DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;SwitchDesktop&amp;quot;, &amp;quot;int&amp;quot;, $p_lngHwnd[0])&lt;br /&gt;
            $p_lngErr = _GetLastErrorMessage()&lt;br /&gt;
&lt;br /&gt;
            If $p_lngRtn[0] = 0 Then&lt;br /&gt;
                If $p_lngErr = 0 Then&lt;br /&gt;
                    ConsoleWrite(&amp;quot;Desktop is locked&amp;quot; &amp;amp; @LF)&lt;br /&gt;
                Else&lt;br /&gt;
                    ConsoleWrite(&amp;quot;Error with SwitchDesktop&amp;quot; &amp;amp; @LF)&lt;br /&gt;
                EndIf&lt;br /&gt;
            Else&lt;br /&gt;
                ConsoleWrite(&amp;quot;Not locked!&amp;quot; &amp;amp; @LF)&lt;br /&gt;
            EndIf&lt;br /&gt;
            $p_lngHwnd = DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;CloseDesktop&amp;quot;, &amp;quot;int&amp;quot;, $p_lngHwnd[0])&lt;br /&gt;
        EndIf&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;IsDeskTopLocked&lt;br /&gt;
&lt;br /&gt;
Func _Terminate()&lt;br /&gt;
    Exit&lt;br /&gt;
EndFunc   ;==&amp;gt;_Terminate&lt;br /&gt;
  &lt;br /&gt;
;===============================================&lt;br /&gt;
;    _GetLastErrorMessage($DisplayMsgBox=&amp;quot;&amp;quot;)&lt;br /&gt;
;    Format the last windows error as a string and return it&lt;br /&gt;
;    if $DisplayMsgBox &amp;lt;&amp;gt; &amp;quot;&amp;quot; Then it will display a message box w/ the error&lt;br /&gt;
;    Return        Window&#039;s error as a string&lt;br /&gt;
;===============================================&lt;br /&gt;
Func _GetLastErrorMessage($DisplayMsgBox = &amp;quot;&amp;quot;)&lt;br /&gt;
    Local $ret, $s&lt;br /&gt;
    Local $p = DllStructCreate(&amp;quot;char[4096]&amp;quot;)&lt;br /&gt;
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000&lt;br /&gt;
    If @error Then Return &amp;quot;&amp;quot;&lt;br /&gt;
    $ret = DllCall(&amp;quot;Kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;GetLastError&amp;quot;)&lt;br /&gt;
    $ret = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;FormatMessage&amp;quot;, _&lt;br /&gt;
            &amp;quot;int&amp;quot;, $FORMAT_MESSAGE_FROM_SYSTEM, _&lt;br /&gt;
            &amp;quot;ptr&amp;quot;, 0, _&lt;br /&gt;
            &amp;quot;int&amp;quot;, $ret[0], _&lt;br /&gt;
            &amp;quot;int&amp;quot;, 0, _&lt;br /&gt;
            &amp;quot;ptr&amp;quot;, DllStructGetPtr($p), _&lt;br /&gt;
            &amp;quot;int&amp;quot;, 4096, _&lt;br /&gt;
            &amp;quot;ptr&amp;quot;, 0)&lt;br /&gt;
    $s = DllStructGetData($p, 1)&lt;br /&gt;
    If $DisplayMsgBox &amp;lt;&amp;gt; &amp;quot;&amp;quot; Then MsgBox(0, &amp;quot;_GetLastErrorMessage&amp;quot;, $DisplayMsgBox &amp;amp; @CRLF &amp;amp; $s)&lt;br /&gt;
    Return $s&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetLastErrorMessage&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
===== _DisplayWindowsSwitcher() =====&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL=66537-knightz93&lt;br /&gt;
 | AuthorName=Knightz93&lt;br /&gt;
 | ModifierURL=35302-guinness&lt;br /&gt;
 | ModifierName=guinness&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang = &amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
HotKeySet(&amp;quot;{ESC}&amp;quot;, &amp;quot;_Exit&amp;quot;) ; Press the ESC key to escape.&lt;br /&gt;
&lt;br /&gt;
HotKeySet(&amp;quot;!3&amp;quot;, &amp;quot;_DisplayWindowsSwitcher&amp;quot;) ; Press Alt+3 to display the Windows Switcher, though this in Windows is also Win Key + Tab.&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
    Sleep(100)&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
; Only works on Windows 7+&lt;br /&gt;
Func _DisplayWindowsSwitcher()&lt;br /&gt;
    Local $oShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $oShell.WindowSwitcher()&lt;br /&gt;
EndFunc   ;==&amp;gt;_DisplayWindowsSwitcher&lt;br /&gt;
&lt;br /&gt;
Func _Exit()&lt;br /&gt;
    Exit&lt;br /&gt;
EndFunc   ;==&amp;gt;_Exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
===== _DisableWindowsLock() =====&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(&#039;Disable Windows Lock: &#039; &amp;amp; _DisableWindowsLock() &amp;amp; @CRLF)&lt;br /&gt;
MsgBox(4096, &#039;&#039;, &#039;Select Win + L to see the result of using _DisableWindowsLock.&#039;)&lt;br /&gt;
ConsoleWrite(&#039;Disable Windows Lock: &#039; &amp;amp; _DisableWindowsLock() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Disable the locking of Windows. Returns 1 - disabled or 0 - enabled.&lt;br /&gt;
Func _DisableWindowsLock()&lt;br /&gt;
    Local $i64Bit = &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
    If @OSArch = &#039;X64&#039; Then&lt;br /&gt;
        $i64Bit = &#039;64&#039;&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $iRegRead = Number(Not RegRead(&#039;HKEY_CURRENT_USER&#039; &amp;amp; $i64Bit &amp;amp; &#039;\Software\Microsoft\Windows\CurrentVersion\Policies\System&#039;, &#039;DisableLockWorkstation&#039;))&lt;br /&gt;
    Return SetError(Not RegWrite(&#039;HKEY_CURRENT_USER&#039; &amp;amp; $i64Bit &amp;amp; &#039;\Software\Microsoft\Windows\CurrentVersion\Policies\System&#039;, &#039;DisableLockWorkstation&#039;, &#039;REG_DWORD&#039;, $iRegRead), 0, $iRegRead)&lt;br /&gt;
EndFunc   ;==&amp;gt;_DisableWindowsLock&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
===== _IsFontExists() =====&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;APIConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_IsFontExists(&amp;quot;WebDings.ttf&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _IsFontExists($sFontType)&lt;br /&gt;
    Return FileExists(_WinAPI_ShellGetSpecialFolderPath($CSIDL_FONTS) &amp;amp; &amp;quot;\&amp;quot; &amp;amp; $sFontType) ; WebDings.ttf&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFontExists&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
===== _GetDesktopWallpaper() =====&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;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite( _GetDesktopWallpaper() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _GetDesktopWallpaper()&lt;br /&gt;
    Local $SPI_GETDESKWALLPAPER = 0x0073&lt;br /&gt;
    Local $tPATH = DllStructCreate(&#039;wchar[260]&#039;)&lt;br /&gt;
    _WinAPI_SystemParametersInfo($SPI_GETDESKWALLPAPER, 260, DllStructGetPtr($tPATH))&lt;br /&gt;
    Return DllStructGetData($tPATH, 1)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetDesktopWallpaper&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
===== _GetOSVersion() =====&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
|AuthorURL=7108-xenobiologist&lt;br /&gt;
|AuthorName=Xenobiologist&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
MsgBox(0,0, _GetOSVersion())&lt;br /&gt;
&lt;br /&gt;
Func _GetOSVersion()&lt;br /&gt;
    Local $objWMIService = ObjGet(&amp;quot;winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2&amp;quot;)&lt;br /&gt;
    Local $colSettings = $objWMIService.ExecQuery(&amp;quot;Select * from Win32_OperatingSystem&amp;quot;)&lt;br /&gt;
    For $objOperatingSystem In $colSettings&lt;br /&gt;
        Return &amp;quot;Windows &amp;quot; &amp;amp; StringMid($objOperatingSystem.Caption, 19)&lt;br /&gt;
    Next&lt;br /&gt;
EndFunc   ;==&amp;gt;_getOSVersion&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
===== _InstallDate() =====&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(_InstallDate() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _InstallDate()&lt;br /&gt;
    Local $oWMIService = ObjGet(&amp;quot;winmgmts:{impersonationLevel = impersonate}!\\&amp;quot; &amp;amp; &amp;quot;.&amp;quot; &amp;amp; &amp;quot;\root\cimv2&amp;quot;)&lt;br /&gt;
    Local $oColFiles = $oWMIService.ExecQuery(&amp;quot;Select * From Win32_OperatingSystem&amp;quot;)&lt;br /&gt;
    If IsObj($oColFiles) Then&lt;br /&gt;
        For $oObjectFile In $oColFiles&lt;br /&gt;
            Return StringRegExpReplace($oObjectFile.InstallDate, &amp;quot;\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:.*)&amp;quot;, &amp;quot;$3/$2/$1 $4:$5:$6&amp;quot;)&lt;br /&gt;
        Next&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return SetError(1, 0, 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;_InstallDate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
===== Installed version of Windows with mathematical operators =====&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
|AuthorURL=52-geosoft&lt;br /&gt;
|AuthorName=GEOSoft&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt; &lt;br /&gt;
; Test the installed version of Windows with mathematical operators.&lt;br /&gt;
&lt;br /&gt;
Global Const $2K_VER = 5.0&lt;br /&gt;
Global Const $XP_VER = 5.1&lt;br /&gt;
Global Const $XP64_VER = 5.2&lt;br /&gt;
Global Const $VISTA_VER = 6.0&lt;br /&gt;
Global Const $W7_VER = 6.1&lt;br /&gt;
&lt;br /&gt;
$iCurrVer = RegRead(&amp;quot;HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion&amp;quot;, &amp;quot;CurrentVersion&amp;quot;)&lt;br /&gt;
MsgBox(0, &amp;quot;Result&amp;quot;, $iCurrVer &amp;gt;= $VISTA_VER)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
=====  _IsElevationRequired() =====&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
|AuthorURL=52374-johnone&lt;br /&gt;
|AuthorName=JohnOne&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; OS dependent = Vista, server 2008 SP1 and WIN7 &lt;br /&gt;
;#### Example 1 ####&lt;br /&gt;
Global $bool = _IsElevationRequired(&amp;quot;C:\Windows\notepad.exe&amp;quot;) ;Pass path of an exe that does not normally need elevated privileges&lt;br /&gt;
If @error Then&lt;br /&gt;
   Exit MsgBox(0,&amp;quot;Error&amp;quot;,@error)&lt;br /&gt;
EndIf&lt;br /&gt;
;should show 0&lt;br /&gt;
MsgBox(0,&amp;quot;Elevation notepad&amp;quot;,$bool)&lt;br /&gt;
&lt;br /&gt;
;#### Example 2 ####&lt;br /&gt;
$bool = _IsElevationRequired(&amp;quot;C:\Windows\regedit.exe&amp;quot;) ;Pass path of an exe that does normally need elevated privileges&lt;br /&gt;
If @error Then&lt;br /&gt;
   Exit MsgBox(0,&amp;quot;Error&amp;quot;,@error)&lt;br /&gt;
EndIf&lt;br /&gt;
;should show 1&lt;br /&gt;
MsgBox(0,&amp;quot;Elevation regedit&amp;quot;,$bool)&lt;br /&gt;
&lt;br /&gt;
Func _IsElevationRequired($szPath) ;Checks if an executable (.exe) needs elevated permissions to run.&lt;br /&gt;
   Local Const $BAD_ARG = 6&lt;br /&gt;
   If StringRight($szPath,3) &amp;lt;&amp;gt; &amp;quot;exe&amp;quot; Then&lt;br /&gt;
      Return SetError($BAD_ARG)&lt;br /&gt;
   EndIf&lt;br /&gt;
   Local $aRtn = DllCall(&amp;quot;shell32.dll&amp;quot;,&amp;quot;BOOL&amp;quot;,865,&amp;quot;wstr&amp;quot;,$szPath)&lt;br /&gt;
   If @error Then&lt;br /&gt;
      Return SetError(@error)&lt;br /&gt;
   EndIf&lt;br /&gt;
   Return $aRtn[0]&lt;br /&gt;
EndFunc ;===&amp;gt;_IsElevationRequired&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
===== _IsServer() =====&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( _IsServer() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _IsServer() ; MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394239(v=vs.85).aspx&lt;br /&gt;
    Local $oWMIService = ObjGet(&amp;quot;winmgmts://./root/cimv2&amp;quot;), $oWMIServiceItem&lt;br /&gt;
    Local $oColItems = $oWMIService.ExecQuery(&amp;quot;Select * From Win32_OperatingSystem&amp;quot;)&lt;br /&gt;
    If IsObj($oColItems) Then&lt;br /&gt;
        For $oWMIServiceItem In $oColItems&lt;br /&gt;
            If $oWMIServiceItem.ProductType = 2 Or $oWMIServiceItem.ProductType = 3 Then&lt;br /&gt;
                Return 1&lt;br /&gt;
            EndIf&lt;br /&gt;
        Next&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return SetError(1, 0, 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
===== _IsPrimaryOS() =====&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;
; Tell if the current OS is the primary OS.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&amp;quot;_IsPrimaryOS() &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsPrimaryOS() &amp;amp; @LF)&lt;br /&gt;
&lt;br /&gt;
Func _IsPrimaryOS($sComputerName = @ComputerName)&lt;br /&gt;
    Local $oColItems, $oWMIService&lt;br /&gt;
&lt;br /&gt;
    $oWMIService = ObjGet(&amp;quot;winmgmts:\\&amp;quot; &amp;amp; $sComputerName &amp;amp; &amp;quot;\root\cimv2&amp;quot;)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 1)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $oColItems = $oWMIService.ExecQuery(&amp;quot;Select * From Win32_SystemOperatingSystem&amp;quot;, &amp;quot;WQL&amp;quot;, 0x30)&lt;br /&gt;
    If IsObj($oColItems) Then&lt;br /&gt;
        For $oObjectItem In $oColItems&lt;br /&gt;
            Return $oObjectItem.PrimaryOS&lt;br /&gt;
        Next&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return SetError(1, 0, 1)&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsPrimaryOS&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
===== _IsSafeMode() =====&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;WinAPI.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_IsSafeMode() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _IsSafeMode()&lt;br /&gt;
    Return _WinAPI_GetSystemMetrics($SM_CLEANBOOT) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsSafeMode&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
===== _IsVirtualMachine() =====&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( _IsVirtualMachine() &amp;amp; @LF)&lt;br /&gt;
&lt;br /&gt;
Func _IsVirtualMachine() ; Returns True or False.&lt;br /&gt;
    Local $oColItems, $oWMIService&lt;br /&gt;
    $oWMIService = ObjGet(&amp;quot;winmgmts:\\localhost\root\cimv2&amp;quot;)&lt;br /&gt;
    $oColItems = $oWMIService.ExecQuery(&amp;quot;Select * From Win32_ComputerSystemProduct&amp;quot;, &amp;quot;WQL&amp;quot;, 0x30)&lt;br /&gt;
    If IsObj($oColItems) Then&lt;br /&gt;
        For $oObjectItem In $oColItems&lt;br /&gt;
            Return StringRegExp($oObjectItem.Name, &#039;VirtualBox|VMWare|Virtual PC&#039;) = 1&lt;br /&gt;
        Next&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return False&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsVirtualMachine&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
===== _IsVistaAbove() =====&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(_IsVistaAbove() &amp;amp; @CRLF) ; Returns True is greater or equal to Windows Vista.&lt;br /&gt;
&lt;br /&gt;
Func _IsVistaAbove()&lt;br /&gt;
    Return RegRead(&amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\&amp;quot;, &amp;quot;CurrentVersion&amp;quot;) &amp;gt;= 6.0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsVistaAbove&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
===== _IsWindowsTablet() =====&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;WinAPI.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MsgBox(64, &amp;quot;_IsWindowsTablet()&amp;quot;, _IsWindowsTablet())&lt;br /&gt;
&lt;br /&gt;
Func _IsWindowsTablet()&lt;br /&gt;
    Return _WinAPI_GetSystemMetrics($SM_TABLETPC) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsWindowsTablet&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
===== _OSArch() =====&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;
#cs&lt;br /&gt;
    If you&#039;re using Windows x86 then &#039;&#039; is returned otherwise if you&#039;re using x64 then &#039;64&#039; is returned.&lt;br /&gt;
#ce&lt;br /&gt;
ConsoleWrite(&amp;quot;Program&amp;quot; &amp;amp; _OSArch() &amp;amp; &amp;quot;.exe&amp;quot; &amp;amp; @LF)&lt;br /&gt;
&lt;br /&gt;
Func _OSArch()&lt;br /&gt;
    Return StringRegExpReplace(@OSArch, &amp;quot;(?i)x86|\D+&amp;quot;, &amp;quot;&amp;quot;) ; Thanks to wraithdu.&lt;br /&gt;
EndFunc   ;==&amp;gt;_OSArch&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
===== _OSSerial() =====&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(_OSSerial() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _OSSerial()&lt;br /&gt;
    Local $oWMIService = ObjGet(&amp;quot;winmgmts:{impersonationLevel = impersonate}!\\&amp;quot; &amp;amp; &amp;quot;.&amp;quot; &amp;amp; &amp;quot;\root\cimv2&amp;quot;)&lt;br /&gt;
    Local $oColFiles = $oWMIService.ExecQuery(&amp;quot;Select * From Win32_OperatingSystem&amp;quot;)&lt;br /&gt;
    If IsObj($oColFiles) Then&lt;br /&gt;
        For $oObjectFile In $oColFiles&lt;br /&gt;
            Return $oObjectFile.SerialNumber&lt;br /&gt;
        Next&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return SetError(1, 0, 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;OSSerial&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
===== _OSVersion() =====&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;
; Get the OS version number without an API call.&lt;br /&gt;
&lt;br /&gt;
MsgBox(0, &amp;quot;_OSVersion()&amp;quot;, _OSVersion())&lt;br /&gt;
MsgBox(0, &amp;quot;_OSVersionEx()&amp;quot;, _OSVersionEx())&lt;br /&gt;
&lt;br /&gt;
Func _OSVersion()&lt;br /&gt;
    Return RegRead(&amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\&amp;quot;, &amp;quot;CurrentVersion&amp;quot;)&lt;br /&gt;
EndFunc   ;==&amp;gt;_OSVersion&lt;br /&gt;
&lt;br /&gt;
Func _OSVersionEx()&lt;br /&gt;
    Return StringLeft(FileGetVersion(@SystemDir &amp;amp; &amp;quot;\WinVer.exe&amp;quot;), 3)&lt;br /&gt;
EndFunc   ;==&amp;gt;_OSVersionEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
===== _ProcessCloseFromPath() =====&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;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
	; Close a process using the filepath rather than the filename, which is what ProcessClose requires.&lt;br /&gt;
&lt;br /&gt;
	; Run Notepad&lt;br /&gt;
	Run(&amp;quot;notepad.exe&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	; Wait 10 seconds for the Notepad window to appear.&lt;br /&gt;
	WinWait(&amp;quot;[CLASS:Notepad]&amp;quot;, &amp;quot;&amp;quot;, 10)&lt;br /&gt;
&lt;br /&gt;
	; Wait for 2 seconds.&lt;br /&gt;
	Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
	Local $sNotepad = @SystemDir &amp;amp; &amp;quot;\notepad.exe&amp;quot;&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Path of Notepad: &amp;quot; &amp;amp; $sNotepad)&lt;br /&gt;
&lt;br /&gt;
	; Close the Notepad process using the filepath.&lt;br /&gt;
	_ProcessCloseFromPath($sNotepad)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _ProcessCloseFromPath($sFilePath)&lt;br /&gt;
	Return FileExists($sFilePath) ? ProcessClose(StringTrimLeft($sFilePath, StringInStr($sFilePath, &amp;quot;\&amp;quot;, Default, -1))) : SetError(1, 0, 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;_ProcessCloseFromPath&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
===== _UnDockPC() =====&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(_UnDockPC() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Ejects the computer from its docking station.&lt;br /&gt;
Func _UnDockPC()&lt;br /&gt;
    Local $oShell = ObjCreate(&#039;shell.application&#039;)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $oShell.EjectPC()&lt;br /&gt;
    Return 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_UnDockPC&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
===== _WMPlayer_Location() =====&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;
; Get the location of Windows Media Player.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_WMPLayer_Location() &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _WMPlayer_Location()&lt;br /&gt;
    Local $aReturn = StringRegExp(_WinAPI_ExpandEnvironmentStrings(RegRead(&amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\wmplayer.exe\shell\open\command&amp;quot;, &amp;quot;&amp;quot;)), &#039;(?s)(?i)&amp;quot;(.*?)&amp;quot;&#039;, 3)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, &amp;quot;&amp;quot;)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $aReturn[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;_WMPlayer_Location&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top|Return To Contents]]&lt;br /&gt;
&lt;br /&gt;
[[category:Snippets]]&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_Files_%26_Folders_)&amp;diff=12409</id>
		<title>Snippets ( Files &amp; Folders )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_Files_%26_Folders_)&amp;diff=12409"/>
		<updated>2014-05-12T19:35:36Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* _IsFileOlder */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
[[category:Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Snippet Credit Header}}&lt;br /&gt;
&lt;br /&gt;
== _ConvertFileToUTF16 ==&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;
_ConvertFileToUTF16(@ScriptDir &amp;amp; &amp;quot;\Example.xml&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _ConvertFileToUTF16($sFilePath)&lt;br /&gt;
    Local $iEncoding = FileGetEncoding($sFilePath)&lt;br /&gt;
    Local $hFileOpen = FileOpen($sFilePath, $iEncoding)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $sData = FileRead($hFileOpen)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
&lt;br /&gt;
    $hFileOpen = FileOpen($sFilePath, 2 + 32)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(2, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    FileWrite($hFileOpen, $sData)&lt;br /&gt;
    Return FileClose($hFileOpen)&lt;br /&gt;
EndFunc   ;==&amp;gt;_ConvertFileToUTF16&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== DropFiles ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 35302-guinness&lt;br /&gt;
 | AuthorName = guinness&lt;br /&gt;
 | Desc = Dropping multiple files onto a GUI&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Dropping multiple files onto a GUI&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;APIConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $__aDropFiles&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
	Local $hGUI = GUICreate(&#039;&#039;, 500, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)&lt;br /&gt;
&lt;br /&gt;
	; Create a label that is transparent which will accept &#039;drop&#039; events.&lt;br /&gt;
	GUICtrlCreateLabel(&amp;quot;&amp;quot;, 0, 0, 500, 500)&lt;br /&gt;
	GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)&lt;br /&gt;
	GUICtrlSetResizing(-1, $GUI_DOCKALL)&lt;br /&gt;
	GUICtrlSetState(-1, $GUI_DROPACCEPTED)&lt;br /&gt;
&lt;br /&gt;
	GUIRegisterMsg($WM_DROPFILES, &amp;quot;WM_DROPFILES&amp;quot;)&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&lt;br /&gt;
				ExitLoop&lt;br /&gt;
&lt;br /&gt;
			Case $GUI_EVENT_DROPPED&lt;br /&gt;
				If $__aDropFiles[0] &amp;gt; 0 Then&lt;br /&gt;
					_ArrayDisplay($__aDropFiles)&lt;br /&gt;
				EndIf&lt;br /&gt;
&lt;br /&gt;
		EndSwitch&lt;br /&gt;
	WEnd&lt;br /&gt;
	GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func WM_DROPFILES($hWnd, $iMsg, $iwParam, $ilParam)&lt;br /&gt;
	#forceref $hWnd, $ilParam&lt;br /&gt;
	Switch $iMsg&lt;br /&gt;
		Case $WM_DROPFILES&lt;br /&gt;
			Local $aReturn = _WinAPI_DragQueryFileEx($iwParam)&lt;br /&gt;
			If IsArray($aReturn) Then&lt;br /&gt;
				$__aDropFiles = $aReturn&lt;br /&gt;
			Else&lt;br /&gt;
				Local $aError[1] = [0]&lt;br /&gt;
				$__aDropFiles = $aError&lt;br /&gt;
			EndIf&lt;br /&gt;
	EndSwitch&lt;br /&gt;
	Return $GUI_RUNDEFMSG&lt;br /&gt;
EndFunc   ;==&amp;gt;WM_DROPFILES&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ExitCheckTextChange ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 8007-negativenrg&lt;br /&gt;
 | AuthorName = NegativeNrG&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Check(when Exit), if Text is not equal to $e_to Then, prompt the user to save or not save.&lt;br /&gt;
;_ExitCheckText Change $Edit Handle, $title of messagebox, $message of messagebox, $equal to(default = NULL).&lt;br /&gt;
&lt;br /&gt;
Func _ExitCheckTextChange($E_hnd,$title,$message,$e_to = &#039;&#039;)&lt;br /&gt;
	Local $buffer, $choice, $filetosave, $handle1&lt;br /&gt;
                $buffer = GUIctrlread($E_hnd)&lt;br /&gt;
        If $buffer &amp;lt;&amp;gt; $e_to Then&lt;br /&gt;
            $choice = Msgbox(4,$title,$message)&lt;br /&gt;
            If $choice = 6 Then&lt;br /&gt;
                $filetosave = FileSaveDialog(&#039;Choose File&#039;,@scriptdir,&#039;(*.au3)&#039;)&lt;br /&gt;
                $handle1 = FileOpen($filetosave,2)&lt;br /&gt;
                FileWrite($handle1,$buffer)&lt;br /&gt;
                Exit&lt;br /&gt;
            Elseif $choice &amp;lt;&amp;gt; 6 Then&lt;br /&gt;
            Exit&lt;br /&gt;
        EndIf&lt;br /&gt;
        Else&lt;br /&gt;
        Exit&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileDeleteEx ==&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;
; Ref: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;APIFilesConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPIFiles.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_FileDeleteEx(&amp;quot;C:\Example.dat&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _FileDeleteEx($sFilePath)&lt;br /&gt;
    Return FileDelete($sFilePath) = 1 ? 1 : Int(_WinAPI_MoveFileEx(FileGetShortName($sFilePath), &amp;quot;&amp;quot;, $MOVE_FILE_DELAY_UNTIL_REBOOT))&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileDeleteEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileCheck ==&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;Date.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Check if the file was modified less than 24 hours ago.&lt;br /&gt;
ConsoleWrite( _FileCheck(@ScriptFullPath, 24) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _FileCheck($sFilePath, $iHours = 24)&lt;br /&gt;
    Local $aTime&lt;br /&gt;
    If FileExists($sFilePath) = 0 Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aTime = FileGetTime($sFilePath, 0, 0)&lt;br /&gt;
    Return Number(_DateDiff(&amp;quot;h&amp;quot;, $aTime[0] &amp;amp; &amp;quot;/&amp;quot; &amp;amp; $aTime[1] &amp;amp; &amp;quot;/&amp;quot; &amp;amp; $aTime[2] &amp;amp; &amp;quot; &amp;quot; &amp;amp; $aTime[3] &amp;amp; &amp;quot;:&amp;quot; &amp;amp; $aTime[4] &amp;amp; &amp;quot;:&amp;quot; &amp;amp; $aTime[5], @YEAR &amp;amp; &amp;quot;/&amp;quot; &amp;amp; @MON &amp;amp; &amp;quot;/&amp;quot; &amp;amp; @MDAY &amp;amp; &amp;quot; &amp;quot; &amp;amp; @HOUR &amp;amp; &amp;quot;:&amp;quot; &amp;amp; @MIN &amp;amp; &amp;quot;:&amp;quot; &amp;amp; @SEC) &amp;lt; $iHours)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileCheck&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileCreateEx ==&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;
_FileCreateEx(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;, 42)&lt;br /&gt;
&lt;br /&gt;
; Create a blank file with a certain size in bytes.&lt;br /&gt;
Func _FileCreateEx($sFilePath, $iBytes = 0)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c fsutil file createnew &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; Int($iBytes), @WorkingDir, @SW_HIDE)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileCreateEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileID ==&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;
FileClose(FileOpen(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;, 2))&lt;br /&gt;
ConsoleWrite(_FileID(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;) &amp;amp; @CRLF)&lt;br /&gt;
FileDelete(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;)&lt;br /&gt;
&lt;br /&gt;
; Rerieve the file id of a filepath.&lt;br /&gt;
Func _FileID($sFilePath)&lt;br /&gt;
    Local $iPID = Run(@ComSpec &amp;amp; &#039; /c fsutil file queryfileid &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot;&#039;, @SystemDir, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sReturn = &#039;&#039;&lt;br /&gt;
    While 1&lt;br /&gt;
        $sReturn &amp;amp;= StdoutRead($iPID)&lt;br /&gt;
        If @error Then&lt;br /&gt;
            ExitLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
    WEnd&lt;br /&gt;
    Return StringStripWS(StringRegExpReplace($sReturn, &#039;File\sID\sis\s(.*?)&#039;, &#039;$1&#039;), 8)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileExistsWithQuotes ==&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(_FileExistsWithQuotes(&#039;&amp;quot;&#039; &amp;amp; @ScriptDir &amp;amp; &#039;&amp;quot;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_FileExistsWithQuotes(&amp;quot;&#039;&amp;quot; &amp;amp; @ScriptDir &amp;amp; &amp;quot;&#039;&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_FileExistsWithQuotes(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Version: 1.00. AutoIt: V3.3.8.1&lt;br /&gt;
; Check a filepath ecists even if the path contains quotation marks.&lt;br /&gt;
Func _FileExistsWithQuotes($sFilePath)&lt;br /&gt;
    Return FileExists(StringRegExpReplace($sFilePath, &#039;^(&amp;quot;|&#039;&#039;)*([^&amp;quot;&#039;&#039;]+)(&amp;quot;|&#039;&#039;)*$&#039;, &#039;\2&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileExistsWithQuotes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== FileLineCount ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 71214-mkish&lt;br /&gt;
 | AuthorName = MKISH&lt;br /&gt;
 | Desc = Checks the number of lines in a file (useful for larger files as well)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Author - MKISH&lt;br /&gt;
&lt;br /&gt;
; Checks the number of lines in a file (useful for larger files as well)&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local $FILE = &amp;quot;G:\WIN7\sources\boot.wim&amp;quot;&lt;br /&gt;
Local $COUNT = 0&lt;br /&gt;
Local $start = default&lt;br /&gt;
Local $res, $fLen, $err&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
	$res = _HexSearch($FILE, StringToBinary(&amp;quot;&amp;quot; &amp;amp; @crlf), $start)&lt;br /&gt;
	$start = $res + 2&lt;br /&gt;
	$COUNT = $COUNT + 1&lt;br /&gt;
	If $res = -1 then exitloop&lt;br /&gt;
Wend&lt;br /&gt;
&lt;br /&gt;
msgbox(64, &amp;quot;&amp;quot;, &amp;quot;Lines count: &amp;quot; &amp;amp; $COUNT)&lt;br /&gt;
&lt;br /&gt;
; _HexSearch function (originally written by Zinthose, modified by MKISH)&lt;br /&gt;
Func _HexSearch($FilePath, $BinaryValue, $StartOffset = Default)&lt;br /&gt;
        Local $Buffer, $ptr, $hFile, $Result, $Read, $SearchValue, $Pos, $BufferSize = 2048&lt;br /&gt;
            If $StartOffset = Default     Then $StartOffset = 0&lt;br /&gt;
            If Not FileExists($FilePath)    Then    Return SetError(1, @error, 0)&lt;br /&gt;
            $fLen = FileGetSize($FilePath)&lt;br /&gt;
            If $StartOffset &amp;gt; $fLen   Then   Return SetError(2, @error, 0)&lt;br /&gt;
            If Not IsBinary($BinaryValue)   Then    Return SetError(3, @error, 0)&lt;br /&gt;
            If Not IsNumber($StartOffset)   Then    Return SetError(4, @error, 0)&lt;br /&gt;
            $SearchValue = BinaryToString($BinaryValue)&lt;br /&gt;
            $Buffer = DllStructCreate(&amp;quot;byte[&amp;quot; &amp;amp; $BufferSize &amp;amp; &amp;quot;]&amp;quot;)&lt;br /&gt;
            $ptr = DllStructGetPtr($Buffer)&lt;br /&gt;
                $hFile = _WinAPI_CreateFile($FilePath, 2, 2, 1)&lt;br /&gt;
                If $hFile = 0 Then Return SetError(5, @error, 0)&lt;br /&gt;
            $Result = _WinAPI_SetFilePointer($hFile, $StartOffset)&lt;br /&gt;
            $err = @error&lt;br /&gt;
            If $Result = 0xFFFFFFFF Then&lt;br /&gt;
                _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                Return SetError(5, $err, 0)&lt;br /&gt;
            EndIf&lt;br /&gt;
            $Pos = $StartOffset&lt;br /&gt;
            While True&lt;br /&gt;
                    $Read = 0&lt;br /&gt;
                    $Result = _WinAPI_ReadFile($hFile, $ptr, $BufferSize, $Read)&lt;br /&gt;
                    $err = @error&lt;br /&gt;
                    If Not $Result Then&lt;br /&gt;
                        _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                        Return SetError(6, $err, 0)&lt;br /&gt;
                    EndIf&lt;br /&gt;
                    $Result = DllStructGetData($Buffer, 1)&lt;br /&gt;
                    $Result = BinaryToString($Result)&lt;br /&gt;
                    $Result = StringInStr($Result, $SearchValue)&lt;br /&gt;
                    If $Result &amp;gt; 0 Then ExitLoop&lt;br /&gt;
                    If $Read &amp;lt; $BufferSize Then&lt;br /&gt;
                        _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                        Return -1&lt;br /&gt;
                    EndIf&lt;br /&gt;
                    $Pos += $Read&lt;br /&gt;
&lt;br /&gt;
            WEnd&lt;br /&gt;
            _WinAPI_CloseHandle($hFile)&lt;br /&gt;
            If Not $Result Then Return SetError(7, @error, 0)&lt;br /&gt;
            $Result = $Pos + $Result - 1&lt;br /&gt;
            Return $Result&lt;br /&gt;
    EndFunc; ==&amp;gt; _HexSearch&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileOpenDialog ==&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;
Local $sFilePath = _FileOpenDialog(&amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;Images (*.jpg;*.bmp)|Videos (*.avi;*.mpg)&amp;quot;, Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1), 1 + 4, &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;File = &#039; &amp;amp; $sFilePath &amp;amp; &#039;, @error = &#039; &amp;amp; @error &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name ..........: _FileOpenDialog&lt;br /&gt;
; Description ...: Initiates a Open File Dialog with the option to set the position of the GUI.&lt;br /&gt;
; Syntax ........: _FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter[, $iLeft = -1[, $iTop = -1[, $iOptions = 0[,&lt;br /&gt;
;                  $sDefaultName = &amp;quot;&amp;quot;]]]])&lt;br /&gt;
; Parameters ....: $sTitle              - Title text of the Dialog GUI.&lt;br /&gt;
;                  $sIntitialDirectory  - Initial directory selected in the GUI file tree.&lt;br /&gt;
;                  $sFilter             - File type single filter such as &amp;quot;All (*.*)&amp;quot; or &amp;quot;Text files (*.txt)&amp;quot;.&lt;br /&gt;
;                  $iLeft               - [optional] The left side of the dialog box. By default (-1), the window is centered.&lt;br /&gt;
;                  $iTop                - [optional] The top of the dialog box. Default (-1) is centered&lt;br /&gt;
;                  $iOptions            - [optional] Dialog Options: To use more than one option, add the required values together. See FileOpenDialog. Default is 0.&lt;br /&gt;
;                  $sDefaultName        - [optional] Suggested file name for the user to open. Default is blank (&amp;quot;&amp;quot;).&lt;br /&gt;
; Return values .: Success: Returns the full path of the file(s) chosen. Results for multiple selections are &amp;quot;Directory|file1|file2|...&amp;quot;&lt;br /&gt;
;                  Failure: Sets @error to non-zero.&lt;br /&gt;
; Author ........: guinness&lt;br /&gt;
; Remarks........: This doesn&#039;t change the working directory of the script like FileOpenDialog does.&lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter, $iLeft = -1, $iTop = -1, $iOptions = 0, $sDefaultName = &amp;quot;&amp;quot;)&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;, -1, -1, $iLeft, $iTop), $sWorkingDir = @WorkingDir&lt;br /&gt;
    Local $sFilePath = FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter, $iOptions, $sDefaultName, $hGUI)&lt;br /&gt;
    Local $iError = @error&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return SetError($iError, GUIDelete($hGUI), $sFilePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileOpenDialog()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileRename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 52374-johnone&lt;br /&gt;
 | AuthorName = JohnOne&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;### Rename a file ###&lt;br /&gt;
;$sFile = Full path to file&lt;br /&gt;
;$sRename = New Filename&lt;br /&gt;
;$iOverWrite = 0 or 1&lt;br /&gt;
&lt;br /&gt;
;Success returns 1&lt;br /&gt;
;failure, returns 0 and sets @error&lt;br /&gt;
; 1 if FileMove fails, &lt;br /&gt;
; 2 if $sFile does not exist&lt;br /&gt;
;@extended&lt;br /&gt;
; 0 if the new file does not already exist / existed&lt;br /&gt;
; 1 if the new file already exists / existed&lt;br /&gt;
&lt;br /&gt;
;#### Example ####&lt;br /&gt;
$File = @ScriptDir &amp;amp; &#039;\filetorename.txt&#039;&lt;br /&gt;
FileWrite($File, &#039;Test&#039;)&lt;br /&gt;
_FileRename($File, &#039;newname.txt&#039;)&lt;br /&gt;
If @error Then MsgBox(0, &amp;quot;Error&amp;quot;, @error)&lt;br /&gt;
&lt;br /&gt;
Func _FileRename($sFile, $sRename, $iOverWrite = 0)&lt;br /&gt;
    Local Const $FILENOTEXIST = 2&lt;br /&gt;
    If Not FileExists($sFile) Then Return SetError($FILENOTEXIST, 0, 0)&lt;br /&gt;
    Local $_StringLen = StringLen($sFile)&lt;br /&gt;
    Local $_StringInStr = StringInStr($sFile, &amp;quot;\&amp;quot;, 0, -1, $_StringLen)&lt;br /&gt;
    Local $_Count = $_StringLen - $_StringInStr&lt;br /&gt;
    Local $_Dir = StringLeft($sFile, $_StringInStr)&lt;br /&gt;
    Local $_NewFile = $_Dir &amp;amp; $sRename&lt;br /&gt;
    Local $_NewFileExists = FileExists($_NewFile)&lt;br /&gt;
    Local $_FileMove = FileMove($sFile, $_NewFile, $iOverWrite)&lt;br /&gt;
    Return SetError(Not $_FileMove, $_NewFileExists, $_FileMove)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileRename&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== _FileRename Alternative ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;FileRename(PathFile, RenameFile)&lt;br /&gt;
;JohnOne&lt;br /&gt;
&lt;br /&gt;
FileRename(@ScriptDir &amp;amp; &amp;quot;\rename.txt&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\renamed.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func FileRename($FileName, $ReName)&lt;br /&gt;
&lt;br /&gt;
	Local $SHFILEOPSTRUCT, $SourceStruct, $DestStruct&lt;br /&gt;
	Local Const $FO_RENAME = 0x0004&lt;br /&gt;
	Local Const $FOF_SILENT = 0x0004&lt;br /&gt;
	Local Const $FOF_NOCONFIRMATION = 0x0010&lt;br /&gt;
	Local Const $FOF_NOERRORUI = 0x0400&lt;br /&gt;
	Local Const $FOF_NOCONFIRMMKDIR = 0x0200&lt;br /&gt;
	Local Const $NULL = 0&lt;br /&gt;
&lt;br /&gt;
	$SourceStruct = _StringToStruct($FileName)&lt;br /&gt;
	$DestStruct = _StringToStruct($ReName)&lt;br /&gt;
&lt;br /&gt;
	$SHFILEOPSTRUCT = DllStructCreate(&amp;quot;hwnd hWnd;uint wFunc;ptr pFrom;ptr pTo;int fFlags;int fAnyOperationsAborted;ptr hNameMappings;ptr lpszProgressTitle&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;hWnd&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;wFunc&amp;quot;, $FO_RENAME)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;pFrom&amp;quot;, DllStructGetPtr($SourceStruct))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;pTo&amp;quot;, DllStructGetPtr($DestStruct))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;fFlags&amp;quot;, BitOR($FOF_SILENT, $FOF_NOCONFIRMATION, $FOF_NOERRORUI, $FOF_NOCONFIRMMKDIR))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;fAnyOperationsAborted&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;hNameMappings&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;lpszProgressTitle&amp;quot;, $NULL)&lt;br /&gt;
&lt;br /&gt;
	$acall = DllCall(&amp;quot;shell32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;SHFileOperation&amp;quot;, &amp;quot;ptr&amp;quot;, DllStructGetPtr($SHFILEOPSTRUCT))&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Return SetError(@error, @extended, 0)&lt;br /&gt;
	EndIf&lt;br /&gt;
	Return 1&lt;br /&gt;
EndFunc   ;==&amp;gt;FileRename&lt;br /&gt;
&lt;br /&gt;
Func _StringToStruct($string)&lt;br /&gt;
&lt;br /&gt;
	Local $iLen = StringLen($string)&lt;br /&gt;
	Local $Struct = DllStructCreate(&amp;quot;char[&amp;quot; &amp;amp; String($iLen + 2) &amp;amp; &amp;quot;]&amp;quot;)&lt;br /&gt;
	DllStructSetData($Struct, 1, $string)&lt;br /&gt;
	DllStructSetData($Struct, 1, 0, $iLen + 1)&lt;br /&gt;
	DllStructSetData($Struct, 1, 0, $iLen + 2)&lt;br /&gt;
&lt;br /&gt;
	Return $Struct&lt;br /&gt;
EndFunc   ;==&amp;gt;_StringToStruct&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFolderDepth ==&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;
; Autoit 3.3.5.4 and Below&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir &amp;amp; &#039;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the folder depth of a filepath.&lt;br /&gt;
Func _GetFolderDepth($sFilePath)&lt;br /&gt;
    If StringInStr($sFilePath, &#039;.&#039;, 2, -1) Then&lt;br /&gt;
        $sFilePath = StringLeft($sFilePath, StringInStr($sFilePath, &amp;quot;&amp;quot;, 2, -1) - 1)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $aArray = StringSplit(StringRegExpReplace($sFilePath, &#039;[/]+z&#039;, &#039;&#039;), &#039;&#039;)&lt;br /&gt;
    Return $aArray[0] - 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFolderDepth&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFolderDepth ==&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;
; Autoit 3.3.5.4 and Above&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir &amp;amp; &#039;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the folder depth of a filepath. Works with V3.3.5.4+&lt;br /&gt;
Func _GetFolderDepth($sFilePath)&lt;br /&gt;
    If StringInStr($sFilePath, &#039;.&#039;, 2, -1) Then&lt;br /&gt;
        $sFilePath = StringLeft($sFilePath, StringInStr($sFilePath, &amp;quot;&amp;quot;, 2, -1) - 1)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return StringSplit(StringRegExpReplace($sFilePath, &#039;[/]+z&#039;, &#039;&#039;), &#039;&#039;)[0] - 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFolderDepth&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsDir ==&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;IsDir: Using a file - &amp;quot; &amp;amp; IsDir(@ScriptFullPath) &amp;amp; @CRLF) ; Return 0&lt;br /&gt;
ConsoleWrite(&amp;quot;IsDir: Using a directory - &amp;quot; &amp;amp; IsDir(@ScriptDir) &amp;amp; @CRLF) ; Return 1&lt;br /&gt;
&lt;br /&gt;
Func IsDir($sFilePath)&lt;br /&gt;
	Return Int(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), &#039;D&#039;, Default, 1) &amp;gt; 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;IsDir&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFile ==&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(&#039;IsFile: Using a file - &#039; &amp;amp; IsFile(@ScriptFullPath) &amp;amp; @CRLF) ; Return 1&lt;br /&gt;
ConsoleWrite(&#039;IsFile: Using a directory - &#039; &amp;amp; IsFile(@ScriptDir) &amp;amp; @CRLF) ; Return 0&lt;br /&gt;
&lt;br /&gt;
Func IsFile($sFilePath)&lt;br /&gt;
	Return Int(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), &#039;D&#039;, Default, 1) = 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;IsFilee&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileDiff ==&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(_IsFileDiff(@ScriptFullPath, @ScriptFullPath) &amp;amp; @CRLF) ; This will return False as the files are exactly the same.&lt;br /&gt;
ConsoleWrite(_IsFileDiff(@ScriptFullPath, @AutoItExe) &amp;amp; @CRLF) ; This will return True as the files are different.&lt;br /&gt;
&lt;br /&gt;
; Check if a file is different.&lt;br /&gt;
Func _IsFileDiff($sFilePath_1, $sFilePath_2)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c FC /B /W &amp;quot;&#039; &amp;amp; $sFilePath_1 &amp;amp; &#039;&amp;quot; &amp;quot;&#039; &amp;amp; $sFilePath_2 &amp;amp; &#039;&amp;quot;&#039;, @WorkingDir, @SW_HIDE) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileDiff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileOlder ==&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;Date.au3&amp;gt; ; Required for _DateDiff()&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;MsgBoxConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Check if the current script is older than 10 days.&lt;br /&gt;
If _IsFileOlder(@ScriptFullPath, 10) Then&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;File is older than 10 days.&#039;)&lt;br /&gt;
Else&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &#039;&#039;, &#039;File isn&#039;&#039;t older than 10 days.&#039;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
; Is a file older than a certain number of days.&lt;br /&gt;
Func _IsFileOlder($sFilePath, $iDays)&lt;br /&gt;
	Local $aArray = FileGetTime($sFilePath, $FT_CREATED)&lt;br /&gt;
	Return _DateDiff(&#039;D&#039;, $aArray[0] &amp;amp; &#039;/&#039; &amp;amp; $aArray[1] &amp;amp; &#039;/&#039; &amp;amp; $aArray[2] &amp;amp; &#039; &#039; &amp;amp; $aArray[3] &amp;amp; &#039;:&#039; &amp;amp; $aArray[4] &amp;amp; &#039;:&#039; &amp;amp; $aArray[5], @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) &amp;gt;= $iDays&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileOlder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileSame ==&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(_IsFileSame(@ScriptFullPath, @ScriptFullPath) &amp;amp; @CRLF) ; This will return True as the files are exactly the same.&lt;br /&gt;
ConsoleWrite(_IsFileSame(@ScriptFullPath, @AutoItExe) &amp;amp; @CRLF) ; This will return False as the files are different.&lt;br /&gt;
&lt;br /&gt;
; Check if a file is the same.&lt;br /&gt;
Func _IsFileSame($sFilePath_1, $sFilePath_2)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c FC /B /W &amp;quot;&#039; &amp;amp; $sFilePath_1 &amp;amp; &#039;&amp;quot; &amp;quot;&#039; &amp;amp; $sFilePath_2 &amp;amp; &#039;&amp;quot;&#039;, @WorkingDir, @SW_HIDE) = 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileSame&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IniReadFile ==&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;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__INIFileFill(@ScriptDir &amp;amp; &#039;\Example.ini&#039;) ; Create an INI file with random data.&lt;br /&gt;
&lt;br /&gt;
Local $aArray = _IniReadFile(@ScriptDir &amp;amp; &#039;\Example.ini&#039;)&lt;br /&gt;
FileDelete(@ScriptDir &amp;amp; &#039;\Example.ini&#039;)&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&lt;br /&gt;
Func _IniReadFile($sFilePath)&lt;br /&gt;
    Local $aReturn[1][3] = [[0, 3]], $aSectionArray, $aSectionNameArray, $iCount = 0&lt;br /&gt;
    $aSectionNameArray = IniReadSectionNames($sFilePath)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $aReturn)&lt;br /&gt;
    EndIf&lt;br /&gt;
    For $A = 1 To $aSectionNameArray[0]&lt;br /&gt;
        $aSectionArray = IniReadSection($sFilePath, $aSectionNameArray[$A])&lt;br /&gt;
        If @error Then&lt;br /&gt;
            ContinueLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
        For $B = 1 To $aSectionArray[0][0]&lt;br /&gt;
            $aReturn[0][0] += 1&lt;br /&gt;
            $iCount += 1&lt;br /&gt;
            If $aReturn[0][0] &amp;lt;= $iCount + 1 Then&lt;br /&gt;
                ReDim $aReturn[$aReturn[0][0] * 2][$aReturn[0][1]]&lt;br /&gt;
            EndIf&lt;br /&gt;
            $aReturn[$iCount][0] = $aSectionArray[$B][0]&lt;br /&gt;
            $aReturn[$iCount][1] = $aSectionArray[$B][1]&lt;br /&gt;
            $aReturn[$iCount][2] = $aSectionNameArray[$A]&lt;br /&gt;
        Next&lt;br /&gt;
    Next&lt;br /&gt;
    ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1]] ; Remove empty entries.&lt;br /&gt;
    Return $aReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_IniReadFile&lt;br /&gt;
&lt;br /&gt;
Func __INIFileFill($sFilePath)&lt;br /&gt;
    Local $sData = &#039;&#039;, $sHeader = &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To Random(1, 5, 1)&lt;br /&gt;
        $sHeader = _RandomText(Random(5, 25, 1))&lt;br /&gt;
        $sData = &amp;quot;&amp;quot;&lt;br /&gt;
        For $j = 1 To Random(1, 25, 1)&lt;br /&gt;
            $sData &amp;amp;= _RandomText(Random(5, 25, 1)) &amp;amp; &#039;=&#039; &amp;amp; _RandomText(Random(5, 25, 1)) &amp;amp; @LF&lt;br /&gt;
        Next&lt;br /&gt;
        IniWriteSection($sFilePath, $sHeader, $sData)&lt;br /&gt;
    Next&lt;br /&gt;
EndFunc   ;==&amp;gt;__FillINIFile&lt;br /&gt;
&lt;br /&gt;
Func _RandomText($iLength = 10)&lt;br /&gt;
    Local $sData = &#039;&#039;, $sRandom = &#039;&#039;&lt;br /&gt;
    For $i = 1 To $iLength&lt;br /&gt;
        $sRandom = Random(55, 116, 1)&lt;br /&gt;
        $sData &amp;amp;= Chr($sRandom + 6 * ($sRandom &amp;gt; 90) - 7 * ($sRandom &amp;lt; 65))&lt;br /&gt;
    Next&lt;br /&gt;
    Return $sData&lt;br /&gt;
EndFunc   ;==&amp;gt;_RandomText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IniReadInit ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 9370-mlowery&lt;br /&gt;
 | AuthorName = mlowery&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;===============================================================================&lt;br /&gt;
; Description:     Reads values from INI or creates INI with initial values.&lt;br /&gt;
;                  Intended to ensure all available INI settings are exposed&lt;br /&gt;
;                  and editable.&lt;br /&gt;
;                  Parameters are identical to IniRead()&lt;br /&gt;
; Parameter(s):    $filename  = filename of INI&lt;br /&gt;
;                  $section  = section name of INI&lt;br /&gt;
;                  $key      = key name in section&lt;br /&gt;
;                  $default  = default value (written to INI if not exists)&lt;br /&gt;
; Requirement(s):  None&lt;br /&gt;
; Return Value(s): Returns value from INI (or default if not defined)&lt;br /&gt;
; Note(s):         Chr(127) used to detect non-existing value since won&#039;t normally exist in a text file&lt;br /&gt;
;===============================================================================&lt;br /&gt;
Func _IniReadInit($filename, $section, $key, $default)&lt;br /&gt;
  Local $value = IniRead($filename, $section, $key, Chr(127))&lt;br /&gt;
    If $value = Chr(127) Then&lt;br /&gt;
      IniWrite($filename, $section, $key, $default)&lt;br /&gt;
      $value = $default&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $value&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsValidFileType ==&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(@ScriptFullPath &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@ScriptFullPath, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(@AutoItExe &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@AutoItExe, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a filepath matches an extension filetype. Based on the idea by guinness - http://www.autoitscript.com/forum/topic/123674-isvalidfiletype/&lt;br /&gt;
Func _IsValidFileType($sFilePath, $sList = &amp;quot;bat;cmd;exe&amp;quot;) ; By AZJIO - http://www.autoitscript.com/forum/topic/...filetype/page__view__findpost_&lt;br /&gt;
    Local $iDot = StringInStr($sFilePath, &amp;quot;.&amp;quot;, 0, -1)&lt;br /&gt;
    Return $iDot And StringInStr(&#039;;&#039; &amp;amp; $sList &amp;amp; &#039;;&#039;, &#039;;&#039; &amp;amp; StringTrimLeft($sFilePath, $iDot) &amp;amp; &#039;;&#039;) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsValidFileType&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;
; Example 2&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(@ScriptFullPath &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@ScriptFullPath, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(@AutoItExe &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@AutoItExe, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a filepath matches an extension filetype. Based on the idea by guinness - http://www.autoitscript.com/forum/topic/123674-isvalidfiletype/&lt;br /&gt;
Func _IsValidFileType($sFilePath, $sList = &amp;quot;bat;cmd;exe&amp;quot;, $iOpFast = 1) ; By Yashied.&lt;br /&gt;
    If StringStripWS($sList, 8) = &amp;quot;&amp;quot; Then&lt;br /&gt;
        $sList = &amp;quot;*&amp;quot;&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return _WinAPI_PathMatchSpec($sFilePath, StringReplace(&#039;;&#039; &amp;amp; $sList, &#039;;&#039;, &#039;;*.&#039;, 0, $iOpFast * 2))&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsValidFileType&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== File Open/Save/Folder Dialog Box ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 2709-mhz&lt;br /&gt;
 | AuthorName = MHz&lt;br /&gt;
 | AuthorURL2 = 4997-odklizec&lt;br /&gt;
 | AuthorName2 = odklizec&lt;br /&gt;
 | AuthorURL3 = 6756-danny35d&lt;br /&gt;
 | AuthorName3 = Danny35d&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Center - File Open/Save/Folder Dialog Box&lt;br /&gt;
; Author - odklizec, MHz, Danny35d&lt;br /&gt;
&lt;br /&gt;
 If StringInStr($cmdlineraw, &#039;/MoveWin&#039;) Then&lt;br /&gt;
	 Local $size, $PosX, $PosY&lt;br /&gt;
     $cmdlineraw = StringSplit(StringMid($cmdlineraw, StringInStr($cmdlineraw, &#039;/MoveWin&#039;)), &#039;:&#039;)&lt;br /&gt;
     While 1&lt;br /&gt;
         Select&lt;br /&gt;
         Case WinExists($cmdlineraw[2])&lt;br /&gt;
             $size=WinGetPos ($cmdlineraw[2])&lt;br /&gt;
             $PosX=@DesktopWidth/2 - $size[2]/2&lt;br /&gt;
             $PosY=@DesktopHeight/2 - $size[3]/2&lt;br /&gt;
             WinMove($cmdlineraw[2], &amp;quot;&amp;quot;, $PosX, $PosY)&lt;br /&gt;
             WinActivate($cmdlineraw[2])&lt;br /&gt;
             ExitLoop&lt;br /&gt;
         EndSelect&lt;br /&gt;
         Sleep(50)&lt;br /&gt;
     WEnd&lt;br /&gt;
     Exit&lt;br /&gt;
 EndIf&lt;br /&gt;
Global $PID, $Read_File, $Save_File&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Open file Dialog Box&#039;)&lt;br /&gt;
 $Read_File = FileOpenDialog ( &amp;quot;Open file Dialog Box&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\&amp;quot;, &amp;quot;AutoIt Files (*.au3)&amp;quot;,3,@ScriptFullPath)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Save file Dialog Box&#039;)&lt;br /&gt;
 $Save_File = FileSaveDialog( &amp;quot;Save file Dialog Box&amp;quot;, @ScriptDir, &amp;quot;Scripts (*.aut;*.au3)&amp;quot;, 3)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Browse for Folder&#039;)&lt;br /&gt;
 FileSelectFolder(&amp;quot;Choose a folder with plugins..&amp;quot;, &amp;quot;&amp;quot;,&amp;quot;4&amp;quot;,&amp;quot;c:\&amp;quot;)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
&lt;br /&gt;
 Func _FindBrowseWin($sTitle)&lt;br /&gt;
     If @Compiled Then&lt;br /&gt;
         Return(Run(@ScriptFullPath &amp;amp; &#039; /MoveWin:&#039; &amp;amp; $sTitle))&lt;br /&gt;
     Else&lt;br /&gt;
         Return(Run(@AutoItExe &amp;amp; &#039; &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot; /MoveWin:&#039; &amp;amp; $sTitle))&lt;br /&gt;
     EndIf&lt;br /&gt;
 EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _MoveFileOnReboot ==&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.2.0, Creation Date = 21/03/12.&lt;br /&gt;
&lt;br /&gt;
; Function to Move or Delete a file on next reboot!&lt;br /&gt;
Func _MoveFileOnReboot($sSourcePath, $sDestPath = &amp;quot;&amp;quot;); If $sDestPath = &amp;quot;&amp;quot; the file is deleted instead of moved.&lt;br /&gt;
    Local $iRet&lt;br /&gt;
&lt;br /&gt;
    ; PendingFileRenameOperations (HKLM\SYSTEM\CurrentControlSet\Control\Session Manager)&lt;br /&gt;
    If $DestPath = &amp;quot;&amp;quot; Then&lt;br /&gt;
        $iRet = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;MoveFileExA&amp;quot;, &amp;quot;str&amp;quot;, $sSourcePath, &amp;quot;int&amp;quot;, 0, &amp;quot;dword&amp;quot;, 4)&lt;br /&gt;
    Else&lt;br /&gt;
        $iRet = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;MoveFileExA&amp;quot;, &amp;quot;str&amp;quot;, $sSourcePath, &amp;quot;str&amp;quot;, $sDestPath, &amp;quot;dword&amp;quot;, 4)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return $iRet&lt;br /&gt;
EndFunc   ;==&amp;gt;_MoveFileOnReboot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _MultipleFileOpenDialog ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL =&lt;br /&gt;
 | AuthorName = /dev/null&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Local $message = &amp;quot;Hold down Ctrl or Shift to choose multiple files.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Local $filename = _MultipleFileOpenDialog($message,300,300)&lt;br /&gt;
&lt;br /&gt;
Local $var = FileOpenDialog($message, @WindowsDir &amp;amp; &amp;quot;\&amp;quot;, &amp;quot;Images (*.jpg;*.bmp)&amp;quot;, 1 + 4 )&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    MsgBox(4096,&amp;quot;&amp;quot;,&amp;quot;No File(s) chosen&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
    $var = StringReplace($var, &amp;quot;|&amp;quot;, @CRLF)&lt;br /&gt;
    MsgBox(4096,&amp;quot;&amp;quot;,&amp;quot;You chose &amp;quot; &amp;amp; $var)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
FileDelete($filename)&lt;br /&gt;
func _MultipleFileOpenDialog($title,$posx,$posy)&lt;br /&gt;
    Local $temp = EnvGet(&amp;quot;temp&amp;quot;)&lt;br /&gt;
    Local $filename = $temp &amp;amp; &amp;quot;\move_file_open_dialog.au3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    Local $script = &#039;Global $title = &amp;quot;&#039; &amp;amp; $title &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Global $pos_x = &#039; &amp;amp; $posx &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Global $pos_y = &#039; &amp;amp; $posy &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;AdlibRegister(&amp;quot;_Move&amp;quot;,10)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;while 1&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;    sleep(1000)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;wend&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Func _Move()&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;   if (WinActive($title)) Then&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;      WinMove($title,&amp;quot;&amp;quot;,$pos_x,$pos_y)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;      Exit&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;   EndIf&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;EndFunc&#039; &amp;amp; @CRLF&lt;br /&gt;
&lt;br /&gt;
    FileWrite($filename,$script)&lt;br /&gt;
    ;MsgBox(0,&amp;quot;&amp;quot;,$script &amp;amp; @CRLF &amp;amp; $filename)&lt;br /&gt;
    Run(@AutoItExe &amp;amp; &amp;quot; /AutoIt3ExecuteScript &amp;quot; &amp;amp; $filename)&lt;br /&gt;
    sleep(250)&lt;br /&gt;
    Return $filename&lt;br /&gt;
EndFunc ;==&amp;gt;_MultipleFileOpenDialog()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _OpenFolder ==&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;
#cs&lt;br /&gt;
    These have been declared in Global scope as you may wish to use them elsewhere in your script.&lt;br /&gt;
#ce&lt;br /&gt;
Global $ALTSTARTUP = 0x1d&lt;br /&gt;
Global $APPDATA = 0x1a&lt;br /&gt;
Global $BITBUCKET = 0x0a&lt;br /&gt;
Global $COMMONALTSTARTUP = 0x1e&lt;br /&gt;
Global $COMMONAPPDATA = 0x23&lt;br /&gt;
Global $COMMONDESKTOPDIR = 0x19&lt;br /&gt;
Global $COMMONFAVORITES = 0x1f&lt;br /&gt;
Global $COMMONPROGRAMS = 0x17&lt;br /&gt;
Global $COMMONSTARTMENU = 0x16&lt;br /&gt;
Global $COMMONSTARTUP = 0x18&lt;br /&gt;
Global $CONTROLS = 0x03&lt;br /&gt;
Global $COOKIES = 0x21&lt;br /&gt;
Global $DESKTOP = 0x00&lt;br /&gt;
Global $DESKTOPDIRECTORY = 0x10&lt;br /&gt;
Global $DRIVES = 0x11&lt;br /&gt;
Global $FAVORITES = 0x06&lt;br /&gt;
Global $FONTS = 0x14&lt;br /&gt;
Global $HISTORY = 0x22&lt;br /&gt;
Global $INTERNETCACHE = 0x20&lt;br /&gt;
Global $LOCALAPPDATA = 0x1c&lt;br /&gt;
Global $MYPICTURES = 0x27&lt;br /&gt;
Global $NETHOOD = 0x13&lt;br /&gt;
Global $NETWORK = 0x12&lt;br /&gt;
Global $PERSONAL = 0x05&lt;br /&gt;
Global $PRINTERS = 0x04&lt;br /&gt;
Global $PRINTHOOD = 0x1b&lt;br /&gt;
Global $PROFILE = 0x28&lt;br /&gt;
Global $PROGRAMFILES = 0x26&lt;br /&gt;
Global $PROGRAMFILESx86 = 0x30&lt;br /&gt;
Global $PROGRAMS = 0x02&lt;br /&gt;
Global $RECENT = 0x08&lt;br /&gt;
Global $SENDTO = 0x09&lt;br /&gt;
Global $STARTMENU = 0x0b&lt;br /&gt;
Global $STARTUP = 0x07&lt;br /&gt;
Global $SYSTEM = 0x25&lt;br /&gt;
Global $SYSTEMx86 = 0x29&lt;br /&gt;
Global $TEMPLATES = 0x15&lt;br /&gt;
Global $WINDOWS = 0x24&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_OpenFolder(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_OpenFolder($PRINTERS) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Open a folder or special folder variable, similar to using ShellExecute.&lt;br /&gt;
Func _OpenFolder($sFolderPath)&lt;br /&gt;
    Local $oShell = ObjCreate(&#039;shell.application&#039;)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $oShell.Open($sFolderPath)&lt;br /&gt;
    Return 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_OpenFolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _PathAppendToFilename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 31965-progandy&lt;br /&gt;
 | AuthorName = ProgAndy&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
$sOrg = &amp;quot;C:\Some.Folder\some.file.ext&amp;quot;&lt;br /&gt;
$sAdd = &amp;quot;_backup&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$sNew = _PathAppendToFilename($sOrg, $sAdd)&lt;br /&gt;
&lt;br /&gt;
$sStripped = _PathStripRightFromFilename($sNew, $sAdd)&lt;br /&gt;
&lt;br /&gt;
MsgBox(0, &amp;quot;&amp;quot;, $sOrg &amp;amp; @CRLF &amp;amp; $sAdd &amp;amp; @CRLF &amp;amp; $sNew &amp;amp; @CRLF &amp;amp; $sStripped)&lt;br /&gt;
&lt;br /&gt;
Func _PathAppendToFilename($sName, $sAppend)&lt;br /&gt;
    ; Author: ProgAndy&lt;br /&gt;
    If StringRegExp($sAppend, &#039;[\/\\:\?&amp;quot;&amp;lt;&amp;gt;\|\*]&#039;) Then Return SetError(1, 0, $sName)&lt;br /&gt;
    Return StringRegExpReplace($sName, &amp;quot;(\.[^\\/\.]+)$&amp;quot;, $sAppend &amp;amp; &amp;quot;\1&amp;quot;, 1)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _PathStripRightFromFilename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 31965-progandy&lt;br /&gt;
 | AuthorName = ProgAndy&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Func _PathStripRightFromFilename($sName, $sStrip)&lt;br /&gt;
    ; Author: ProgAndy&lt;br /&gt;
    If StringRegExp($sStrip, &#039;[\/\\:\?&amp;quot;&amp;lt;&amp;gt;\|\*]&#039;) Then Return SetError(1, 0, $sName)&lt;br /&gt;
    Return StringRegExpReplace($sName, &amp;quot;\Q&amp;quot; &amp;amp; $sStrip &amp;amp; &amp;quot;\E(\.[^\\/\.]+)$&amp;quot;, &amp;quot;\1&amp;quot;, 1)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SelfDelete ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 2709-mhz&lt;br /&gt;
 | AuthorName = MHz&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; This also removes the directory which the file is in&lt;br /&gt;
; Author MHz with the directory delete addition by The Kandie Man&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;:loop2&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;rmdir /q &amp;quot;&#039; &amp;amp; $dirToDelete &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;if exist &amp;quot;&#039; &amp;amp; $dirToDelete &amp;amp; &#039;&amp;quot; goto loop2&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;del &#039; &amp;amp; @TempDir &amp;amp; &#039;\scratch.bat&#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&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ShellExecuteFileSelectFolder ==&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(_ShellExecuteFileSelectFolder(&#039;Select a Folder&#039;, @HomeDrive) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Shell Execute a selected folder.&lt;br /&gt;
Func _ShellExecuteFileSelectFolder($sText, $sRoot, $iFlag = 0, $sInitialDir = &#039;&#039;, $hWnd = &#039;&#039;)&lt;br /&gt;
    Local $sFolder = FileSelectFolder($sText, $sRoot, $iFlag, $sInitialDir, $hWnd)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(@error, @extended, &#039;&#039;)&lt;br /&gt;
    EndIf&lt;br /&gt;
    ShellExecute($sFolder)&lt;br /&gt;
    Return $sFolder&lt;br /&gt;
EndFunc   ;==&amp;gt;_ShellExecuteFileSelectFolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SuiCide ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 28010-larrydalooza&lt;br /&gt;
 | AuthorName = LarryDalooza&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; IMPORTANT MAKE A COPY OF SCRIPT BEFORE DELETION&lt;br /&gt;
; Deletes the running script&lt;br /&gt;
&lt;br /&gt;
Func SuiCide()&lt;br /&gt;
	Local $sFilePath = @TempDir &amp;amp; &#039;\SuiCide.bat&#039;&lt;br /&gt;
	FileDelete($sFilePath)&lt;br /&gt;
	FileWrite($sFilePath, &#039;loop:&#039; &amp;amp; @CRLF &amp;amp; &#039;del &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
			&#039;ping -n 1 -w 250 zxywqxz_q&#039; &amp;amp; @CRLF &amp;amp; &#039;if exist &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; _&lt;br /&gt;
			&#039;&amp;quot; goto loop&#039; &amp;amp; @CRLF &amp;amp; &#039;del SuiCide.bat&#039; &amp;amp; @CRLF)&lt;br /&gt;
	Exit Run($sFilePath, @TempDir, @SW_HIDE)&lt;br /&gt;
EndFunc   ;==&amp;gt;SuiCide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _UniqueFilename ==&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;
&lt;br /&gt;
ConsoleWrite(_UniqueFilename(@ScriptDir, &#039;.au3&#039;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _UniqueFilename($sFilePath, $sExtension)&lt;br /&gt;
    Local $iRandom = 0, $sUnqiueFileName = &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
    $sExtension = &#039;.&#039; &amp;amp; StringRegExpReplace($sExtension, &#039;\A[\.]+&#039;, &#039;&#039;)&lt;br /&gt;
    $sFilePath = StringRegExpReplace($sFilePath, &#039;[\\/]+\z&#039;, &#039;&#039;) &amp;amp; &#039;\&#039;&lt;br /&gt;
    While 1&lt;br /&gt;
        $iRandom = Random(55, 116, 1)&lt;br /&gt;
        $sUnqiueFileName &amp;amp;= Chr($iRandom + 6 * ($iRandom &amp;gt; 90) - 7 * ($iRandom &amp;lt; 65))&lt;br /&gt;
        If FileExists($sFilePath &amp;amp; $sUnqiueFileName &amp;amp; $sExtension) = 0 And StringLen($sUnqiueFileName) &amp;gt; 7 Then&lt;br /&gt;
            ExitLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
    WEnd&lt;br /&gt;
    Return $sFilePath &amp;amp; $sUnqiueFileName &amp;amp; $sExtension&lt;br /&gt;
EndFunc   ;==&amp;gt;_UniqueFilename&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Windows - Copy With Progress ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 19-jos&lt;br /&gt;
 | AuthorName = Jos&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Windows - Copy With Progress&lt;br /&gt;
&lt;br /&gt;
;~ 4 Do not display a progress dialog box.&lt;br /&gt;
;~ 8 Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.&lt;br /&gt;
;~ 16 Respond with &amp;quot;Yes to All&amp;quot; for any dialog box that is displayed.&lt;br /&gt;
;~ 64 Preserve undo information, if possible.&lt;br /&gt;
;~ 128 Perform the operation on files only if a wildcard file name (*.*) is specified.&lt;br /&gt;
;~ 256 Display a progress dialog box but do not show the file names.&lt;br /&gt;
;~ 512 Do not confirm the creation of a new directory if the operation requires one to be created.&lt;br /&gt;
;~ 1024 Do not display a user interface if an error occurs.&lt;br /&gt;
;~ 2048 Version 4.71. Do not copy the security attributes of the file.&lt;br /&gt;
;~ 4096 Only operate in the local directory. Don&#039;t operate recursively into subdirectories.&lt;br /&gt;
;~ 8192 Version 5.0. Do not copy connected files as a group. Only copy the specified files.&lt;br /&gt;
&lt;br /&gt;
_FileCopy(&amp;quot;C:\Installed Apps\Patches\WindowsXP-KB835935-SP2-ENU.exe&amp;quot;,&amp;quot;C:\temp&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
; to copy a directory the destination directory must exist&lt;br /&gt;
&lt;br /&gt;
Func _FileCopy($fromFile,$tofile)&lt;br /&gt;
    Local $FOF_RESPOND_YES = 16&lt;br /&gt;
    Local $FOF_SIMPLEPROGRESS = 256&lt;br /&gt;
    $winShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
    $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_Files_%26_Folders_)&amp;diff=12408</id>
		<title>Snippets ( Files &amp; Folders )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_Files_%26_Folders_)&amp;diff=12408"/>
		<updated>2014-05-12T19:34:08Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* _IsFile */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
[[category:Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Snippet Credit Header}}&lt;br /&gt;
&lt;br /&gt;
== _ConvertFileToUTF16 ==&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;
_ConvertFileToUTF16(@ScriptDir &amp;amp; &amp;quot;\Example.xml&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _ConvertFileToUTF16($sFilePath)&lt;br /&gt;
    Local $iEncoding = FileGetEncoding($sFilePath)&lt;br /&gt;
    Local $hFileOpen = FileOpen($sFilePath, $iEncoding)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $sData = FileRead($hFileOpen)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
&lt;br /&gt;
    $hFileOpen = FileOpen($sFilePath, 2 + 32)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(2, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    FileWrite($hFileOpen, $sData)&lt;br /&gt;
    Return FileClose($hFileOpen)&lt;br /&gt;
EndFunc   ;==&amp;gt;_ConvertFileToUTF16&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== DropFiles ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 35302-guinness&lt;br /&gt;
 | AuthorName = guinness&lt;br /&gt;
 | Desc = Dropping multiple files onto a GUI&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Dropping multiple files onto a GUI&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;APIConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $__aDropFiles&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
	Local $hGUI = GUICreate(&#039;&#039;, 500, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)&lt;br /&gt;
&lt;br /&gt;
	; Create a label that is transparent which will accept &#039;drop&#039; events.&lt;br /&gt;
	GUICtrlCreateLabel(&amp;quot;&amp;quot;, 0, 0, 500, 500)&lt;br /&gt;
	GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)&lt;br /&gt;
	GUICtrlSetResizing(-1, $GUI_DOCKALL)&lt;br /&gt;
	GUICtrlSetState(-1, $GUI_DROPACCEPTED)&lt;br /&gt;
&lt;br /&gt;
	GUIRegisterMsg($WM_DROPFILES, &amp;quot;WM_DROPFILES&amp;quot;)&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&lt;br /&gt;
				ExitLoop&lt;br /&gt;
&lt;br /&gt;
			Case $GUI_EVENT_DROPPED&lt;br /&gt;
				If $__aDropFiles[0] &amp;gt; 0 Then&lt;br /&gt;
					_ArrayDisplay($__aDropFiles)&lt;br /&gt;
				EndIf&lt;br /&gt;
&lt;br /&gt;
		EndSwitch&lt;br /&gt;
	WEnd&lt;br /&gt;
	GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func WM_DROPFILES($hWnd, $iMsg, $iwParam, $ilParam)&lt;br /&gt;
	#forceref $hWnd, $ilParam&lt;br /&gt;
	Switch $iMsg&lt;br /&gt;
		Case $WM_DROPFILES&lt;br /&gt;
			Local $aReturn = _WinAPI_DragQueryFileEx($iwParam)&lt;br /&gt;
			If IsArray($aReturn) Then&lt;br /&gt;
				$__aDropFiles = $aReturn&lt;br /&gt;
			Else&lt;br /&gt;
				Local $aError[1] = [0]&lt;br /&gt;
				$__aDropFiles = $aError&lt;br /&gt;
			EndIf&lt;br /&gt;
	EndSwitch&lt;br /&gt;
	Return $GUI_RUNDEFMSG&lt;br /&gt;
EndFunc   ;==&amp;gt;WM_DROPFILES&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ExitCheckTextChange ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 8007-negativenrg&lt;br /&gt;
 | AuthorName = NegativeNrG&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Check(when Exit), if Text is not equal to $e_to Then, prompt the user to save or not save.&lt;br /&gt;
;_ExitCheckText Change $Edit Handle, $title of messagebox, $message of messagebox, $equal to(default = NULL).&lt;br /&gt;
&lt;br /&gt;
Func _ExitCheckTextChange($E_hnd,$title,$message,$e_to = &#039;&#039;)&lt;br /&gt;
	Local $buffer, $choice, $filetosave, $handle1&lt;br /&gt;
                $buffer = GUIctrlread($E_hnd)&lt;br /&gt;
        If $buffer &amp;lt;&amp;gt; $e_to Then&lt;br /&gt;
            $choice = Msgbox(4,$title,$message)&lt;br /&gt;
            If $choice = 6 Then&lt;br /&gt;
                $filetosave = FileSaveDialog(&#039;Choose File&#039;,@scriptdir,&#039;(*.au3)&#039;)&lt;br /&gt;
                $handle1 = FileOpen($filetosave,2)&lt;br /&gt;
                FileWrite($handle1,$buffer)&lt;br /&gt;
                Exit&lt;br /&gt;
            Elseif $choice &amp;lt;&amp;gt; 6 Then&lt;br /&gt;
            Exit&lt;br /&gt;
        EndIf&lt;br /&gt;
        Else&lt;br /&gt;
        Exit&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileDeleteEx ==&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;
; Ref: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;APIFilesConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPIFiles.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_FileDeleteEx(&amp;quot;C:\Example.dat&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _FileDeleteEx($sFilePath)&lt;br /&gt;
    Return FileDelete($sFilePath) = 1 ? 1 : Int(_WinAPI_MoveFileEx(FileGetShortName($sFilePath), &amp;quot;&amp;quot;, $MOVE_FILE_DELAY_UNTIL_REBOOT))&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileDeleteEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileCheck ==&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;Date.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Check if the file was modified less than 24 hours ago.&lt;br /&gt;
ConsoleWrite( _FileCheck(@ScriptFullPath, 24) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _FileCheck($sFilePath, $iHours = 24)&lt;br /&gt;
    Local $aTime&lt;br /&gt;
    If FileExists($sFilePath) = 0 Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aTime = FileGetTime($sFilePath, 0, 0)&lt;br /&gt;
    Return Number(_DateDiff(&amp;quot;h&amp;quot;, $aTime[0] &amp;amp; &amp;quot;/&amp;quot; &amp;amp; $aTime[1] &amp;amp; &amp;quot;/&amp;quot; &amp;amp; $aTime[2] &amp;amp; &amp;quot; &amp;quot; &amp;amp; $aTime[3] &amp;amp; &amp;quot;:&amp;quot; &amp;amp; $aTime[4] &amp;amp; &amp;quot;:&amp;quot; &amp;amp; $aTime[5], @YEAR &amp;amp; &amp;quot;/&amp;quot; &amp;amp; @MON &amp;amp; &amp;quot;/&amp;quot; &amp;amp; @MDAY &amp;amp; &amp;quot; &amp;quot; &amp;amp; @HOUR &amp;amp; &amp;quot;:&amp;quot; &amp;amp; @MIN &amp;amp; &amp;quot;:&amp;quot; &amp;amp; @SEC) &amp;lt; $iHours)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileCheck&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileCreateEx ==&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;
_FileCreateEx(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;, 42)&lt;br /&gt;
&lt;br /&gt;
; Create a blank file with a certain size in bytes.&lt;br /&gt;
Func _FileCreateEx($sFilePath, $iBytes = 0)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c fsutil file createnew &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; Int($iBytes), @WorkingDir, @SW_HIDE)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileCreateEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileID ==&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;
FileClose(FileOpen(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;, 2))&lt;br /&gt;
ConsoleWrite(_FileID(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;) &amp;amp; @CRLF)&lt;br /&gt;
FileDelete(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;)&lt;br /&gt;
&lt;br /&gt;
; Rerieve the file id of a filepath.&lt;br /&gt;
Func _FileID($sFilePath)&lt;br /&gt;
    Local $iPID = Run(@ComSpec &amp;amp; &#039; /c fsutil file queryfileid &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot;&#039;, @SystemDir, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sReturn = &#039;&#039;&lt;br /&gt;
    While 1&lt;br /&gt;
        $sReturn &amp;amp;= StdoutRead($iPID)&lt;br /&gt;
        If @error Then&lt;br /&gt;
            ExitLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
    WEnd&lt;br /&gt;
    Return StringStripWS(StringRegExpReplace($sReturn, &#039;File\sID\sis\s(.*?)&#039;, &#039;$1&#039;), 8)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileExistsWithQuotes ==&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(_FileExistsWithQuotes(&#039;&amp;quot;&#039; &amp;amp; @ScriptDir &amp;amp; &#039;&amp;quot;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_FileExistsWithQuotes(&amp;quot;&#039;&amp;quot; &amp;amp; @ScriptDir &amp;amp; &amp;quot;&#039;&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_FileExistsWithQuotes(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Version: 1.00. AutoIt: V3.3.8.1&lt;br /&gt;
; Check a filepath ecists even if the path contains quotation marks.&lt;br /&gt;
Func _FileExistsWithQuotes($sFilePath)&lt;br /&gt;
    Return FileExists(StringRegExpReplace($sFilePath, &#039;^(&amp;quot;|&#039;&#039;)*([^&amp;quot;&#039;&#039;]+)(&amp;quot;|&#039;&#039;)*$&#039;, &#039;\2&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileExistsWithQuotes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== FileLineCount ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 71214-mkish&lt;br /&gt;
 | AuthorName = MKISH&lt;br /&gt;
 | Desc = Checks the number of lines in a file (useful for larger files as well)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Author - MKISH&lt;br /&gt;
&lt;br /&gt;
; Checks the number of lines in a file (useful for larger files as well)&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local $FILE = &amp;quot;G:\WIN7\sources\boot.wim&amp;quot;&lt;br /&gt;
Local $COUNT = 0&lt;br /&gt;
Local $start = default&lt;br /&gt;
Local $res, $fLen, $err&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
	$res = _HexSearch($FILE, StringToBinary(&amp;quot;&amp;quot; &amp;amp; @crlf), $start)&lt;br /&gt;
	$start = $res + 2&lt;br /&gt;
	$COUNT = $COUNT + 1&lt;br /&gt;
	If $res = -1 then exitloop&lt;br /&gt;
Wend&lt;br /&gt;
&lt;br /&gt;
msgbox(64, &amp;quot;&amp;quot;, &amp;quot;Lines count: &amp;quot; &amp;amp; $COUNT)&lt;br /&gt;
&lt;br /&gt;
; _HexSearch function (originally written by Zinthose, modified by MKISH)&lt;br /&gt;
Func _HexSearch($FilePath, $BinaryValue, $StartOffset = Default)&lt;br /&gt;
        Local $Buffer, $ptr, $hFile, $Result, $Read, $SearchValue, $Pos, $BufferSize = 2048&lt;br /&gt;
            If $StartOffset = Default     Then $StartOffset = 0&lt;br /&gt;
            If Not FileExists($FilePath)    Then    Return SetError(1, @error, 0)&lt;br /&gt;
            $fLen = FileGetSize($FilePath)&lt;br /&gt;
            If $StartOffset &amp;gt; $fLen   Then   Return SetError(2, @error, 0)&lt;br /&gt;
            If Not IsBinary($BinaryValue)   Then    Return SetError(3, @error, 0)&lt;br /&gt;
            If Not IsNumber($StartOffset)   Then    Return SetError(4, @error, 0)&lt;br /&gt;
            $SearchValue = BinaryToString($BinaryValue)&lt;br /&gt;
            $Buffer = DllStructCreate(&amp;quot;byte[&amp;quot; &amp;amp; $BufferSize &amp;amp; &amp;quot;]&amp;quot;)&lt;br /&gt;
            $ptr = DllStructGetPtr($Buffer)&lt;br /&gt;
                $hFile = _WinAPI_CreateFile($FilePath, 2, 2, 1)&lt;br /&gt;
                If $hFile = 0 Then Return SetError(5, @error, 0)&lt;br /&gt;
            $Result = _WinAPI_SetFilePointer($hFile, $StartOffset)&lt;br /&gt;
            $err = @error&lt;br /&gt;
            If $Result = 0xFFFFFFFF Then&lt;br /&gt;
                _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                Return SetError(5, $err, 0)&lt;br /&gt;
            EndIf&lt;br /&gt;
            $Pos = $StartOffset&lt;br /&gt;
            While True&lt;br /&gt;
                    $Read = 0&lt;br /&gt;
                    $Result = _WinAPI_ReadFile($hFile, $ptr, $BufferSize, $Read)&lt;br /&gt;
                    $err = @error&lt;br /&gt;
                    If Not $Result Then&lt;br /&gt;
                        _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                        Return SetError(6, $err, 0)&lt;br /&gt;
                    EndIf&lt;br /&gt;
                    $Result = DllStructGetData($Buffer, 1)&lt;br /&gt;
                    $Result = BinaryToString($Result)&lt;br /&gt;
                    $Result = StringInStr($Result, $SearchValue)&lt;br /&gt;
                    If $Result &amp;gt; 0 Then ExitLoop&lt;br /&gt;
                    If $Read &amp;lt; $BufferSize Then&lt;br /&gt;
                        _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                        Return -1&lt;br /&gt;
                    EndIf&lt;br /&gt;
                    $Pos += $Read&lt;br /&gt;
&lt;br /&gt;
            WEnd&lt;br /&gt;
            _WinAPI_CloseHandle($hFile)&lt;br /&gt;
            If Not $Result Then Return SetError(7, @error, 0)&lt;br /&gt;
            $Result = $Pos + $Result - 1&lt;br /&gt;
            Return $Result&lt;br /&gt;
    EndFunc; ==&amp;gt; _HexSearch&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileOpenDialog ==&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;
Local $sFilePath = _FileOpenDialog(&amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;Images (*.jpg;*.bmp)|Videos (*.avi;*.mpg)&amp;quot;, Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1), 1 + 4, &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;File = &#039; &amp;amp; $sFilePath &amp;amp; &#039;, @error = &#039; &amp;amp; @error &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name ..........: _FileOpenDialog&lt;br /&gt;
; Description ...: Initiates a Open File Dialog with the option to set the position of the GUI.&lt;br /&gt;
; Syntax ........: _FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter[, $iLeft = -1[, $iTop = -1[, $iOptions = 0[,&lt;br /&gt;
;                  $sDefaultName = &amp;quot;&amp;quot;]]]])&lt;br /&gt;
; Parameters ....: $sTitle              - Title text of the Dialog GUI.&lt;br /&gt;
;                  $sIntitialDirectory  - Initial directory selected in the GUI file tree.&lt;br /&gt;
;                  $sFilter             - File type single filter such as &amp;quot;All (*.*)&amp;quot; or &amp;quot;Text files (*.txt)&amp;quot;.&lt;br /&gt;
;                  $iLeft               - [optional] The left side of the dialog box. By default (-1), the window is centered.&lt;br /&gt;
;                  $iTop                - [optional] The top of the dialog box. Default (-1) is centered&lt;br /&gt;
;                  $iOptions            - [optional] Dialog Options: To use more than one option, add the required values together. See FileOpenDialog. Default is 0.&lt;br /&gt;
;                  $sDefaultName        - [optional] Suggested file name for the user to open. Default is blank (&amp;quot;&amp;quot;).&lt;br /&gt;
; Return values .: Success: Returns the full path of the file(s) chosen. Results for multiple selections are &amp;quot;Directory|file1|file2|...&amp;quot;&lt;br /&gt;
;                  Failure: Sets @error to non-zero.&lt;br /&gt;
; Author ........: guinness&lt;br /&gt;
; Remarks........: This doesn&#039;t change the working directory of the script like FileOpenDialog does.&lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter, $iLeft = -1, $iTop = -1, $iOptions = 0, $sDefaultName = &amp;quot;&amp;quot;)&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;, -1, -1, $iLeft, $iTop), $sWorkingDir = @WorkingDir&lt;br /&gt;
    Local $sFilePath = FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter, $iOptions, $sDefaultName, $hGUI)&lt;br /&gt;
    Local $iError = @error&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return SetError($iError, GUIDelete($hGUI), $sFilePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileOpenDialog()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileRename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 52374-johnone&lt;br /&gt;
 | AuthorName = JohnOne&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;### Rename a file ###&lt;br /&gt;
;$sFile = Full path to file&lt;br /&gt;
;$sRename = New Filename&lt;br /&gt;
;$iOverWrite = 0 or 1&lt;br /&gt;
&lt;br /&gt;
;Success returns 1&lt;br /&gt;
;failure, returns 0 and sets @error&lt;br /&gt;
; 1 if FileMove fails, &lt;br /&gt;
; 2 if $sFile does not exist&lt;br /&gt;
;@extended&lt;br /&gt;
; 0 if the new file does not already exist / existed&lt;br /&gt;
; 1 if the new file already exists / existed&lt;br /&gt;
&lt;br /&gt;
;#### Example ####&lt;br /&gt;
$File = @ScriptDir &amp;amp; &#039;\filetorename.txt&#039;&lt;br /&gt;
FileWrite($File, &#039;Test&#039;)&lt;br /&gt;
_FileRename($File, &#039;newname.txt&#039;)&lt;br /&gt;
If @error Then MsgBox(0, &amp;quot;Error&amp;quot;, @error)&lt;br /&gt;
&lt;br /&gt;
Func _FileRename($sFile, $sRename, $iOverWrite = 0)&lt;br /&gt;
    Local Const $FILENOTEXIST = 2&lt;br /&gt;
    If Not FileExists($sFile) Then Return SetError($FILENOTEXIST, 0, 0)&lt;br /&gt;
    Local $_StringLen = StringLen($sFile)&lt;br /&gt;
    Local $_StringInStr = StringInStr($sFile, &amp;quot;\&amp;quot;, 0, -1, $_StringLen)&lt;br /&gt;
    Local $_Count = $_StringLen - $_StringInStr&lt;br /&gt;
    Local $_Dir = StringLeft($sFile, $_StringInStr)&lt;br /&gt;
    Local $_NewFile = $_Dir &amp;amp; $sRename&lt;br /&gt;
    Local $_NewFileExists = FileExists($_NewFile)&lt;br /&gt;
    Local $_FileMove = FileMove($sFile, $_NewFile, $iOverWrite)&lt;br /&gt;
    Return SetError(Not $_FileMove, $_NewFileExists, $_FileMove)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileRename&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== _FileRename Alternative ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;FileRename(PathFile, RenameFile)&lt;br /&gt;
;JohnOne&lt;br /&gt;
&lt;br /&gt;
FileRename(@ScriptDir &amp;amp; &amp;quot;\rename.txt&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\renamed.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func FileRename($FileName, $ReName)&lt;br /&gt;
&lt;br /&gt;
	Local $SHFILEOPSTRUCT, $SourceStruct, $DestStruct&lt;br /&gt;
	Local Const $FO_RENAME = 0x0004&lt;br /&gt;
	Local Const $FOF_SILENT = 0x0004&lt;br /&gt;
	Local Const $FOF_NOCONFIRMATION = 0x0010&lt;br /&gt;
	Local Const $FOF_NOERRORUI = 0x0400&lt;br /&gt;
	Local Const $FOF_NOCONFIRMMKDIR = 0x0200&lt;br /&gt;
	Local Const $NULL = 0&lt;br /&gt;
&lt;br /&gt;
	$SourceStruct = _StringToStruct($FileName)&lt;br /&gt;
	$DestStruct = _StringToStruct($ReName)&lt;br /&gt;
&lt;br /&gt;
	$SHFILEOPSTRUCT = DllStructCreate(&amp;quot;hwnd hWnd;uint wFunc;ptr pFrom;ptr pTo;int fFlags;int fAnyOperationsAborted;ptr hNameMappings;ptr lpszProgressTitle&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;hWnd&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;wFunc&amp;quot;, $FO_RENAME)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;pFrom&amp;quot;, DllStructGetPtr($SourceStruct))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;pTo&amp;quot;, DllStructGetPtr($DestStruct))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;fFlags&amp;quot;, BitOR($FOF_SILENT, $FOF_NOCONFIRMATION, $FOF_NOERRORUI, $FOF_NOCONFIRMMKDIR))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;fAnyOperationsAborted&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;hNameMappings&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;lpszProgressTitle&amp;quot;, $NULL)&lt;br /&gt;
&lt;br /&gt;
	$acall = DllCall(&amp;quot;shell32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;SHFileOperation&amp;quot;, &amp;quot;ptr&amp;quot;, DllStructGetPtr($SHFILEOPSTRUCT))&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Return SetError(@error, @extended, 0)&lt;br /&gt;
	EndIf&lt;br /&gt;
	Return 1&lt;br /&gt;
EndFunc   ;==&amp;gt;FileRename&lt;br /&gt;
&lt;br /&gt;
Func _StringToStruct($string)&lt;br /&gt;
&lt;br /&gt;
	Local $iLen = StringLen($string)&lt;br /&gt;
	Local $Struct = DllStructCreate(&amp;quot;char[&amp;quot; &amp;amp; String($iLen + 2) &amp;amp; &amp;quot;]&amp;quot;)&lt;br /&gt;
	DllStructSetData($Struct, 1, $string)&lt;br /&gt;
	DllStructSetData($Struct, 1, 0, $iLen + 1)&lt;br /&gt;
	DllStructSetData($Struct, 1, 0, $iLen + 2)&lt;br /&gt;
&lt;br /&gt;
	Return $Struct&lt;br /&gt;
EndFunc   ;==&amp;gt;_StringToStruct&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFolderDepth ==&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;
; Autoit 3.3.5.4 and Below&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir &amp;amp; &#039;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the folder depth of a filepath.&lt;br /&gt;
Func _GetFolderDepth($sFilePath)&lt;br /&gt;
    If StringInStr($sFilePath, &#039;.&#039;, 2, -1) Then&lt;br /&gt;
        $sFilePath = StringLeft($sFilePath, StringInStr($sFilePath, &amp;quot;&amp;quot;, 2, -1) - 1)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $aArray = StringSplit(StringRegExpReplace($sFilePath, &#039;[/]+z&#039;, &#039;&#039;), &#039;&#039;)&lt;br /&gt;
    Return $aArray[0] - 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFolderDepth&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFolderDepth ==&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;
; Autoit 3.3.5.4 and Above&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir &amp;amp; &#039;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the folder depth of a filepath. Works with V3.3.5.4+&lt;br /&gt;
Func _GetFolderDepth($sFilePath)&lt;br /&gt;
    If StringInStr($sFilePath, &#039;.&#039;, 2, -1) Then&lt;br /&gt;
        $sFilePath = StringLeft($sFilePath, StringInStr($sFilePath, &amp;quot;&amp;quot;, 2, -1) - 1)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return StringSplit(StringRegExpReplace($sFilePath, &#039;[/]+z&#039;, &#039;&#039;), &#039;&#039;)[0] - 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFolderDepth&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsDir ==&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;IsDir: Using a file - &amp;quot; &amp;amp; IsDir(@ScriptFullPath) &amp;amp; @CRLF) ; Return 0&lt;br /&gt;
ConsoleWrite(&amp;quot;IsDir: Using a directory - &amp;quot; &amp;amp; IsDir(@ScriptDir) &amp;amp; @CRLF) ; Return 1&lt;br /&gt;
&lt;br /&gt;
Func IsDir($sFilePath)&lt;br /&gt;
	Return Int(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), &#039;D&#039;, Default, 1) &amp;gt; 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;IsDir&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFile ==&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(&#039;IsFile: Using a file - &#039; &amp;amp; IsFile(@ScriptFullPath) &amp;amp; @CRLF) ; Return 1&lt;br /&gt;
ConsoleWrite(&#039;IsFile: Using a directory - &#039; &amp;amp; IsFile(@ScriptDir) &amp;amp; @CRLF) ; Return 0&lt;br /&gt;
&lt;br /&gt;
Func IsFile($sFilePath)&lt;br /&gt;
	Return Int(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), &#039;D&#039;, Default, 1) = 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;IsFilee&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileDiff ==&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(_IsFileDiff(@ScriptFullPath, @ScriptFullPath) &amp;amp; @CRLF) ; This will return False as the files are exactly the same.&lt;br /&gt;
ConsoleWrite(_IsFileDiff(@ScriptFullPath, @AutoItExe) &amp;amp; @CRLF) ; This will return True as the files are different.&lt;br /&gt;
&lt;br /&gt;
; Check if a file is different.&lt;br /&gt;
Func _IsFileDiff($sFilePath_1, $sFilePath_2)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c FC /B /W &amp;quot;&#039; &amp;amp; $sFilePath_1 &amp;amp; &#039;&amp;quot; &amp;quot;&#039; &amp;amp; $sFilePath_2 &amp;amp; &#039;&amp;quot;&#039;, @WorkingDir, @SW_HIDE) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileDiff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileOlder ==&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;Date.au3&amp;gt; ; Required for _DateDiff()&lt;br /&gt;
&lt;br /&gt;
; Check if the current script is older than 10 days.&lt;br /&gt;
If _IsFileOlder(@ScriptFullPath, 10) Then&lt;br /&gt;
	MsgBox(4096, &#039;&#039;, &#039;File is older than 10 days.&#039;)&lt;br /&gt;
Else&lt;br /&gt;
	MsgBox(4096, &#039;&#039;, &#039;File isn&#039;&#039;t older than 10 days.&#039;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
; Is a file older than a certain number of days.&lt;br /&gt;
Func _IsFileOlder($sFilePath, $iDays)&lt;br /&gt;
	Local $aArray = FileGetTime($sFilePath, 0)&lt;br /&gt;
	Return _DateDiff(&#039;D&#039;, $aArray[0] &amp;amp; &#039;/&#039; &amp;amp; $aArray[1] &amp;amp; &#039;/&#039; &amp;amp; $aArray[2] &amp;amp; &#039; &#039; &amp;amp; $aArray[3] &amp;amp; &#039;:&#039; &amp;amp; $aArray[4] &amp;amp; &#039;:&#039; &amp;amp; $aArray[5], @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) &amp;gt;= $iDays&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileOlder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileSame ==&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(_IsFileSame(@ScriptFullPath, @ScriptFullPath) &amp;amp; @CRLF) ; This will return True as the files are exactly the same.&lt;br /&gt;
ConsoleWrite(_IsFileSame(@ScriptFullPath, @AutoItExe) &amp;amp; @CRLF) ; This will return False as the files are different.&lt;br /&gt;
&lt;br /&gt;
; Check if a file is the same.&lt;br /&gt;
Func _IsFileSame($sFilePath_1, $sFilePath_2)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c FC /B /W &amp;quot;&#039; &amp;amp; $sFilePath_1 &amp;amp; &#039;&amp;quot; &amp;quot;&#039; &amp;amp; $sFilePath_2 &amp;amp; &#039;&amp;quot;&#039;, @WorkingDir, @SW_HIDE) = 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileSame&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IniReadFile ==&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;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__INIFileFill(@ScriptDir &amp;amp; &#039;\Example.ini&#039;) ; Create an INI file with random data.&lt;br /&gt;
&lt;br /&gt;
Local $aArray = _IniReadFile(@ScriptDir &amp;amp; &#039;\Example.ini&#039;)&lt;br /&gt;
FileDelete(@ScriptDir &amp;amp; &#039;\Example.ini&#039;)&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&lt;br /&gt;
Func _IniReadFile($sFilePath)&lt;br /&gt;
    Local $aReturn[1][3] = [[0, 3]], $aSectionArray, $aSectionNameArray, $iCount = 0&lt;br /&gt;
    $aSectionNameArray = IniReadSectionNames($sFilePath)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $aReturn)&lt;br /&gt;
    EndIf&lt;br /&gt;
    For $A = 1 To $aSectionNameArray[0]&lt;br /&gt;
        $aSectionArray = IniReadSection($sFilePath, $aSectionNameArray[$A])&lt;br /&gt;
        If @error Then&lt;br /&gt;
            ContinueLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
        For $B = 1 To $aSectionArray[0][0]&lt;br /&gt;
            $aReturn[0][0] += 1&lt;br /&gt;
            $iCount += 1&lt;br /&gt;
            If $aReturn[0][0] &amp;lt;= $iCount + 1 Then&lt;br /&gt;
                ReDim $aReturn[$aReturn[0][0] * 2][$aReturn[0][1]]&lt;br /&gt;
            EndIf&lt;br /&gt;
            $aReturn[$iCount][0] = $aSectionArray[$B][0]&lt;br /&gt;
            $aReturn[$iCount][1] = $aSectionArray[$B][1]&lt;br /&gt;
            $aReturn[$iCount][2] = $aSectionNameArray[$A]&lt;br /&gt;
        Next&lt;br /&gt;
    Next&lt;br /&gt;
    ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1]] ; Remove empty entries.&lt;br /&gt;
    Return $aReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_IniReadFile&lt;br /&gt;
&lt;br /&gt;
Func __INIFileFill($sFilePath)&lt;br /&gt;
    Local $sData = &#039;&#039;, $sHeader = &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To Random(1, 5, 1)&lt;br /&gt;
        $sHeader = _RandomText(Random(5, 25, 1))&lt;br /&gt;
        $sData = &amp;quot;&amp;quot;&lt;br /&gt;
        For $j = 1 To Random(1, 25, 1)&lt;br /&gt;
            $sData &amp;amp;= _RandomText(Random(5, 25, 1)) &amp;amp; &#039;=&#039; &amp;amp; _RandomText(Random(5, 25, 1)) &amp;amp; @LF&lt;br /&gt;
        Next&lt;br /&gt;
        IniWriteSection($sFilePath, $sHeader, $sData)&lt;br /&gt;
    Next&lt;br /&gt;
EndFunc   ;==&amp;gt;__FillINIFile&lt;br /&gt;
&lt;br /&gt;
Func _RandomText($iLength = 10)&lt;br /&gt;
    Local $sData = &#039;&#039;, $sRandom = &#039;&#039;&lt;br /&gt;
    For $i = 1 To $iLength&lt;br /&gt;
        $sRandom = Random(55, 116, 1)&lt;br /&gt;
        $sData &amp;amp;= Chr($sRandom + 6 * ($sRandom &amp;gt; 90) - 7 * ($sRandom &amp;lt; 65))&lt;br /&gt;
    Next&lt;br /&gt;
    Return $sData&lt;br /&gt;
EndFunc   ;==&amp;gt;_RandomText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IniReadInit ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 9370-mlowery&lt;br /&gt;
 | AuthorName = mlowery&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;===============================================================================&lt;br /&gt;
; Description:     Reads values from INI or creates INI with initial values.&lt;br /&gt;
;                  Intended to ensure all available INI settings are exposed&lt;br /&gt;
;                  and editable.&lt;br /&gt;
;                  Parameters are identical to IniRead()&lt;br /&gt;
; Parameter(s):    $filename  = filename of INI&lt;br /&gt;
;                  $section  = section name of INI&lt;br /&gt;
;                  $key      = key name in section&lt;br /&gt;
;                  $default  = default value (written to INI if not exists)&lt;br /&gt;
; Requirement(s):  None&lt;br /&gt;
; Return Value(s): Returns value from INI (or default if not defined)&lt;br /&gt;
; Note(s):         Chr(127) used to detect non-existing value since won&#039;t normally exist in a text file&lt;br /&gt;
;===============================================================================&lt;br /&gt;
Func _IniReadInit($filename, $section, $key, $default)&lt;br /&gt;
  Local $value = IniRead($filename, $section, $key, Chr(127))&lt;br /&gt;
    If $value = Chr(127) Then&lt;br /&gt;
      IniWrite($filename, $section, $key, $default)&lt;br /&gt;
      $value = $default&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $value&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsValidFileType ==&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(@ScriptFullPath &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@ScriptFullPath, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(@AutoItExe &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@AutoItExe, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a filepath matches an extension filetype. Based on the idea by guinness - http://www.autoitscript.com/forum/topic/123674-isvalidfiletype/&lt;br /&gt;
Func _IsValidFileType($sFilePath, $sList = &amp;quot;bat;cmd;exe&amp;quot;) ; By AZJIO - http://www.autoitscript.com/forum/topic/...filetype/page__view__findpost_&lt;br /&gt;
    Local $iDot = StringInStr($sFilePath, &amp;quot;.&amp;quot;, 0, -1)&lt;br /&gt;
    Return $iDot And StringInStr(&#039;;&#039; &amp;amp; $sList &amp;amp; &#039;;&#039;, &#039;;&#039; &amp;amp; StringTrimLeft($sFilePath, $iDot) &amp;amp; &#039;;&#039;) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsValidFileType&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;
; Example 2&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(@ScriptFullPath &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@ScriptFullPath, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(@AutoItExe &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@AutoItExe, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a filepath matches an extension filetype. Based on the idea by guinness - http://www.autoitscript.com/forum/topic/123674-isvalidfiletype/&lt;br /&gt;
Func _IsValidFileType($sFilePath, $sList = &amp;quot;bat;cmd;exe&amp;quot;, $iOpFast = 1) ; By Yashied.&lt;br /&gt;
    If StringStripWS($sList, 8) = &amp;quot;&amp;quot; Then&lt;br /&gt;
        $sList = &amp;quot;*&amp;quot;&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return _WinAPI_PathMatchSpec($sFilePath, StringReplace(&#039;;&#039; &amp;amp; $sList, &#039;;&#039;, &#039;;*.&#039;, 0, $iOpFast * 2))&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsValidFileType&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== File Open/Save/Folder Dialog Box ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 2709-mhz&lt;br /&gt;
 | AuthorName = MHz&lt;br /&gt;
 | AuthorURL2 = 4997-odklizec&lt;br /&gt;
 | AuthorName2 = odklizec&lt;br /&gt;
 | AuthorURL3 = 6756-danny35d&lt;br /&gt;
 | AuthorName3 = Danny35d&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Center - File Open/Save/Folder Dialog Box&lt;br /&gt;
; Author - odklizec, MHz, Danny35d&lt;br /&gt;
&lt;br /&gt;
 If StringInStr($cmdlineraw, &#039;/MoveWin&#039;) Then&lt;br /&gt;
	 Local $size, $PosX, $PosY&lt;br /&gt;
     $cmdlineraw = StringSplit(StringMid($cmdlineraw, StringInStr($cmdlineraw, &#039;/MoveWin&#039;)), &#039;:&#039;)&lt;br /&gt;
     While 1&lt;br /&gt;
         Select&lt;br /&gt;
         Case WinExists($cmdlineraw[2])&lt;br /&gt;
             $size=WinGetPos ($cmdlineraw[2])&lt;br /&gt;
             $PosX=@DesktopWidth/2 - $size[2]/2&lt;br /&gt;
             $PosY=@DesktopHeight/2 - $size[3]/2&lt;br /&gt;
             WinMove($cmdlineraw[2], &amp;quot;&amp;quot;, $PosX, $PosY)&lt;br /&gt;
             WinActivate($cmdlineraw[2])&lt;br /&gt;
             ExitLoop&lt;br /&gt;
         EndSelect&lt;br /&gt;
         Sleep(50)&lt;br /&gt;
     WEnd&lt;br /&gt;
     Exit&lt;br /&gt;
 EndIf&lt;br /&gt;
Global $PID, $Read_File, $Save_File&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Open file Dialog Box&#039;)&lt;br /&gt;
 $Read_File = FileOpenDialog ( &amp;quot;Open file Dialog Box&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\&amp;quot;, &amp;quot;AutoIt Files (*.au3)&amp;quot;,3,@ScriptFullPath)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Save file Dialog Box&#039;)&lt;br /&gt;
 $Save_File = FileSaveDialog( &amp;quot;Save file Dialog Box&amp;quot;, @ScriptDir, &amp;quot;Scripts (*.aut;*.au3)&amp;quot;, 3)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Browse for Folder&#039;)&lt;br /&gt;
 FileSelectFolder(&amp;quot;Choose a folder with plugins..&amp;quot;, &amp;quot;&amp;quot;,&amp;quot;4&amp;quot;,&amp;quot;c:\&amp;quot;)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
&lt;br /&gt;
 Func _FindBrowseWin($sTitle)&lt;br /&gt;
     If @Compiled Then&lt;br /&gt;
         Return(Run(@ScriptFullPath &amp;amp; &#039; /MoveWin:&#039; &amp;amp; $sTitle))&lt;br /&gt;
     Else&lt;br /&gt;
         Return(Run(@AutoItExe &amp;amp; &#039; &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot; /MoveWin:&#039; &amp;amp; $sTitle))&lt;br /&gt;
     EndIf&lt;br /&gt;
 EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _MoveFileOnReboot ==&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.2.0, Creation Date = 21/03/12.&lt;br /&gt;
&lt;br /&gt;
; Function to Move or Delete a file on next reboot!&lt;br /&gt;
Func _MoveFileOnReboot($sSourcePath, $sDestPath = &amp;quot;&amp;quot;); If $sDestPath = &amp;quot;&amp;quot; the file is deleted instead of moved.&lt;br /&gt;
    Local $iRet&lt;br /&gt;
&lt;br /&gt;
    ; PendingFileRenameOperations (HKLM\SYSTEM\CurrentControlSet\Control\Session Manager)&lt;br /&gt;
    If $DestPath = &amp;quot;&amp;quot; Then&lt;br /&gt;
        $iRet = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;MoveFileExA&amp;quot;, &amp;quot;str&amp;quot;, $sSourcePath, &amp;quot;int&amp;quot;, 0, &amp;quot;dword&amp;quot;, 4)&lt;br /&gt;
    Else&lt;br /&gt;
        $iRet = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;MoveFileExA&amp;quot;, &amp;quot;str&amp;quot;, $sSourcePath, &amp;quot;str&amp;quot;, $sDestPath, &amp;quot;dword&amp;quot;, 4)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return $iRet&lt;br /&gt;
EndFunc   ;==&amp;gt;_MoveFileOnReboot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _MultipleFileOpenDialog ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL =&lt;br /&gt;
 | AuthorName = /dev/null&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Local $message = &amp;quot;Hold down Ctrl or Shift to choose multiple files.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Local $filename = _MultipleFileOpenDialog($message,300,300)&lt;br /&gt;
&lt;br /&gt;
Local $var = FileOpenDialog($message, @WindowsDir &amp;amp; &amp;quot;\&amp;quot;, &amp;quot;Images (*.jpg;*.bmp)&amp;quot;, 1 + 4 )&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    MsgBox(4096,&amp;quot;&amp;quot;,&amp;quot;No File(s) chosen&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
    $var = StringReplace($var, &amp;quot;|&amp;quot;, @CRLF)&lt;br /&gt;
    MsgBox(4096,&amp;quot;&amp;quot;,&amp;quot;You chose &amp;quot; &amp;amp; $var)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
FileDelete($filename)&lt;br /&gt;
func _MultipleFileOpenDialog($title,$posx,$posy)&lt;br /&gt;
    Local $temp = EnvGet(&amp;quot;temp&amp;quot;)&lt;br /&gt;
    Local $filename = $temp &amp;amp; &amp;quot;\move_file_open_dialog.au3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    Local $script = &#039;Global $title = &amp;quot;&#039; &amp;amp; $title &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Global $pos_x = &#039; &amp;amp; $posx &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Global $pos_y = &#039; &amp;amp; $posy &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;AdlibRegister(&amp;quot;_Move&amp;quot;,10)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;while 1&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;    sleep(1000)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;wend&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Func _Move()&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;   if (WinActive($title)) Then&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;      WinMove($title,&amp;quot;&amp;quot;,$pos_x,$pos_y)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;      Exit&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;   EndIf&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;EndFunc&#039; &amp;amp; @CRLF&lt;br /&gt;
&lt;br /&gt;
    FileWrite($filename,$script)&lt;br /&gt;
    ;MsgBox(0,&amp;quot;&amp;quot;,$script &amp;amp; @CRLF &amp;amp; $filename)&lt;br /&gt;
    Run(@AutoItExe &amp;amp; &amp;quot; /AutoIt3ExecuteScript &amp;quot; &amp;amp; $filename)&lt;br /&gt;
    sleep(250)&lt;br /&gt;
    Return $filename&lt;br /&gt;
EndFunc ;==&amp;gt;_MultipleFileOpenDialog()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _OpenFolder ==&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;
#cs&lt;br /&gt;
    These have been declared in Global scope as you may wish to use them elsewhere in your script.&lt;br /&gt;
#ce&lt;br /&gt;
Global $ALTSTARTUP = 0x1d&lt;br /&gt;
Global $APPDATA = 0x1a&lt;br /&gt;
Global $BITBUCKET = 0x0a&lt;br /&gt;
Global $COMMONALTSTARTUP = 0x1e&lt;br /&gt;
Global $COMMONAPPDATA = 0x23&lt;br /&gt;
Global $COMMONDESKTOPDIR = 0x19&lt;br /&gt;
Global $COMMONFAVORITES = 0x1f&lt;br /&gt;
Global $COMMONPROGRAMS = 0x17&lt;br /&gt;
Global $COMMONSTARTMENU = 0x16&lt;br /&gt;
Global $COMMONSTARTUP = 0x18&lt;br /&gt;
Global $CONTROLS = 0x03&lt;br /&gt;
Global $COOKIES = 0x21&lt;br /&gt;
Global $DESKTOP = 0x00&lt;br /&gt;
Global $DESKTOPDIRECTORY = 0x10&lt;br /&gt;
Global $DRIVES = 0x11&lt;br /&gt;
Global $FAVORITES = 0x06&lt;br /&gt;
Global $FONTS = 0x14&lt;br /&gt;
Global $HISTORY = 0x22&lt;br /&gt;
Global $INTERNETCACHE = 0x20&lt;br /&gt;
Global $LOCALAPPDATA = 0x1c&lt;br /&gt;
Global $MYPICTURES = 0x27&lt;br /&gt;
Global $NETHOOD = 0x13&lt;br /&gt;
Global $NETWORK = 0x12&lt;br /&gt;
Global $PERSONAL = 0x05&lt;br /&gt;
Global $PRINTERS = 0x04&lt;br /&gt;
Global $PRINTHOOD = 0x1b&lt;br /&gt;
Global $PROFILE = 0x28&lt;br /&gt;
Global $PROGRAMFILES = 0x26&lt;br /&gt;
Global $PROGRAMFILESx86 = 0x30&lt;br /&gt;
Global $PROGRAMS = 0x02&lt;br /&gt;
Global $RECENT = 0x08&lt;br /&gt;
Global $SENDTO = 0x09&lt;br /&gt;
Global $STARTMENU = 0x0b&lt;br /&gt;
Global $STARTUP = 0x07&lt;br /&gt;
Global $SYSTEM = 0x25&lt;br /&gt;
Global $SYSTEMx86 = 0x29&lt;br /&gt;
Global $TEMPLATES = 0x15&lt;br /&gt;
Global $WINDOWS = 0x24&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_OpenFolder(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_OpenFolder($PRINTERS) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Open a folder or special folder variable, similar to using ShellExecute.&lt;br /&gt;
Func _OpenFolder($sFolderPath)&lt;br /&gt;
    Local $oShell = ObjCreate(&#039;shell.application&#039;)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $oShell.Open($sFolderPath)&lt;br /&gt;
    Return 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_OpenFolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _PathAppendToFilename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 31965-progandy&lt;br /&gt;
 | AuthorName = ProgAndy&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
$sOrg = &amp;quot;C:\Some.Folder\some.file.ext&amp;quot;&lt;br /&gt;
$sAdd = &amp;quot;_backup&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$sNew = _PathAppendToFilename($sOrg, $sAdd)&lt;br /&gt;
&lt;br /&gt;
$sStripped = _PathStripRightFromFilename($sNew, $sAdd)&lt;br /&gt;
&lt;br /&gt;
MsgBox(0, &amp;quot;&amp;quot;, $sOrg &amp;amp; @CRLF &amp;amp; $sAdd &amp;amp; @CRLF &amp;amp; $sNew &amp;amp; @CRLF &amp;amp; $sStripped)&lt;br /&gt;
&lt;br /&gt;
Func _PathAppendToFilename($sName, $sAppend)&lt;br /&gt;
    ; Author: ProgAndy&lt;br /&gt;
    If StringRegExp($sAppend, &#039;[\/\\:\?&amp;quot;&amp;lt;&amp;gt;\|\*]&#039;) Then Return SetError(1, 0, $sName)&lt;br /&gt;
    Return StringRegExpReplace($sName, &amp;quot;(\.[^\\/\.]+)$&amp;quot;, $sAppend &amp;amp; &amp;quot;\1&amp;quot;, 1)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _PathStripRightFromFilename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 31965-progandy&lt;br /&gt;
 | AuthorName = ProgAndy&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Func _PathStripRightFromFilename($sName, $sStrip)&lt;br /&gt;
    ; Author: ProgAndy&lt;br /&gt;
    If StringRegExp($sStrip, &#039;[\/\\:\?&amp;quot;&amp;lt;&amp;gt;\|\*]&#039;) Then Return SetError(1, 0, $sName)&lt;br /&gt;
    Return StringRegExpReplace($sName, &amp;quot;\Q&amp;quot; &amp;amp; $sStrip &amp;amp; &amp;quot;\E(\.[^\\/\.]+)$&amp;quot;, &amp;quot;\1&amp;quot;, 1)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SelfDelete ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 2709-mhz&lt;br /&gt;
 | AuthorName = MHz&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; This also removes the directory which the file is in&lt;br /&gt;
; Author MHz with the directory delete addition by The Kandie Man&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;:loop2&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;rmdir /q &amp;quot;&#039; &amp;amp; $dirToDelete &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;if exist &amp;quot;&#039; &amp;amp; $dirToDelete &amp;amp; &#039;&amp;quot; goto loop2&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;del &#039; &amp;amp; @TempDir &amp;amp; &#039;\scratch.bat&#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&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ShellExecuteFileSelectFolder ==&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(_ShellExecuteFileSelectFolder(&#039;Select a Folder&#039;, @HomeDrive) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Shell Execute a selected folder.&lt;br /&gt;
Func _ShellExecuteFileSelectFolder($sText, $sRoot, $iFlag = 0, $sInitialDir = &#039;&#039;, $hWnd = &#039;&#039;)&lt;br /&gt;
    Local $sFolder = FileSelectFolder($sText, $sRoot, $iFlag, $sInitialDir, $hWnd)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(@error, @extended, &#039;&#039;)&lt;br /&gt;
    EndIf&lt;br /&gt;
    ShellExecute($sFolder)&lt;br /&gt;
    Return $sFolder&lt;br /&gt;
EndFunc   ;==&amp;gt;_ShellExecuteFileSelectFolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SuiCide ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 28010-larrydalooza&lt;br /&gt;
 | AuthorName = LarryDalooza&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; IMPORTANT MAKE A COPY OF SCRIPT BEFORE DELETION&lt;br /&gt;
; Deletes the running script&lt;br /&gt;
&lt;br /&gt;
Func SuiCide()&lt;br /&gt;
	Local $sFilePath = @TempDir &amp;amp; &#039;\SuiCide.bat&#039;&lt;br /&gt;
	FileDelete($sFilePath)&lt;br /&gt;
	FileWrite($sFilePath, &#039;loop:&#039; &amp;amp; @CRLF &amp;amp; &#039;del &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
			&#039;ping -n 1 -w 250 zxywqxz_q&#039; &amp;amp; @CRLF &amp;amp; &#039;if exist &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; _&lt;br /&gt;
			&#039;&amp;quot; goto loop&#039; &amp;amp; @CRLF &amp;amp; &#039;del SuiCide.bat&#039; &amp;amp; @CRLF)&lt;br /&gt;
	Exit Run($sFilePath, @TempDir, @SW_HIDE)&lt;br /&gt;
EndFunc   ;==&amp;gt;SuiCide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _UniqueFilename ==&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;
&lt;br /&gt;
ConsoleWrite(_UniqueFilename(@ScriptDir, &#039;.au3&#039;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _UniqueFilename($sFilePath, $sExtension)&lt;br /&gt;
    Local $iRandom = 0, $sUnqiueFileName = &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
    $sExtension = &#039;.&#039; &amp;amp; StringRegExpReplace($sExtension, &#039;\A[\.]+&#039;, &#039;&#039;)&lt;br /&gt;
    $sFilePath = StringRegExpReplace($sFilePath, &#039;[\\/]+\z&#039;, &#039;&#039;) &amp;amp; &#039;\&#039;&lt;br /&gt;
    While 1&lt;br /&gt;
        $iRandom = Random(55, 116, 1)&lt;br /&gt;
        $sUnqiueFileName &amp;amp;= Chr($iRandom + 6 * ($iRandom &amp;gt; 90) - 7 * ($iRandom &amp;lt; 65))&lt;br /&gt;
        If FileExists($sFilePath &amp;amp; $sUnqiueFileName &amp;amp; $sExtension) = 0 And StringLen($sUnqiueFileName) &amp;gt; 7 Then&lt;br /&gt;
            ExitLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
    WEnd&lt;br /&gt;
    Return $sFilePath &amp;amp; $sUnqiueFileName &amp;amp; $sExtension&lt;br /&gt;
EndFunc   ;==&amp;gt;_UniqueFilename&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Windows - Copy With Progress ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 19-jos&lt;br /&gt;
 | AuthorName = Jos&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Windows - Copy With Progress&lt;br /&gt;
&lt;br /&gt;
;~ 4 Do not display a progress dialog box.&lt;br /&gt;
;~ 8 Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.&lt;br /&gt;
;~ 16 Respond with &amp;quot;Yes to All&amp;quot; for any dialog box that is displayed.&lt;br /&gt;
;~ 64 Preserve undo information, if possible.&lt;br /&gt;
;~ 128 Perform the operation on files only if a wildcard file name (*.*) is specified.&lt;br /&gt;
;~ 256 Display a progress dialog box but do not show the file names.&lt;br /&gt;
;~ 512 Do not confirm the creation of a new directory if the operation requires one to be created.&lt;br /&gt;
;~ 1024 Do not display a user interface if an error occurs.&lt;br /&gt;
;~ 2048 Version 4.71. Do not copy the security attributes of the file.&lt;br /&gt;
;~ 4096 Only operate in the local directory. Don&#039;t operate recursively into subdirectories.&lt;br /&gt;
;~ 8192 Version 5.0. Do not copy connected files as a group. Only copy the specified files.&lt;br /&gt;
&lt;br /&gt;
_FileCopy(&amp;quot;C:\Installed Apps\Patches\WindowsXP-KB835935-SP2-ENU.exe&amp;quot;,&amp;quot;C:\temp&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
; to copy a directory the destination directory must exist&lt;br /&gt;
&lt;br /&gt;
Func _FileCopy($fromFile,$tofile)&lt;br /&gt;
    Local $FOF_RESPOND_YES = 16&lt;br /&gt;
    Local $FOF_SIMPLEPROGRESS = 256&lt;br /&gt;
    $winShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
    $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_Files_%26_Folders_)&amp;diff=12407</id>
		<title>Snippets ( Files &amp; Folders )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_Files_%26_Folders_)&amp;diff=12407"/>
		<updated>2014-05-12T19:33:33Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* _IsDir */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
[[category:Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Snippet Credit Header}}&lt;br /&gt;
&lt;br /&gt;
== _ConvertFileToUTF16 ==&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;
_ConvertFileToUTF16(@ScriptDir &amp;amp; &amp;quot;\Example.xml&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _ConvertFileToUTF16($sFilePath)&lt;br /&gt;
    Local $iEncoding = FileGetEncoding($sFilePath)&lt;br /&gt;
    Local $hFileOpen = FileOpen($sFilePath, $iEncoding)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $sData = FileRead($hFileOpen)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
&lt;br /&gt;
    $hFileOpen = FileOpen($sFilePath, 2 + 32)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(2, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    FileWrite($hFileOpen, $sData)&lt;br /&gt;
    Return FileClose($hFileOpen)&lt;br /&gt;
EndFunc   ;==&amp;gt;_ConvertFileToUTF16&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== DropFiles ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 35302-guinness&lt;br /&gt;
 | AuthorName = guinness&lt;br /&gt;
 | Desc = Dropping multiple files onto a GUI&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Dropping multiple files onto a GUI&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;APIConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $__aDropFiles&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
	Local $hGUI = GUICreate(&#039;&#039;, 500, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)&lt;br /&gt;
&lt;br /&gt;
	; Create a label that is transparent which will accept &#039;drop&#039; events.&lt;br /&gt;
	GUICtrlCreateLabel(&amp;quot;&amp;quot;, 0, 0, 500, 500)&lt;br /&gt;
	GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)&lt;br /&gt;
	GUICtrlSetResizing(-1, $GUI_DOCKALL)&lt;br /&gt;
	GUICtrlSetState(-1, $GUI_DROPACCEPTED)&lt;br /&gt;
&lt;br /&gt;
	GUIRegisterMsg($WM_DROPFILES, &amp;quot;WM_DROPFILES&amp;quot;)&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&lt;br /&gt;
				ExitLoop&lt;br /&gt;
&lt;br /&gt;
			Case $GUI_EVENT_DROPPED&lt;br /&gt;
				If $__aDropFiles[0] &amp;gt; 0 Then&lt;br /&gt;
					_ArrayDisplay($__aDropFiles)&lt;br /&gt;
				EndIf&lt;br /&gt;
&lt;br /&gt;
		EndSwitch&lt;br /&gt;
	WEnd&lt;br /&gt;
	GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func WM_DROPFILES($hWnd, $iMsg, $iwParam, $ilParam)&lt;br /&gt;
	#forceref $hWnd, $ilParam&lt;br /&gt;
	Switch $iMsg&lt;br /&gt;
		Case $WM_DROPFILES&lt;br /&gt;
			Local $aReturn = _WinAPI_DragQueryFileEx($iwParam)&lt;br /&gt;
			If IsArray($aReturn) Then&lt;br /&gt;
				$__aDropFiles = $aReturn&lt;br /&gt;
			Else&lt;br /&gt;
				Local $aError[1] = [0]&lt;br /&gt;
				$__aDropFiles = $aError&lt;br /&gt;
			EndIf&lt;br /&gt;
	EndSwitch&lt;br /&gt;
	Return $GUI_RUNDEFMSG&lt;br /&gt;
EndFunc   ;==&amp;gt;WM_DROPFILES&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ExitCheckTextChange ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 8007-negativenrg&lt;br /&gt;
 | AuthorName = NegativeNrG&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Check(when Exit), if Text is not equal to $e_to Then, prompt the user to save or not save.&lt;br /&gt;
;_ExitCheckText Change $Edit Handle, $title of messagebox, $message of messagebox, $equal to(default = NULL).&lt;br /&gt;
&lt;br /&gt;
Func _ExitCheckTextChange($E_hnd,$title,$message,$e_to = &#039;&#039;)&lt;br /&gt;
	Local $buffer, $choice, $filetosave, $handle1&lt;br /&gt;
                $buffer = GUIctrlread($E_hnd)&lt;br /&gt;
        If $buffer &amp;lt;&amp;gt; $e_to Then&lt;br /&gt;
            $choice = Msgbox(4,$title,$message)&lt;br /&gt;
            If $choice = 6 Then&lt;br /&gt;
                $filetosave = FileSaveDialog(&#039;Choose File&#039;,@scriptdir,&#039;(*.au3)&#039;)&lt;br /&gt;
                $handle1 = FileOpen($filetosave,2)&lt;br /&gt;
                FileWrite($handle1,$buffer)&lt;br /&gt;
                Exit&lt;br /&gt;
            Elseif $choice &amp;lt;&amp;gt; 6 Then&lt;br /&gt;
            Exit&lt;br /&gt;
        EndIf&lt;br /&gt;
        Else&lt;br /&gt;
        Exit&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileDeleteEx ==&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;
; Ref: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;APIFilesConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPIFiles.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_FileDeleteEx(&amp;quot;C:\Example.dat&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _FileDeleteEx($sFilePath)&lt;br /&gt;
    Return FileDelete($sFilePath) = 1 ? 1 : Int(_WinAPI_MoveFileEx(FileGetShortName($sFilePath), &amp;quot;&amp;quot;, $MOVE_FILE_DELAY_UNTIL_REBOOT))&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileDeleteEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileCheck ==&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;Date.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Check if the file was modified less than 24 hours ago.&lt;br /&gt;
ConsoleWrite( _FileCheck(@ScriptFullPath, 24) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _FileCheck($sFilePath, $iHours = 24)&lt;br /&gt;
    Local $aTime&lt;br /&gt;
    If FileExists($sFilePath) = 0 Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aTime = FileGetTime($sFilePath, 0, 0)&lt;br /&gt;
    Return Number(_DateDiff(&amp;quot;h&amp;quot;, $aTime[0] &amp;amp; &amp;quot;/&amp;quot; &amp;amp; $aTime[1] &amp;amp; &amp;quot;/&amp;quot; &amp;amp; $aTime[2] &amp;amp; &amp;quot; &amp;quot; &amp;amp; $aTime[3] &amp;amp; &amp;quot;:&amp;quot; &amp;amp; $aTime[4] &amp;amp; &amp;quot;:&amp;quot; &amp;amp; $aTime[5], @YEAR &amp;amp; &amp;quot;/&amp;quot; &amp;amp; @MON &amp;amp; &amp;quot;/&amp;quot; &amp;amp; @MDAY &amp;amp; &amp;quot; &amp;quot; &amp;amp; @HOUR &amp;amp; &amp;quot;:&amp;quot; &amp;amp; @MIN &amp;amp; &amp;quot;:&amp;quot; &amp;amp; @SEC) &amp;lt; $iHours)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileCheck&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileCreateEx ==&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;
_FileCreateEx(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;, 42)&lt;br /&gt;
&lt;br /&gt;
; Create a blank file with a certain size in bytes.&lt;br /&gt;
Func _FileCreateEx($sFilePath, $iBytes = 0)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c fsutil file createnew &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; Int($iBytes), @WorkingDir, @SW_HIDE)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileCreateEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileID ==&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;
FileClose(FileOpen(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;, 2))&lt;br /&gt;
ConsoleWrite(_FileID(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;) &amp;amp; @CRLF)&lt;br /&gt;
FileDelete(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;)&lt;br /&gt;
&lt;br /&gt;
; Rerieve the file id of a filepath.&lt;br /&gt;
Func _FileID($sFilePath)&lt;br /&gt;
    Local $iPID = Run(@ComSpec &amp;amp; &#039; /c fsutil file queryfileid &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot;&#039;, @SystemDir, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sReturn = &#039;&#039;&lt;br /&gt;
    While 1&lt;br /&gt;
        $sReturn &amp;amp;= StdoutRead($iPID)&lt;br /&gt;
        If @error Then&lt;br /&gt;
            ExitLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
    WEnd&lt;br /&gt;
    Return StringStripWS(StringRegExpReplace($sReturn, &#039;File\sID\sis\s(.*?)&#039;, &#039;$1&#039;), 8)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileExistsWithQuotes ==&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(_FileExistsWithQuotes(&#039;&amp;quot;&#039; &amp;amp; @ScriptDir &amp;amp; &#039;&amp;quot;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_FileExistsWithQuotes(&amp;quot;&#039;&amp;quot; &amp;amp; @ScriptDir &amp;amp; &amp;quot;&#039;&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_FileExistsWithQuotes(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Version: 1.00. AutoIt: V3.3.8.1&lt;br /&gt;
; Check a filepath ecists even if the path contains quotation marks.&lt;br /&gt;
Func _FileExistsWithQuotes($sFilePath)&lt;br /&gt;
    Return FileExists(StringRegExpReplace($sFilePath, &#039;^(&amp;quot;|&#039;&#039;)*([^&amp;quot;&#039;&#039;]+)(&amp;quot;|&#039;&#039;)*$&#039;, &#039;\2&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileExistsWithQuotes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== FileLineCount ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 71214-mkish&lt;br /&gt;
 | AuthorName = MKISH&lt;br /&gt;
 | Desc = Checks the number of lines in a file (useful for larger files as well)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Author - MKISH&lt;br /&gt;
&lt;br /&gt;
; Checks the number of lines in a file (useful for larger files as well)&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local $FILE = &amp;quot;G:\WIN7\sources\boot.wim&amp;quot;&lt;br /&gt;
Local $COUNT = 0&lt;br /&gt;
Local $start = default&lt;br /&gt;
Local $res, $fLen, $err&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
	$res = _HexSearch($FILE, StringToBinary(&amp;quot;&amp;quot; &amp;amp; @crlf), $start)&lt;br /&gt;
	$start = $res + 2&lt;br /&gt;
	$COUNT = $COUNT + 1&lt;br /&gt;
	If $res = -1 then exitloop&lt;br /&gt;
Wend&lt;br /&gt;
&lt;br /&gt;
msgbox(64, &amp;quot;&amp;quot;, &amp;quot;Lines count: &amp;quot; &amp;amp; $COUNT)&lt;br /&gt;
&lt;br /&gt;
; _HexSearch function (originally written by Zinthose, modified by MKISH)&lt;br /&gt;
Func _HexSearch($FilePath, $BinaryValue, $StartOffset = Default)&lt;br /&gt;
        Local $Buffer, $ptr, $hFile, $Result, $Read, $SearchValue, $Pos, $BufferSize = 2048&lt;br /&gt;
            If $StartOffset = Default     Then $StartOffset = 0&lt;br /&gt;
            If Not FileExists($FilePath)    Then    Return SetError(1, @error, 0)&lt;br /&gt;
            $fLen = FileGetSize($FilePath)&lt;br /&gt;
            If $StartOffset &amp;gt; $fLen   Then   Return SetError(2, @error, 0)&lt;br /&gt;
            If Not IsBinary($BinaryValue)   Then    Return SetError(3, @error, 0)&lt;br /&gt;
            If Not IsNumber($StartOffset)   Then    Return SetError(4, @error, 0)&lt;br /&gt;
            $SearchValue = BinaryToString($BinaryValue)&lt;br /&gt;
            $Buffer = DllStructCreate(&amp;quot;byte[&amp;quot; &amp;amp; $BufferSize &amp;amp; &amp;quot;]&amp;quot;)&lt;br /&gt;
            $ptr = DllStructGetPtr($Buffer)&lt;br /&gt;
                $hFile = _WinAPI_CreateFile($FilePath, 2, 2, 1)&lt;br /&gt;
                If $hFile = 0 Then Return SetError(5, @error, 0)&lt;br /&gt;
            $Result = _WinAPI_SetFilePointer($hFile, $StartOffset)&lt;br /&gt;
            $err = @error&lt;br /&gt;
            If $Result = 0xFFFFFFFF Then&lt;br /&gt;
                _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                Return SetError(5, $err, 0)&lt;br /&gt;
            EndIf&lt;br /&gt;
            $Pos = $StartOffset&lt;br /&gt;
            While True&lt;br /&gt;
                    $Read = 0&lt;br /&gt;
                    $Result = _WinAPI_ReadFile($hFile, $ptr, $BufferSize, $Read)&lt;br /&gt;
                    $err = @error&lt;br /&gt;
                    If Not $Result Then&lt;br /&gt;
                        _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                        Return SetError(6, $err, 0)&lt;br /&gt;
                    EndIf&lt;br /&gt;
                    $Result = DllStructGetData($Buffer, 1)&lt;br /&gt;
                    $Result = BinaryToString($Result)&lt;br /&gt;
                    $Result = StringInStr($Result, $SearchValue)&lt;br /&gt;
                    If $Result &amp;gt; 0 Then ExitLoop&lt;br /&gt;
                    If $Read &amp;lt; $BufferSize Then&lt;br /&gt;
                        _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                        Return -1&lt;br /&gt;
                    EndIf&lt;br /&gt;
                    $Pos += $Read&lt;br /&gt;
&lt;br /&gt;
            WEnd&lt;br /&gt;
            _WinAPI_CloseHandle($hFile)&lt;br /&gt;
            If Not $Result Then Return SetError(7, @error, 0)&lt;br /&gt;
            $Result = $Pos + $Result - 1&lt;br /&gt;
            Return $Result&lt;br /&gt;
    EndFunc; ==&amp;gt; _HexSearch&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileOpenDialog ==&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;
Local $sFilePath = _FileOpenDialog(&amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;Images (*.jpg;*.bmp)|Videos (*.avi;*.mpg)&amp;quot;, Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1), 1 + 4, &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;File = &#039; &amp;amp; $sFilePath &amp;amp; &#039;, @error = &#039; &amp;amp; @error &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name ..........: _FileOpenDialog&lt;br /&gt;
; Description ...: Initiates a Open File Dialog with the option to set the position of the GUI.&lt;br /&gt;
; Syntax ........: _FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter[, $iLeft = -1[, $iTop = -1[, $iOptions = 0[,&lt;br /&gt;
;                  $sDefaultName = &amp;quot;&amp;quot;]]]])&lt;br /&gt;
; Parameters ....: $sTitle              - Title text of the Dialog GUI.&lt;br /&gt;
;                  $sIntitialDirectory  - Initial directory selected in the GUI file tree.&lt;br /&gt;
;                  $sFilter             - File type single filter such as &amp;quot;All (*.*)&amp;quot; or &amp;quot;Text files (*.txt)&amp;quot;.&lt;br /&gt;
;                  $iLeft               - [optional] The left side of the dialog box. By default (-1), the window is centered.&lt;br /&gt;
;                  $iTop                - [optional] The top of the dialog box. Default (-1) is centered&lt;br /&gt;
;                  $iOptions            - [optional] Dialog Options: To use more than one option, add the required values together. See FileOpenDialog. Default is 0.&lt;br /&gt;
;                  $sDefaultName        - [optional] Suggested file name for the user to open. Default is blank (&amp;quot;&amp;quot;).&lt;br /&gt;
; Return values .: Success: Returns the full path of the file(s) chosen. Results for multiple selections are &amp;quot;Directory|file1|file2|...&amp;quot;&lt;br /&gt;
;                  Failure: Sets @error to non-zero.&lt;br /&gt;
; Author ........: guinness&lt;br /&gt;
; Remarks........: This doesn&#039;t change the working directory of the script like FileOpenDialog does.&lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter, $iLeft = -1, $iTop = -1, $iOptions = 0, $sDefaultName = &amp;quot;&amp;quot;)&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;, -1, -1, $iLeft, $iTop), $sWorkingDir = @WorkingDir&lt;br /&gt;
    Local $sFilePath = FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter, $iOptions, $sDefaultName, $hGUI)&lt;br /&gt;
    Local $iError = @error&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return SetError($iError, GUIDelete($hGUI), $sFilePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileOpenDialog()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileRename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 52374-johnone&lt;br /&gt;
 | AuthorName = JohnOne&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;### Rename a file ###&lt;br /&gt;
;$sFile = Full path to file&lt;br /&gt;
;$sRename = New Filename&lt;br /&gt;
;$iOverWrite = 0 or 1&lt;br /&gt;
&lt;br /&gt;
;Success returns 1&lt;br /&gt;
;failure, returns 0 and sets @error&lt;br /&gt;
; 1 if FileMove fails, &lt;br /&gt;
; 2 if $sFile does not exist&lt;br /&gt;
;@extended&lt;br /&gt;
; 0 if the new file does not already exist / existed&lt;br /&gt;
; 1 if the new file already exists / existed&lt;br /&gt;
&lt;br /&gt;
;#### Example ####&lt;br /&gt;
$File = @ScriptDir &amp;amp; &#039;\filetorename.txt&#039;&lt;br /&gt;
FileWrite($File, &#039;Test&#039;)&lt;br /&gt;
_FileRename($File, &#039;newname.txt&#039;)&lt;br /&gt;
If @error Then MsgBox(0, &amp;quot;Error&amp;quot;, @error)&lt;br /&gt;
&lt;br /&gt;
Func _FileRename($sFile, $sRename, $iOverWrite = 0)&lt;br /&gt;
    Local Const $FILENOTEXIST = 2&lt;br /&gt;
    If Not FileExists($sFile) Then Return SetError($FILENOTEXIST, 0, 0)&lt;br /&gt;
    Local $_StringLen = StringLen($sFile)&lt;br /&gt;
    Local $_StringInStr = StringInStr($sFile, &amp;quot;\&amp;quot;, 0, -1, $_StringLen)&lt;br /&gt;
    Local $_Count = $_StringLen - $_StringInStr&lt;br /&gt;
    Local $_Dir = StringLeft($sFile, $_StringInStr)&lt;br /&gt;
    Local $_NewFile = $_Dir &amp;amp; $sRename&lt;br /&gt;
    Local $_NewFileExists = FileExists($_NewFile)&lt;br /&gt;
    Local $_FileMove = FileMove($sFile, $_NewFile, $iOverWrite)&lt;br /&gt;
    Return SetError(Not $_FileMove, $_NewFileExists, $_FileMove)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileRename&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== _FileRename Alternative ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;FileRename(PathFile, RenameFile)&lt;br /&gt;
;JohnOne&lt;br /&gt;
&lt;br /&gt;
FileRename(@ScriptDir &amp;amp; &amp;quot;\rename.txt&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\renamed.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func FileRename($FileName, $ReName)&lt;br /&gt;
&lt;br /&gt;
	Local $SHFILEOPSTRUCT, $SourceStruct, $DestStruct&lt;br /&gt;
	Local Const $FO_RENAME = 0x0004&lt;br /&gt;
	Local Const $FOF_SILENT = 0x0004&lt;br /&gt;
	Local Const $FOF_NOCONFIRMATION = 0x0010&lt;br /&gt;
	Local Const $FOF_NOERRORUI = 0x0400&lt;br /&gt;
	Local Const $FOF_NOCONFIRMMKDIR = 0x0200&lt;br /&gt;
	Local Const $NULL = 0&lt;br /&gt;
&lt;br /&gt;
	$SourceStruct = _StringToStruct($FileName)&lt;br /&gt;
	$DestStruct = _StringToStruct($ReName)&lt;br /&gt;
&lt;br /&gt;
	$SHFILEOPSTRUCT = DllStructCreate(&amp;quot;hwnd hWnd;uint wFunc;ptr pFrom;ptr pTo;int fFlags;int fAnyOperationsAborted;ptr hNameMappings;ptr lpszProgressTitle&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;hWnd&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;wFunc&amp;quot;, $FO_RENAME)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;pFrom&amp;quot;, DllStructGetPtr($SourceStruct))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;pTo&amp;quot;, DllStructGetPtr($DestStruct))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;fFlags&amp;quot;, BitOR($FOF_SILENT, $FOF_NOCONFIRMATION, $FOF_NOERRORUI, $FOF_NOCONFIRMMKDIR))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;fAnyOperationsAborted&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;hNameMappings&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;lpszProgressTitle&amp;quot;, $NULL)&lt;br /&gt;
&lt;br /&gt;
	$acall = DllCall(&amp;quot;shell32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;SHFileOperation&amp;quot;, &amp;quot;ptr&amp;quot;, DllStructGetPtr($SHFILEOPSTRUCT))&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Return SetError(@error, @extended, 0)&lt;br /&gt;
	EndIf&lt;br /&gt;
	Return 1&lt;br /&gt;
EndFunc   ;==&amp;gt;FileRename&lt;br /&gt;
&lt;br /&gt;
Func _StringToStruct($string)&lt;br /&gt;
&lt;br /&gt;
	Local $iLen = StringLen($string)&lt;br /&gt;
	Local $Struct = DllStructCreate(&amp;quot;char[&amp;quot; &amp;amp; String($iLen + 2) &amp;amp; &amp;quot;]&amp;quot;)&lt;br /&gt;
	DllStructSetData($Struct, 1, $string)&lt;br /&gt;
	DllStructSetData($Struct, 1, 0, $iLen + 1)&lt;br /&gt;
	DllStructSetData($Struct, 1, 0, $iLen + 2)&lt;br /&gt;
&lt;br /&gt;
	Return $Struct&lt;br /&gt;
EndFunc   ;==&amp;gt;_StringToStruct&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFolderDepth ==&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;
; Autoit 3.3.5.4 and Below&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir &amp;amp; &#039;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the folder depth of a filepath.&lt;br /&gt;
Func _GetFolderDepth($sFilePath)&lt;br /&gt;
    If StringInStr($sFilePath, &#039;.&#039;, 2, -1) Then&lt;br /&gt;
        $sFilePath = StringLeft($sFilePath, StringInStr($sFilePath, &amp;quot;&amp;quot;, 2, -1) - 1)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $aArray = StringSplit(StringRegExpReplace($sFilePath, &#039;[/]+z&#039;, &#039;&#039;), &#039;&#039;)&lt;br /&gt;
    Return $aArray[0] - 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFolderDepth&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFolderDepth ==&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;
; Autoit 3.3.5.4 and Above&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir &amp;amp; &#039;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the folder depth of a filepath. Works with V3.3.5.4+&lt;br /&gt;
Func _GetFolderDepth($sFilePath)&lt;br /&gt;
    If StringInStr($sFilePath, &#039;.&#039;, 2, -1) Then&lt;br /&gt;
        $sFilePath = StringLeft($sFilePath, StringInStr($sFilePath, &amp;quot;&amp;quot;, 2, -1) - 1)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return StringSplit(StringRegExpReplace($sFilePath, &#039;[/]+z&#039;, &#039;&#039;), &#039;&#039;)[0] - 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFolderDepth&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsDir ==&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;IsDir: Using a file - &amp;quot; &amp;amp; IsDir(@ScriptFullPath) &amp;amp; @CRLF) ; Return 0&lt;br /&gt;
ConsoleWrite(&amp;quot;IsDir: Using a directory - &amp;quot; &amp;amp; IsDir(@ScriptDir) &amp;amp; @CRLF) ; Return 1&lt;br /&gt;
&lt;br /&gt;
Func IsDir($sFilePath)&lt;br /&gt;
	Return Int(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), &#039;D&#039;, Default, 1) &amp;gt; 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;IsDir&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFile ==&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;
Func IsFile($sFilePath)&lt;br /&gt;
    Return Number(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), &amp;quot;D&amp;quot;, 2, 1) = 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;IsFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileDiff ==&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(_IsFileDiff(@ScriptFullPath, @ScriptFullPath) &amp;amp; @CRLF) ; This will return False as the files are exactly the same.&lt;br /&gt;
ConsoleWrite(_IsFileDiff(@ScriptFullPath, @AutoItExe) &amp;amp; @CRLF) ; This will return True as the files are different.&lt;br /&gt;
&lt;br /&gt;
; Check if a file is different.&lt;br /&gt;
Func _IsFileDiff($sFilePath_1, $sFilePath_2)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c FC /B /W &amp;quot;&#039; &amp;amp; $sFilePath_1 &amp;amp; &#039;&amp;quot; &amp;quot;&#039; &amp;amp; $sFilePath_2 &amp;amp; &#039;&amp;quot;&#039;, @WorkingDir, @SW_HIDE) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileDiff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileOlder ==&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;Date.au3&amp;gt; ; Required for _DateDiff()&lt;br /&gt;
&lt;br /&gt;
; Check if the current script is older than 10 days.&lt;br /&gt;
If _IsFileOlder(@ScriptFullPath, 10) Then&lt;br /&gt;
	MsgBox(4096, &#039;&#039;, &#039;File is older than 10 days.&#039;)&lt;br /&gt;
Else&lt;br /&gt;
	MsgBox(4096, &#039;&#039;, &#039;File isn&#039;&#039;t older than 10 days.&#039;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
; Is a file older than a certain number of days.&lt;br /&gt;
Func _IsFileOlder($sFilePath, $iDays)&lt;br /&gt;
	Local $aArray = FileGetTime($sFilePath, 0)&lt;br /&gt;
	Return _DateDiff(&#039;D&#039;, $aArray[0] &amp;amp; &#039;/&#039; &amp;amp; $aArray[1] &amp;amp; &#039;/&#039; &amp;amp; $aArray[2] &amp;amp; &#039; &#039; &amp;amp; $aArray[3] &amp;amp; &#039;:&#039; &amp;amp; $aArray[4] &amp;amp; &#039;:&#039; &amp;amp; $aArray[5], @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) &amp;gt;= $iDays&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileOlder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileSame ==&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(_IsFileSame(@ScriptFullPath, @ScriptFullPath) &amp;amp; @CRLF) ; This will return True as the files are exactly the same.&lt;br /&gt;
ConsoleWrite(_IsFileSame(@ScriptFullPath, @AutoItExe) &amp;amp; @CRLF) ; This will return False as the files are different.&lt;br /&gt;
&lt;br /&gt;
; Check if a file is the same.&lt;br /&gt;
Func _IsFileSame($sFilePath_1, $sFilePath_2)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c FC /B /W &amp;quot;&#039; &amp;amp; $sFilePath_1 &amp;amp; &#039;&amp;quot; &amp;quot;&#039; &amp;amp; $sFilePath_2 &amp;amp; &#039;&amp;quot;&#039;, @WorkingDir, @SW_HIDE) = 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileSame&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IniReadFile ==&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;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__INIFileFill(@ScriptDir &amp;amp; &#039;\Example.ini&#039;) ; Create an INI file with random data.&lt;br /&gt;
&lt;br /&gt;
Local $aArray = _IniReadFile(@ScriptDir &amp;amp; &#039;\Example.ini&#039;)&lt;br /&gt;
FileDelete(@ScriptDir &amp;amp; &#039;\Example.ini&#039;)&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&lt;br /&gt;
Func _IniReadFile($sFilePath)&lt;br /&gt;
    Local $aReturn[1][3] = [[0, 3]], $aSectionArray, $aSectionNameArray, $iCount = 0&lt;br /&gt;
    $aSectionNameArray = IniReadSectionNames($sFilePath)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $aReturn)&lt;br /&gt;
    EndIf&lt;br /&gt;
    For $A = 1 To $aSectionNameArray[0]&lt;br /&gt;
        $aSectionArray = IniReadSection($sFilePath, $aSectionNameArray[$A])&lt;br /&gt;
        If @error Then&lt;br /&gt;
            ContinueLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
        For $B = 1 To $aSectionArray[0][0]&lt;br /&gt;
            $aReturn[0][0] += 1&lt;br /&gt;
            $iCount += 1&lt;br /&gt;
            If $aReturn[0][0] &amp;lt;= $iCount + 1 Then&lt;br /&gt;
                ReDim $aReturn[$aReturn[0][0] * 2][$aReturn[0][1]]&lt;br /&gt;
            EndIf&lt;br /&gt;
            $aReturn[$iCount][0] = $aSectionArray[$B][0]&lt;br /&gt;
            $aReturn[$iCount][1] = $aSectionArray[$B][1]&lt;br /&gt;
            $aReturn[$iCount][2] = $aSectionNameArray[$A]&lt;br /&gt;
        Next&lt;br /&gt;
    Next&lt;br /&gt;
    ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1]] ; Remove empty entries.&lt;br /&gt;
    Return $aReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_IniReadFile&lt;br /&gt;
&lt;br /&gt;
Func __INIFileFill($sFilePath)&lt;br /&gt;
    Local $sData = &#039;&#039;, $sHeader = &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To Random(1, 5, 1)&lt;br /&gt;
        $sHeader = _RandomText(Random(5, 25, 1))&lt;br /&gt;
        $sData = &amp;quot;&amp;quot;&lt;br /&gt;
        For $j = 1 To Random(1, 25, 1)&lt;br /&gt;
            $sData &amp;amp;= _RandomText(Random(5, 25, 1)) &amp;amp; &#039;=&#039; &amp;amp; _RandomText(Random(5, 25, 1)) &amp;amp; @LF&lt;br /&gt;
        Next&lt;br /&gt;
        IniWriteSection($sFilePath, $sHeader, $sData)&lt;br /&gt;
    Next&lt;br /&gt;
EndFunc   ;==&amp;gt;__FillINIFile&lt;br /&gt;
&lt;br /&gt;
Func _RandomText($iLength = 10)&lt;br /&gt;
    Local $sData = &#039;&#039;, $sRandom = &#039;&#039;&lt;br /&gt;
    For $i = 1 To $iLength&lt;br /&gt;
        $sRandom = Random(55, 116, 1)&lt;br /&gt;
        $sData &amp;amp;= Chr($sRandom + 6 * ($sRandom &amp;gt; 90) - 7 * ($sRandom &amp;lt; 65))&lt;br /&gt;
    Next&lt;br /&gt;
    Return $sData&lt;br /&gt;
EndFunc   ;==&amp;gt;_RandomText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IniReadInit ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 9370-mlowery&lt;br /&gt;
 | AuthorName = mlowery&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;===============================================================================&lt;br /&gt;
; Description:     Reads values from INI or creates INI with initial values.&lt;br /&gt;
;                  Intended to ensure all available INI settings are exposed&lt;br /&gt;
;                  and editable.&lt;br /&gt;
;                  Parameters are identical to IniRead()&lt;br /&gt;
; Parameter(s):    $filename  = filename of INI&lt;br /&gt;
;                  $section  = section name of INI&lt;br /&gt;
;                  $key      = key name in section&lt;br /&gt;
;                  $default  = default value (written to INI if not exists)&lt;br /&gt;
; Requirement(s):  None&lt;br /&gt;
; Return Value(s): Returns value from INI (or default if not defined)&lt;br /&gt;
; Note(s):         Chr(127) used to detect non-existing value since won&#039;t normally exist in a text file&lt;br /&gt;
;===============================================================================&lt;br /&gt;
Func _IniReadInit($filename, $section, $key, $default)&lt;br /&gt;
  Local $value = IniRead($filename, $section, $key, Chr(127))&lt;br /&gt;
    If $value = Chr(127) Then&lt;br /&gt;
      IniWrite($filename, $section, $key, $default)&lt;br /&gt;
      $value = $default&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $value&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsValidFileType ==&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(@ScriptFullPath &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@ScriptFullPath, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(@AutoItExe &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@AutoItExe, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a filepath matches an extension filetype. Based on the idea by guinness - http://www.autoitscript.com/forum/topic/123674-isvalidfiletype/&lt;br /&gt;
Func _IsValidFileType($sFilePath, $sList = &amp;quot;bat;cmd;exe&amp;quot;) ; By AZJIO - http://www.autoitscript.com/forum/topic/...filetype/page__view__findpost_&lt;br /&gt;
    Local $iDot = StringInStr($sFilePath, &amp;quot;.&amp;quot;, 0, -1)&lt;br /&gt;
    Return $iDot And StringInStr(&#039;;&#039; &amp;amp; $sList &amp;amp; &#039;;&#039;, &#039;;&#039; &amp;amp; StringTrimLeft($sFilePath, $iDot) &amp;amp; &#039;;&#039;) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsValidFileType&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;
; Example 2&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(@ScriptFullPath &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@ScriptFullPath, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(@AutoItExe &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@AutoItExe, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a filepath matches an extension filetype. Based on the idea by guinness - http://www.autoitscript.com/forum/topic/123674-isvalidfiletype/&lt;br /&gt;
Func _IsValidFileType($sFilePath, $sList = &amp;quot;bat;cmd;exe&amp;quot;, $iOpFast = 1) ; By Yashied.&lt;br /&gt;
    If StringStripWS($sList, 8) = &amp;quot;&amp;quot; Then&lt;br /&gt;
        $sList = &amp;quot;*&amp;quot;&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return _WinAPI_PathMatchSpec($sFilePath, StringReplace(&#039;;&#039; &amp;amp; $sList, &#039;;&#039;, &#039;;*.&#039;, 0, $iOpFast * 2))&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsValidFileType&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== File Open/Save/Folder Dialog Box ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 2709-mhz&lt;br /&gt;
 | AuthorName = MHz&lt;br /&gt;
 | AuthorURL2 = 4997-odklizec&lt;br /&gt;
 | AuthorName2 = odklizec&lt;br /&gt;
 | AuthorURL3 = 6756-danny35d&lt;br /&gt;
 | AuthorName3 = Danny35d&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Center - File Open/Save/Folder Dialog Box&lt;br /&gt;
; Author - odklizec, MHz, Danny35d&lt;br /&gt;
&lt;br /&gt;
 If StringInStr($cmdlineraw, &#039;/MoveWin&#039;) Then&lt;br /&gt;
	 Local $size, $PosX, $PosY&lt;br /&gt;
     $cmdlineraw = StringSplit(StringMid($cmdlineraw, StringInStr($cmdlineraw, &#039;/MoveWin&#039;)), &#039;:&#039;)&lt;br /&gt;
     While 1&lt;br /&gt;
         Select&lt;br /&gt;
         Case WinExists($cmdlineraw[2])&lt;br /&gt;
             $size=WinGetPos ($cmdlineraw[2])&lt;br /&gt;
             $PosX=@DesktopWidth/2 - $size[2]/2&lt;br /&gt;
             $PosY=@DesktopHeight/2 - $size[3]/2&lt;br /&gt;
             WinMove($cmdlineraw[2], &amp;quot;&amp;quot;, $PosX, $PosY)&lt;br /&gt;
             WinActivate($cmdlineraw[2])&lt;br /&gt;
             ExitLoop&lt;br /&gt;
         EndSelect&lt;br /&gt;
         Sleep(50)&lt;br /&gt;
     WEnd&lt;br /&gt;
     Exit&lt;br /&gt;
 EndIf&lt;br /&gt;
Global $PID, $Read_File, $Save_File&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Open file Dialog Box&#039;)&lt;br /&gt;
 $Read_File = FileOpenDialog ( &amp;quot;Open file Dialog Box&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\&amp;quot;, &amp;quot;AutoIt Files (*.au3)&amp;quot;,3,@ScriptFullPath)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Save file Dialog Box&#039;)&lt;br /&gt;
 $Save_File = FileSaveDialog( &amp;quot;Save file Dialog Box&amp;quot;, @ScriptDir, &amp;quot;Scripts (*.aut;*.au3)&amp;quot;, 3)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Browse for Folder&#039;)&lt;br /&gt;
 FileSelectFolder(&amp;quot;Choose a folder with plugins..&amp;quot;, &amp;quot;&amp;quot;,&amp;quot;4&amp;quot;,&amp;quot;c:\&amp;quot;)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
&lt;br /&gt;
 Func _FindBrowseWin($sTitle)&lt;br /&gt;
     If @Compiled Then&lt;br /&gt;
         Return(Run(@ScriptFullPath &amp;amp; &#039; /MoveWin:&#039; &amp;amp; $sTitle))&lt;br /&gt;
     Else&lt;br /&gt;
         Return(Run(@AutoItExe &amp;amp; &#039; &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot; /MoveWin:&#039; &amp;amp; $sTitle))&lt;br /&gt;
     EndIf&lt;br /&gt;
 EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _MoveFileOnReboot ==&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.2.0, Creation Date = 21/03/12.&lt;br /&gt;
&lt;br /&gt;
; Function to Move or Delete a file on next reboot!&lt;br /&gt;
Func _MoveFileOnReboot($sSourcePath, $sDestPath = &amp;quot;&amp;quot;); If $sDestPath = &amp;quot;&amp;quot; the file is deleted instead of moved.&lt;br /&gt;
    Local $iRet&lt;br /&gt;
&lt;br /&gt;
    ; PendingFileRenameOperations (HKLM\SYSTEM\CurrentControlSet\Control\Session Manager)&lt;br /&gt;
    If $DestPath = &amp;quot;&amp;quot; Then&lt;br /&gt;
        $iRet = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;MoveFileExA&amp;quot;, &amp;quot;str&amp;quot;, $sSourcePath, &amp;quot;int&amp;quot;, 0, &amp;quot;dword&amp;quot;, 4)&lt;br /&gt;
    Else&lt;br /&gt;
        $iRet = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;MoveFileExA&amp;quot;, &amp;quot;str&amp;quot;, $sSourcePath, &amp;quot;str&amp;quot;, $sDestPath, &amp;quot;dword&amp;quot;, 4)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return $iRet&lt;br /&gt;
EndFunc   ;==&amp;gt;_MoveFileOnReboot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _MultipleFileOpenDialog ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL =&lt;br /&gt;
 | AuthorName = /dev/null&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Local $message = &amp;quot;Hold down Ctrl or Shift to choose multiple files.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Local $filename = _MultipleFileOpenDialog($message,300,300)&lt;br /&gt;
&lt;br /&gt;
Local $var = FileOpenDialog($message, @WindowsDir &amp;amp; &amp;quot;\&amp;quot;, &amp;quot;Images (*.jpg;*.bmp)&amp;quot;, 1 + 4 )&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    MsgBox(4096,&amp;quot;&amp;quot;,&amp;quot;No File(s) chosen&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
    $var = StringReplace($var, &amp;quot;|&amp;quot;, @CRLF)&lt;br /&gt;
    MsgBox(4096,&amp;quot;&amp;quot;,&amp;quot;You chose &amp;quot; &amp;amp; $var)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
FileDelete($filename)&lt;br /&gt;
func _MultipleFileOpenDialog($title,$posx,$posy)&lt;br /&gt;
    Local $temp = EnvGet(&amp;quot;temp&amp;quot;)&lt;br /&gt;
    Local $filename = $temp &amp;amp; &amp;quot;\move_file_open_dialog.au3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    Local $script = &#039;Global $title = &amp;quot;&#039; &amp;amp; $title &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Global $pos_x = &#039; &amp;amp; $posx &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Global $pos_y = &#039; &amp;amp; $posy &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;AdlibRegister(&amp;quot;_Move&amp;quot;,10)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;while 1&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;    sleep(1000)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;wend&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Func _Move()&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;   if (WinActive($title)) Then&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;      WinMove($title,&amp;quot;&amp;quot;,$pos_x,$pos_y)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;      Exit&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;   EndIf&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;EndFunc&#039; &amp;amp; @CRLF&lt;br /&gt;
&lt;br /&gt;
    FileWrite($filename,$script)&lt;br /&gt;
    ;MsgBox(0,&amp;quot;&amp;quot;,$script &amp;amp; @CRLF &amp;amp; $filename)&lt;br /&gt;
    Run(@AutoItExe &amp;amp; &amp;quot; /AutoIt3ExecuteScript &amp;quot; &amp;amp; $filename)&lt;br /&gt;
    sleep(250)&lt;br /&gt;
    Return $filename&lt;br /&gt;
EndFunc ;==&amp;gt;_MultipleFileOpenDialog()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _OpenFolder ==&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;
#cs&lt;br /&gt;
    These have been declared in Global scope as you may wish to use them elsewhere in your script.&lt;br /&gt;
#ce&lt;br /&gt;
Global $ALTSTARTUP = 0x1d&lt;br /&gt;
Global $APPDATA = 0x1a&lt;br /&gt;
Global $BITBUCKET = 0x0a&lt;br /&gt;
Global $COMMONALTSTARTUP = 0x1e&lt;br /&gt;
Global $COMMONAPPDATA = 0x23&lt;br /&gt;
Global $COMMONDESKTOPDIR = 0x19&lt;br /&gt;
Global $COMMONFAVORITES = 0x1f&lt;br /&gt;
Global $COMMONPROGRAMS = 0x17&lt;br /&gt;
Global $COMMONSTARTMENU = 0x16&lt;br /&gt;
Global $COMMONSTARTUP = 0x18&lt;br /&gt;
Global $CONTROLS = 0x03&lt;br /&gt;
Global $COOKIES = 0x21&lt;br /&gt;
Global $DESKTOP = 0x00&lt;br /&gt;
Global $DESKTOPDIRECTORY = 0x10&lt;br /&gt;
Global $DRIVES = 0x11&lt;br /&gt;
Global $FAVORITES = 0x06&lt;br /&gt;
Global $FONTS = 0x14&lt;br /&gt;
Global $HISTORY = 0x22&lt;br /&gt;
Global $INTERNETCACHE = 0x20&lt;br /&gt;
Global $LOCALAPPDATA = 0x1c&lt;br /&gt;
Global $MYPICTURES = 0x27&lt;br /&gt;
Global $NETHOOD = 0x13&lt;br /&gt;
Global $NETWORK = 0x12&lt;br /&gt;
Global $PERSONAL = 0x05&lt;br /&gt;
Global $PRINTERS = 0x04&lt;br /&gt;
Global $PRINTHOOD = 0x1b&lt;br /&gt;
Global $PROFILE = 0x28&lt;br /&gt;
Global $PROGRAMFILES = 0x26&lt;br /&gt;
Global $PROGRAMFILESx86 = 0x30&lt;br /&gt;
Global $PROGRAMS = 0x02&lt;br /&gt;
Global $RECENT = 0x08&lt;br /&gt;
Global $SENDTO = 0x09&lt;br /&gt;
Global $STARTMENU = 0x0b&lt;br /&gt;
Global $STARTUP = 0x07&lt;br /&gt;
Global $SYSTEM = 0x25&lt;br /&gt;
Global $SYSTEMx86 = 0x29&lt;br /&gt;
Global $TEMPLATES = 0x15&lt;br /&gt;
Global $WINDOWS = 0x24&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_OpenFolder(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_OpenFolder($PRINTERS) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Open a folder or special folder variable, similar to using ShellExecute.&lt;br /&gt;
Func _OpenFolder($sFolderPath)&lt;br /&gt;
    Local $oShell = ObjCreate(&#039;shell.application&#039;)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $oShell.Open($sFolderPath)&lt;br /&gt;
    Return 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_OpenFolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _PathAppendToFilename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 31965-progandy&lt;br /&gt;
 | AuthorName = ProgAndy&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
$sOrg = &amp;quot;C:\Some.Folder\some.file.ext&amp;quot;&lt;br /&gt;
$sAdd = &amp;quot;_backup&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$sNew = _PathAppendToFilename($sOrg, $sAdd)&lt;br /&gt;
&lt;br /&gt;
$sStripped = _PathStripRightFromFilename($sNew, $sAdd)&lt;br /&gt;
&lt;br /&gt;
MsgBox(0, &amp;quot;&amp;quot;, $sOrg &amp;amp; @CRLF &amp;amp; $sAdd &amp;amp; @CRLF &amp;amp; $sNew &amp;amp; @CRLF &amp;amp; $sStripped)&lt;br /&gt;
&lt;br /&gt;
Func _PathAppendToFilename($sName, $sAppend)&lt;br /&gt;
    ; Author: ProgAndy&lt;br /&gt;
    If StringRegExp($sAppend, &#039;[\/\\:\?&amp;quot;&amp;lt;&amp;gt;\|\*]&#039;) Then Return SetError(1, 0, $sName)&lt;br /&gt;
    Return StringRegExpReplace($sName, &amp;quot;(\.[^\\/\.]+)$&amp;quot;, $sAppend &amp;amp; &amp;quot;\1&amp;quot;, 1)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _PathStripRightFromFilename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 31965-progandy&lt;br /&gt;
 | AuthorName = ProgAndy&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Func _PathStripRightFromFilename($sName, $sStrip)&lt;br /&gt;
    ; Author: ProgAndy&lt;br /&gt;
    If StringRegExp($sStrip, &#039;[\/\\:\?&amp;quot;&amp;lt;&amp;gt;\|\*]&#039;) Then Return SetError(1, 0, $sName)&lt;br /&gt;
    Return StringRegExpReplace($sName, &amp;quot;\Q&amp;quot; &amp;amp; $sStrip &amp;amp; &amp;quot;\E(\.[^\\/\.]+)$&amp;quot;, &amp;quot;\1&amp;quot;, 1)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SelfDelete ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 2709-mhz&lt;br /&gt;
 | AuthorName = MHz&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; This also removes the directory which the file is in&lt;br /&gt;
; Author MHz with the directory delete addition by The Kandie Man&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;:loop2&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;rmdir /q &amp;quot;&#039; &amp;amp; $dirToDelete &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;if exist &amp;quot;&#039; &amp;amp; $dirToDelete &amp;amp; &#039;&amp;quot; goto loop2&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;del &#039; &amp;amp; @TempDir &amp;amp; &#039;\scratch.bat&#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&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ShellExecuteFileSelectFolder ==&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(_ShellExecuteFileSelectFolder(&#039;Select a Folder&#039;, @HomeDrive) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Shell Execute a selected folder.&lt;br /&gt;
Func _ShellExecuteFileSelectFolder($sText, $sRoot, $iFlag = 0, $sInitialDir = &#039;&#039;, $hWnd = &#039;&#039;)&lt;br /&gt;
    Local $sFolder = FileSelectFolder($sText, $sRoot, $iFlag, $sInitialDir, $hWnd)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(@error, @extended, &#039;&#039;)&lt;br /&gt;
    EndIf&lt;br /&gt;
    ShellExecute($sFolder)&lt;br /&gt;
    Return $sFolder&lt;br /&gt;
EndFunc   ;==&amp;gt;_ShellExecuteFileSelectFolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SuiCide ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 28010-larrydalooza&lt;br /&gt;
 | AuthorName = LarryDalooza&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; IMPORTANT MAKE A COPY OF SCRIPT BEFORE DELETION&lt;br /&gt;
; Deletes the running script&lt;br /&gt;
&lt;br /&gt;
Func SuiCide()&lt;br /&gt;
	Local $sFilePath = @TempDir &amp;amp; &#039;\SuiCide.bat&#039;&lt;br /&gt;
	FileDelete($sFilePath)&lt;br /&gt;
	FileWrite($sFilePath, &#039;loop:&#039; &amp;amp; @CRLF &amp;amp; &#039;del &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
			&#039;ping -n 1 -w 250 zxywqxz_q&#039; &amp;amp; @CRLF &amp;amp; &#039;if exist &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; _&lt;br /&gt;
			&#039;&amp;quot; goto loop&#039; &amp;amp; @CRLF &amp;amp; &#039;del SuiCide.bat&#039; &amp;amp; @CRLF)&lt;br /&gt;
	Exit Run($sFilePath, @TempDir, @SW_HIDE)&lt;br /&gt;
EndFunc   ;==&amp;gt;SuiCide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _UniqueFilename ==&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;
&lt;br /&gt;
ConsoleWrite(_UniqueFilename(@ScriptDir, &#039;.au3&#039;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _UniqueFilename($sFilePath, $sExtension)&lt;br /&gt;
    Local $iRandom = 0, $sUnqiueFileName = &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
    $sExtension = &#039;.&#039; &amp;amp; StringRegExpReplace($sExtension, &#039;\A[\.]+&#039;, &#039;&#039;)&lt;br /&gt;
    $sFilePath = StringRegExpReplace($sFilePath, &#039;[\\/]+\z&#039;, &#039;&#039;) &amp;amp; &#039;\&#039;&lt;br /&gt;
    While 1&lt;br /&gt;
        $iRandom = Random(55, 116, 1)&lt;br /&gt;
        $sUnqiueFileName &amp;amp;= Chr($iRandom + 6 * ($iRandom &amp;gt; 90) - 7 * ($iRandom &amp;lt; 65))&lt;br /&gt;
        If FileExists($sFilePath &amp;amp; $sUnqiueFileName &amp;amp; $sExtension) = 0 And StringLen($sUnqiueFileName) &amp;gt; 7 Then&lt;br /&gt;
            ExitLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
    WEnd&lt;br /&gt;
    Return $sFilePath &amp;amp; $sUnqiueFileName &amp;amp; $sExtension&lt;br /&gt;
EndFunc   ;==&amp;gt;_UniqueFilename&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Windows - Copy With Progress ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 19-jos&lt;br /&gt;
 | AuthorName = Jos&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Windows - Copy With Progress&lt;br /&gt;
&lt;br /&gt;
;~ 4 Do not display a progress dialog box.&lt;br /&gt;
;~ 8 Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.&lt;br /&gt;
;~ 16 Respond with &amp;quot;Yes to All&amp;quot; for any dialog box that is displayed.&lt;br /&gt;
;~ 64 Preserve undo information, if possible.&lt;br /&gt;
;~ 128 Perform the operation on files only if a wildcard file name (*.*) is specified.&lt;br /&gt;
;~ 256 Display a progress dialog box but do not show the file names.&lt;br /&gt;
;~ 512 Do not confirm the creation of a new directory if the operation requires one to be created.&lt;br /&gt;
;~ 1024 Do not display a user interface if an error occurs.&lt;br /&gt;
;~ 2048 Version 4.71. Do not copy the security attributes of the file.&lt;br /&gt;
;~ 4096 Only operate in the local directory. Don&#039;t operate recursively into subdirectories.&lt;br /&gt;
;~ 8192 Version 5.0. Do not copy connected files as a group. Only copy the specified files.&lt;br /&gt;
&lt;br /&gt;
_FileCopy(&amp;quot;C:\Installed Apps\Patches\WindowsXP-KB835935-SP2-ENU.exe&amp;quot;,&amp;quot;C:\temp&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
; to copy a directory the destination directory must exist&lt;br /&gt;
&lt;br /&gt;
Func _FileCopy($fromFile,$tofile)&lt;br /&gt;
    Local $FOF_RESPOND_YES = 16&lt;br /&gt;
    Local $FOF_SIMPLEPROGRESS = 256&lt;br /&gt;
    $winShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
    $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_Files_%26_Folders_)&amp;diff=12406</id>
		<title>Snippets ( Files &amp; Folders )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_Files_%26_Folders_)&amp;diff=12406"/>
		<updated>2014-05-12T19:24:45Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* _FileDeleteEx */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
[[category:Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Snippet Credit Header}}&lt;br /&gt;
&lt;br /&gt;
== _ConvertFileToUTF16 ==&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;
_ConvertFileToUTF16(@ScriptDir &amp;amp; &amp;quot;\Example.xml&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _ConvertFileToUTF16($sFilePath)&lt;br /&gt;
    Local $iEncoding = FileGetEncoding($sFilePath)&lt;br /&gt;
    Local $hFileOpen = FileOpen($sFilePath, $iEncoding)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $sData = FileRead($hFileOpen)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
&lt;br /&gt;
    $hFileOpen = FileOpen($sFilePath, 2 + 32)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(2, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    FileWrite($hFileOpen, $sData)&lt;br /&gt;
    Return FileClose($hFileOpen)&lt;br /&gt;
EndFunc   ;==&amp;gt;_ConvertFileToUTF16&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== DropFiles ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 35302-guinness&lt;br /&gt;
 | AuthorName = guinness&lt;br /&gt;
 | Desc = Dropping multiple files onto a GUI&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Dropping multiple files onto a GUI&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;APIConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $__aDropFiles&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
	Local $hGUI = GUICreate(&#039;&#039;, 500, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)&lt;br /&gt;
&lt;br /&gt;
	; Create a label that is transparent which will accept &#039;drop&#039; events.&lt;br /&gt;
	GUICtrlCreateLabel(&amp;quot;&amp;quot;, 0, 0, 500, 500)&lt;br /&gt;
	GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)&lt;br /&gt;
	GUICtrlSetResizing(-1, $GUI_DOCKALL)&lt;br /&gt;
	GUICtrlSetState(-1, $GUI_DROPACCEPTED)&lt;br /&gt;
&lt;br /&gt;
	GUIRegisterMsg($WM_DROPFILES, &amp;quot;WM_DROPFILES&amp;quot;)&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&lt;br /&gt;
				ExitLoop&lt;br /&gt;
&lt;br /&gt;
			Case $GUI_EVENT_DROPPED&lt;br /&gt;
				If $__aDropFiles[0] &amp;gt; 0 Then&lt;br /&gt;
					_ArrayDisplay($__aDropFiles)&lt;br /&gt;
				EndIf&lt;br /&gt;
&lt;br /&gt;
		EndSwitch&lt;br /&gt;
	WEnd&lt;br /&gt;
	GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func WM_DROPFILES($hWnd, $iMsg, $iwParam, $ilParam)&lt;br /&gt;
	#forceref $hWnd, $ilParam&lt;br /&gt;
	Switch $iMsg&lt;br /&gt;
		Case $WM_DROPFILES&lt;br /&gt;
			Local $aReturn = _WinAPI_DragQueryFileEx($iwParam)&lt;br /&gt;
			If IsArray($aReturn) Then&lt;br /&gt;
				$__aDropFiles = $aReturn&lt;br /&gt;
			Else&lt;br /&gt;
				Local $aError[1] = [0]&lt;br /&gt;
				$__aDropFiles = $aError&lt;br /&gt;
			EndIf&lt;br /&gt;
	EndSwitch&lt;br /&gt;
	Return $GUI_RUNDEFMSG&lt;br /&gt;
EndFunc   ;==&amp;gt;WM_DROPFILES&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ExitCheckTextChange ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 8007-negativenrg&lt;br /&gt;
 | AuthorName = NegativeNrG&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Check(when Exit), if Text is not equal to $e_to Then, prompt the user to save or not save.&lt;br /&gt;
;_ExitCheckText Change $Edit Handle, $title of messagebox, $message of messagebox, $equal to(default = NULL).&lt;br /&gt;
&lt;br /&gt;
Func _ExitCheckTextChange($E_hnd,$title,$message,$e_to = &#039;&#039;)&lt;br /&gt;
	Local $buffer, $choice, $filetosave, $handle1&lt;br /&gt;
                $buffer = GUIctrlread($E_hnd)&lt;br /&gt;
        If $buffer &amp;lt;&amp;gt; $e_to Then&lt;br /&gt;
            $choice = Msgbox(4,$title,$message)&lt;br /&gt;
            If $choice = 6 Then&lt;br /&gt;
                $filetosave = FileSaveDialog(&#039;Choose File&#039;,@scriptdir,&#039;(*.au3)&#039;)&lt;br /&gt;
                $handle1 = FileOpen($filetosave,2)&lt;br /&gt;
                FileWrite($handle1,$buffer)&lt;br /&gt;
                Exit&lt;br /&gt;
            Elseif $choice &amp;lt;&amp;gt; 6 Then&lt;br /&gt;
            Exit&lt;br /&gt;
        EndIf&lt;br /&gt;
        Else&lt;br /&gt;
        Exit&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileDeleteEx ==&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;
; Ref: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;APIFilesConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPIFiles.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_FileDeleteEx(&amp;quot;C:\Example.dat&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _FileDeleteEx($sFilePath)&lt;br /&gt;
    Return FileDelete($sFilePath) = 1 ? 1 : Int(_WinAPI_MoveFileEx(FileGetShortName($sFilePath), &amp;quot;&amp;quot;, $MOVE_FILE_DELAY_UNTIL_REBOOT))&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileDeleteEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileCheck ==&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;Date.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Check if the file was modified less than 24 hours ago.&lt;br /&gt;
ConsoleWrite( _FileCheck(@ScriptFullPath, 24) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _FileCheck($sFilePath, $iHours = 24)&lt;br /&gt;
    Local $aTime&lt;br /&gt;
    If FileExists($sFilePath) = 0 Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aTime = FileGetTime($sFilePath, 0, 0)&lt;br /&gt;
    Return Number(_DateDiff(&amp;quot;h&amp;quot;, $aTime[0] &amp;amp; &amp;quot;/&amp;quot; &amp;amp; $aTime[1] &amp;amp; &amp;quot;/&amp;quot; &amp;amp; $aTime[2] &amp;amp; &amp;quot; &amp;quot; &amp;amp; $aTime[3] &amp;amp; &amp;quot;:&amp;quot; &amp;amp; $aTime[4] &amp;amp; &amp;quot;:&amp;quot; &amp;amp; $aTime[5], @YEAR &amp;amp; &amp;quot;/&amp;quot; &amp;amp; @MON &amp;amp; &amp;quot;/&amp;quot; &amp;amp; @MDAY &amp;amp; &amp;quot; &amp;quot; &amp;amp; @HOUR &amp;amp; &amp;quot;:&amp;quot; &amp;amp; @MIN &amp;amp; &amp;quot;:&amp;quot; &amp;amp; @SEC) &amp;lt; $iHours)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileCheck&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileCreateEx ==&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;
_FileCreateEx(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;, 42)&lt;br /&gt;
&lt;br /&gt;
; Create a blank file with a certain size in bytes.&lt;br /&gt;
Func _FileCreateEx($sFilePath, $iBytes = 0)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c fsutil file createnew &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; Int($iBytes), @WorkingDir, @SW_HIDE)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileCreateEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileID ==&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;
FileClose(FileOpen(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;, 2))&lt;br /&gt;
ConsoleWrite(_FileID(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;) &amp;amp; @CRLF)&lt;br /&gt;
FileDelete(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;)&lt;br /&gt;
&lt;br /&gt;
; Rerieve the file id of a filepath.&lt;br /&gt;
Func _FileID($sFilePath)&lt;br /&gt;
    Local $iPID = Run(@ComSpec &amp;amp; &#039; /c fsutil file queryfileid &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot;&#039;, @SystemDir, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sReturn = &#039;&#039;&lt;br /&gt;
    While 1&lt;br /&gt;
        $sReturn &amp;amp;= StdoutRead($iPID)&lt;br /&gt;
        If @error Then&lt;br /&gt;
            ExitLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
    WEnd&lt;br /&gt;
    Return StringStripWS(StringRegExpReplace($sReturn, &#039;File\sID\sis\s(.*?)&#039;, &#039;$1&#039;), 8)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileExistsWithQuotes ==&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(_FileExistsWithQuotes(&#039;&amp;quot;&#039; &amp;amp; @ScriptDir &amp;amp; &#039;&amp;quot;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_FileExistsWithQuotes(&amp;quot;&#039;&amp;quot; &amp;amp; @ScriptDir &amp;amp; &amp;quot;&#039;&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_FileExistsWithQuotes(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Version: 1.00. AutoIt: V3.3.8.1&lt;br /&gt;
; Check a filepath ecists even if the path contains quotation marks.&lt;br /&gt;
Func _FileExistsWithQuotes($sFilePath)&lt;br /&gt;
    Return FileExists(StringRegExpReplace($sFilePath, &#039;^(&amp;quot;|&#039;&#039;)*([^&amp;quot;&#039;&#039;]+)(&amp;quot;|&#039;&#039;)*$&#039;, &#039;\2&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileExistsWithQuotes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== FileLineCount ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 71214-mkish&lt;br /&gt;
 | AuthorName = MKISH&lt;br /&gt;
 | Desc = Checks the number of lines in a file (useful for larger files as well)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Author - MKISH&lt;br /&gt;
&lt;br /&gt;
; Checks the number of lines in a file (useful for larger files as well)&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local $FILE = &amp;quot;G:\WIN7\sources\boot.wim&amp;quot;&lt;br /&gt;
Local $COUNT = 0&lt;br /&gt;
Local $start = default&lt;br /&gt;
Local $res, $fLen, $err&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
	$res = _HexSearch($FILE, StringToBinary(&amp;quot;&amp;quot; &amp;amp; @crlf), $start)&lt;br /&gt;
	$start = $res + 2&lt;br /&gt;
	$COUNT = $COUNT + 1&lt;br /&gt;
	If $res = -1 then exitloop&lt;br /&gt;
Wend&lt;br /&gt;
&lt;br /&gt;
msgbox(64, &amp;quot;&amp;quot;, &amp;quot;Lines count: &amp;quot; &amp;amp; $COUNT)&lt;br /&gt;
&lt;br /&gt;
; _HexSearch function (originally written by Zinthose, modified by MKISH)&lt;br /&gt;
Func _HexSearch($FilePath, $BinaryValue, $StartOffset = Default)&lt;br /&gt;
        Local $Buffer, $ptr, $hFile, $Result, $Read, $SearchValue, $Pos, $BufferSize = 2048&lt;br /&gt;
            If $StartOffset = Default     Then $StartOffset = 0&lt;br /&gt;
            If Not FileExists($FilePath)    Then    Return SetError(1, @error, 0)&lt;br /&gt;
            $fLen = FileGetSize($FilePath)&lt;br /&gt;
            If $StartOffset &amp;gt; $fLen   Then   Return SetError(2, @error, 0)&lt;br /&gt;
            If Not IsBinary($BinaryValue)   Then    Return SetError(3, @error, 0)&lt;br /&gt;
            If Not IsNumber($StartOffset)   Then    Return SetError(4, @error, 0)&lt;br /&gt;
            $SearchValue = BinaryToString($BinaryValue)&lt;br /&gt;
            $Buffer = DllStructCreate(&amp;quot;byte[&amp;quot; &amp;amp; $BufferSize &amp;amp; &amp;quot;]&amp;quot;)&lt;br /&gt;
            $ptr = DllStructGetPtr($Buffer)&lt;br /&gt;
                $hFile = _WinAPI_CreateFile($FilePath, 2, 2, 1)&lt;br /&gt;
                If $hFile = 0 Then Return SetError(5, @error, 0)&lt;br /&gt;
            $Result = _WinAPI_SetFilePointer($hFile, $StartOffset)&lt;br /&gt;
            $err = @error&lt;br /&gt;
            If $Result = 0xFFFFFFFF Then&lt;br /&gt;
                _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                Return SetError(5, $err, 0)&lt;br /&gt;
            EndIf&lt;br /&gt;
            $Pos = $StartOffset&lt;br /&gt;
            While True&lt;br /&gt;
                    $Read = 0&lt;br /&gt;
                    $Result = _WinAPI_ReadFile($hFile, $ptr, $BufferSize, $Read)&lt;br /&gt;
                    $err = @error&lt;br /&gt;
                    If Not $Result Then&lt;br /&gt;
                        _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                        Return SetError(6, $err, 0)&lt;br /&gt;
                    EndIf&lt;br /&gt;
                    $Result = DllStructGetData($Buffer, 1)&lt;br /&gt;
                    $Result = BinaryToString($Result)&lt;br /&gt;
                    $Result = StringInStr($Result, $SearchValue)&lt;br /&gt;
                    If $Result &amp;gt; 0 Then ExitLoop&lt;br /&gt;
                    If $Read &amp;lt; $BufferSize Then&lt;br /&gt;
                        _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                        Return -1&lt;br /&gt;
                    EndIf&lt;br /&gt;
                    $Pos += $Read&lt;br /&gt;
&lt;br /&gt;
            WEnd&lt;br /&gt;
            _WinAPI_CloseHandle($hFile)&lt;br /&gt;
            If Not $Result Then Return SetError(7, @error, 0)&lt;br /&gt;
            $Result = $Pos + $Result - 1&lt;br /&gt;
            Return $Result&lt;br /&gt;
    EndFunc; ==&amp;gt; _HexSearch&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileOpenDialog ==&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;
Local $sFilePath = _FileOpenDialog(&amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;Images (*.jpg;*.bmp)|Videos (*.avi;*.mpg)&amp;quot;, Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1), 1 + 4, &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;File = &#039; &amp;amp; $sFilePath &amp;amp; &#039;, @error = &#039; &amp;amp; @error &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name ..........: _FileOpenDialog&lt;br /&gt;
; Description ...: Initiates a Open File Dialog with the option to set the position of the GUI.&lt;br /&gt;
; Syntax ........: _FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter[, $iLeft = -1[, $iTop = -1[, $iOptions = 0[,&lt;br /&gt;
;                  $sDefaultName = &amp;quot;&amp;quot;]]]])&lt;br /&gt;
; Parameters ....: $sTitle              - Title text of the Dialog GUI.&lt;br /&gt;
;                  $sIntitialDirectory  - Initial directory selected in the GUI file tree.&lt;br /&gt;
;                  $sFilter             - File type single filter such as &amp;quot;All (*.*)&amp;quot; or &amp;quot;Text files (*.txt)&amp;quot;.&lt;br /&gt;
;                  $iLeft               - [optional] The left side of the dialog box. By default (-1), the window is centered.&lt;br /&gt;
;                  $iTop                - [optional] The top of the dialog box. Default (-1) is centered&lt;br /&gt;
;                  $iOptions            - [optional] Dialog Options: To use more than one option, add the required values together. See FileOpenDialog. Default is 0.&lt;br /&gt;
;                  $sDefaultName        - [optional] Suggested file name for the user to open. Default is blank (&amp;quot;&amp;quot;).&lt;br /&gt;
; Return values .: Success: Returns the full path of the file(s) chosen. Results for multiple selections are &amp;quot;Directory|file1|file2|...&amp;quot;&lt;br /&gt;
;                  Failure: Sets @error to non-zero.&lt;br /&gt;
; Author ........: guinness&lt;br /&gt;
; Remarks........: This doesn&#039;t change the working directory of the script like FileOpenDialog does.&lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter, $iLeft = -1, $iTop = -1, $iOptions = 0, $sDefaultName = &amp;quot;&amp;quot;)&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;, -1, -1, $iLeft, $iTop), $sWorkingDir = @WorkingDir&lt;br /&gt;
    Local $sFilePath = FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter, $iOptions, $sDefaultName, $hGUI)&lt;br /&gt;
    Local $iError = @error&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return SetError($iError, GUIDelete($hGUI), $sFilePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileOpenDialog()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileRename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 52374-johnone&lt;br /&gt;
 | AuthorName = JohnOne&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;### Rename a file ###&lt;br /&gt;
;$sFile = Full path to file&lt;br /&gt;
;$sRename = New Filename&lt;br /&gt;
;$iOverWrite = 0 or 1&lt;br /&gt;
&lt;br /&gt;
;Success returns 1&lt;br /&gt;
;failure, returns 0 and sets @error&lt;br /&gt;
; 1 if FileMove fails, &lt;br /&gt;
; 2 if $sFile does not exist&lt;br /&gt;
;@extended&lt;br /&gt;
; 0 if the new file does not already exist / existed&lt;br /&gt;
; 1 if the new file already exists / existed&lt;br /&gt;
&lt;br /&gt;
;#### Example ####&lt;br /&gt;
$File = @ScriptDir &amp;amp; &#039;\filetorename.txt&#039;&lt;br /&gt;
FileWrite($File, &#039;Test&#039;)&lt;br /&gt;
_FileRename($File, &#039;newname.txt&#039;)&lt;br /&gt;
If @error Then MsgBox(0, &amp;quot;Error&amp;quot;, @error)&lt;br /&gt;
&lt;br /&gt;
Func _FileRename($sFile, $sRename, $iOverWrite = 0)&lt;br /&gt;
    Local Const $FILENOTEXIST = 2&lt;br /&gt;
    If Not FileExists($sFile) Then Return SetError($FILENOTEXIST, 0, 0)&lt;br /&gt;
    Local $_StringLen = StringLen($sFile)&lt;br /&gt;
    Local $_StringInStr = StringInStr($sFile, &amp;quot;\&amp;quot;, 0, -1, $_StringLen)&lt;br /&gt;
    Local $_Count = $_StringLen - $_StringInStr&lt;br /&gt;
    Local $_Dir = StringLeft($sFile, $_StringInStr)&lt;br /&gt;
    Local $_NewFile = $_Dir &amp;amp; $sRename&lt;br /&gt;
    Local $_NewFileExists = FileExists($_NewFile)&lt;br /&gt;
    Local $_FileMove = FileMove($sFile, $_NewFile, $iOverWrite)&lt;br /&gt;
    Return SetError(Not $_FileMove, $_NewFileExists, $_FileMove)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileRename&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== _FileRename Alternative ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;FileRename(PathFile, RenameFile)&lt;br /&gt;
;JohnOne&lt;br /&gt;
&lt;br /&gt;
FileRename(@ScriptDir &amp;amp; &amp;quot;\rename.txt&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\renamed.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func FileRename($FileName, $ReName)&lt;br /&gt;
&lt;br /&gt;
	Local $SHFILEOPSTRUCT, $SourceStruct, $DestStruct&lt;br /&gt;
	Local Const $FO_RENAME = 0x0004&lt;br /&gt;
	Local Const $FOF_SILENT = 0x0004&lt;br /&gt;
	Local Const $FOF_NOCONFIRMATION = 0x0010&lt;br /&gt;
	Local Const $FOF_NOERRORUI = 0x0400&lt;br /&gt;
	Local Const $FOF_NOCONFIRMMKDIR = 0x0200&lt;br /&gt;
	Local Const $NULL = 0&lt;br /&gt;
&lt;br /&gt;
	$SourceStruct = _StringToStruct($FileName)&lt;br /&gt;
	$DestStruct = _StringToStruct($ReName)&lt;br /&gt;
&lt;br /&gt;
	$SHFILEOPSTRUCT = DllStructCreate(&amp;quot;hwnd hWnd;uint wFunc;ptr pFrom;ptr pTo;int fFlags;int fAnyOperationsAborted;ptr hNameMappings;ptr lpszProgressTitle&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;hWnd&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;wFunc&amp;quot;, $FO_RENAME)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;pFrom&amp;quot;, DllStructGetPtr($SourceStruct))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;pTo&amp;quot;, DllStructGetPtr($DestStruct))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;fFlags&amp;quot;, BitOR($FOF_SILENT, $FOF_NOCONFIRMATION, $FOF_NOERRORUI, $FOF_NOCONFIRMMKDIR))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;fAnyOperationsAborted&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;hNameMappings&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;lpszProgressTitle&amp;quot;, $NULL)&lt;br /&gt;
&lt;br /&gt;
	$acall = DllCall(&amp;quot;shell32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;SHFileOperation&amp;quot;, &amp;quot;ptr&amp;quot;, DllStructGetPtr($SHFILEOPSTRUCT))&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Return SetError(@error, @extended, 0)&lt;br /&gt;
	EndIf&lt;br /&gt;
	Return 1&lt;br /&gt;
EndFunc   ;==&amp;gt;FileRename&lt;br /&gt;
&lt;br /&gt;
Func _StringToStruct($string)&lt;br /&gt;
&lt;br /&gt;
	Local $iLen = StringLen($string)&lt;br /&gt;
	Local $Struct = DllStructCreate(&amp;quot;char[&amp;quot; &amp;amp; String($iLen + 2) &amp;amp; &amp;quot;]&amp;quot;)&lt;br /&gt;
	DllStructSetData($Struct, 1, $string)&lt;br /&gt;
	DllStructSetData($Struct, 1, 0, $iLen + 1)&lt;br /&gt;
	DllStructSetData($Struct, 1, 0, $iLen + 2)&lt;br /&gt;
&lt;br /&gt;
	Return $Struct&lt;br /&gt;
EndFunc   ;==&amp;gt;_StringToStruct&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFolderDepth ==&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;
; Autoit 3.3.5.4 and Below&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir &amp;amp; &#039;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the folder depth of a filepath.&lt;br /&gt;
Func _GetFolderDepth($sFilePath)&lt;br /&gt;
    If StringInStr($sFilePath, &#039;.&#039;, 2, -1) Then&lt;br /&gt;
        $sFilePath = StringLeft($sFilePath, StringInStr($sFilePath, &amp;quot;&amp;quot;, 2, -1) - 1)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $aArray = StringSplit(StringRegExpReplace($sFilePath, &#039;[/]+z&#039;, &#039;&#039;), &#039;&#039;)&lt;br /&gt;
    Return $aArray[0] - 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFolderDepth&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFolderDepth ==&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;
; Autoit 3.3.5.4 and Above&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir &amp;amp; &#039;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the folder depth of a filepath. Works with V3.3.5.4+&lt;br /&gt;
Func _GetFolderDepth($sFilePath)&lt;br /&gt;
    If StringInStr($sFilePath, &#039;.&#039;, 2, -1) Then&lt;br /&gt;
        $sFilePath = StringLeft($sFilePath, StringInStr($sFilePath, &amp;quot;&amp;quot;, 2, -1) - 1)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return StringSplit(StringRegExpReplace($sFilePath, &#039;[/]+z&#039;, &#039;&#039;), &#039;&#039;)[0] - 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFolderDepth&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsDir ==&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;IsDir: Using a file - &amp;quot; &amp;amp; IsDir(@ScriptFullPath) &amp;amp; @CRLF) ; Return 0&lt;br /&gt;
ConsoleWrite(&amp;quot;IsFile: Using a file - &amp;quot; &amp;amp; IsFile(@ScriptFullPath) &amp;amp; @CRLF) ; Return 1&lt;br /&gt;
ConsoleWrite(&amp;quot;IsDir: Using a directory - &amp;quot; &amp;amp; IsDir(@ScriptDir) &amp;amp; @CRLF) ; Return 1&lt;br /&gt;
ConsoleWrite(&amp;quot;IsFile: Using a directory - &amp;quot; &amp;amp; IsFile(@ScriptDir) &amp;amp; @CRLF) ; Return 0&lt;br /&gt;
&lt;br /&gt;
Func IsDir($sFilePath)&lt;br /&gt;
    Return Number(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), &amp;quot;D&amp;quot;, 2, 1) &amp;gt; 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;IsDir&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFile ==&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;
Func IsFile($sFilePath)&lt;br /&gt;
    Return Number(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), &amp;quot;D&amp;quot;, 2, 1) = 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;IsFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileDiff ==&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(_IsFileDiff(@ScriptFullPath, @ScriptFullPath) &amp;amp; @CRLF) ; This will return False as the files are exactly the same.&lt;br /&gt;
ConsoleWrite(_IsFileDiff(@ScriptFullPath, @AutoItExe) &amp;amp; @CRLF) ; This will return True as the files are different.&lt;br /&gt;
&lt;br /&gt;
; Check if a file is different.&lt;br /&gt;
Func _IsFileDiff($sFilePath_1, $sFilePath_2)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c FC /B /W &amp;quot;&#039; &amp;amp; $sFilePath_1 &amp;amp; &#039;&amp;quot; &amp;quot;&#039; &amp;amp; $sFilePath_2 &amp;amp; &#039;&amp;quot;&#039;, @WorkingDir, @SW_HIDE) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileDiff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileOlder ==&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;Date.au3&amp;gt; ; Required for _DateDiff()&lt;br /&gt;
&lt;br /&gt;
; Check if the current script is older than 10 days.&lt;br /&gt;
If _IsFileOlder(@ScriptFullPath, 10) Then&lt;br /&gt;
	MsgBox(4096, &#039;&#039;, &#039;File is older than 10 days.&#039;)&lt;br /&gt;
Else&lt;br /&gt;
	MsgBox(4096, &#039;&#039;, &#039;File isn&#039;&#039;t older than 10 days.&#039;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
; Is a file older than a certain number of days.&lt;br /&gt;
Func _IsFileOlder($sFilePath, $iDays)&lt;br /&gt;
	Local $aArray = FileGetTime($sFilePath, 0)&lt;br /&gt;
	Return _DateDiff(&#039;D&#039;, $aArray[0] &amp;amp; &#039;/&#039; &amp;amp; $aArray[1] &amp;amp; &#039;/&#039; &amp;amp; $aArray[2] &amp;amp; &#039; &#039; &amp;amp; $aArray[3] &amp;amp; &#039;:&#039; &amp;amp; $aArray[4] &amp;amp; &#039;:&#039; &amp;amp; $aArray[5], @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) &amp;gt;= $iDays&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileOlder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileSame ==&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(_IsFileSame(@ScriptFullPath, @ScriptFullPath) &amp;amp; @CRLF) ; This will return True as the files are exactly the same.&lt;br /&gt;
ConsoleWrite(_IsFileSame(@ScriptFullPath, @AutoItExe) &amp;amp; @CRLF) ; This will return False as the files are different.&lt;br /&gt;
&lt;br /&gt;
; Check if a file is the same.&lt;br /&gt;
Func _IsFileSame($sFilePath_1, $sFilePath_2)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c FC /B /W &amp;quot;&#039; &amp;amp; $sFilePath_1 &amp;amp; &#039;&amp;quot; &amp;quot;&#039; &amp;amp; $sFilePath_2 &amp;amp; &#039;&amp;quot;&#039;, @WorkingDir, @SW_HIDE) = 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileSame&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IniReadFile ==&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;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__INIFileFill(@ScriptDir &amp;amp; &#039;\Example.ini&#039;) ; Create an INI file with random data.&lt;br /&gt;
&lt;br /&gt;
Local $aArray = _IniReadFile(@ScriptDir &amp;amp; &#039;\Example.ini&#039;)&lt;br /&gt;
FileDelete(@ScriptDir &amp;amp; &#039;\Example.ini&#039;)&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&lt;br /&gt;
Func _IniReadFile($sFilePath)&lt;br /&gt;
    Local $aReturn[1][3] = [[0, 3]], $aSectionArray, $aSectionNameArray, $iCount = 0&lt;br /&gt;
    $aSectionNameArray = IniReadSectionNames($sFilePath)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $aReturn)&lt;br /&gt;
    EndIf&lt;br /&gt;
    For $A = 1 To $aSectionNameArray[0]&lt;br /&gt;
        $aSectionArray = IniReadSection($sFilePath, $aSectionNameArray[$A])&lt;br /&gt;
        If @error Then&lt;br /&gt;
            ContinueLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
        For $B = 1 To $aSectionArray[0][0]&lt;br /&gt;
            $aReturn[0][0] += 1&lt;br /&gt;
            $iCount += 1&lt;br /&gt;
            If $aReturn[0][0] &amp;lt;= $iCount + 1 Then&lt;br /&gt;
                ReDim $aReturn[$aReturn[0][0] * 2][$aReturn[0][1]]&lt;br /&gt;
            EndIf&lt;br /&gt;
            $aReturn[$iCount][0] = $aSectionArray[$B][0]&lt;br /&gt;
            $aReturn[$iCount][1] = $aSectionArray[$B][1]&lt;br /&gt;
            $aReturn[$iCount][2] = $aSectionNameArray[$A]&lt;br /&gt;
        Next&lt;br /&gt;
    Next&lt;br /&gt;
    ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1]] ; Remove empty entries.&lt;br /&gt;
    Return $aReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_IniReadFile&lt;br /&gt;
&lt;br /&gt;
Func __INIFileFill($sFilePath)&lt;br /&gt;
    Local $sData = &#039;&#039;, $sHeader = &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To Random(1, 5, 1)&lt;br /&gt;
        $sHeader = _RandomText(Random(5, 25, 1))&lt;br /&gt;
        $sData = &amp;quot;&amp;quot;&lt;br /&gt;
        For $j = 1 To Random(1, 25, 1)&lt;br /&gt;
            $sData &amp;amp;= _RandomText(Random(5, 25, 1)) &amp;amp; &#039;=&#039; &amp;amp; _RandomText(Random(5, 25, 1)) &amp;amp; @LF&lt;br /&gt;
        Next&lt;br /&gt;
        IniWriteSection($sFilePath, $sHeader, $sData)&lt;br /&gt;
    Next&lt;br /&gt;
EndFunc   ;==&amp;gt;__FillINIFile&lt;br /&gt;
&lt;br /&gt;
Func _RandomText($iLength = 10)&lt;br /&gt;
    Local $sData = &#039;&#039;, $sRandom = &#039;&#039;&lt;br /&gt;
    For $i = 1 To $iLength&lt;br /&gt;
        $sRandom = Random(55, 116, 1)&lt;br /&gt;
        $sData &amp;amp;= Chr($sRandom + 6 * ($sRandom &amp;gt; 90) - 7 * ($sRandom &amp;lt; 65))&lt;br /&gt;
    Next&lt;br /&gt;
    Return $sData&lt;br /&gt;
EndFunc   ;==&amp;gt;_RandomText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IniReadInit ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 9370-mlowery&lt;br /&gt;
 | AuthorName = mlowery&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;===============================================================================&lt;br /&gt;
; Description:     Reads values from INI or creates INI with initial values.&lt;br /&gt;
;                  Intended to ensure all available INI settings are exposed&lt;br /&gt;
;                  and editable.&lt;br /&gt;
;                  Parameters are identical to IniRead()&lt;br /&gt;
; Parameter(s):    $filename  = filename of INI&lt;br /&gt;
;                  $section  = section name of INI&lt;br /&gt;
;                  $key      = key name in section&lt;br /&gt;
;                  $default  = default value (written to INI if not exists)&lt;br /&gt;
; Requirement(s):  None&lt;br /&gt;
; Return Value(s): Returns value from INI (or default if not defined)&lt;br /&gt;
; Note(s):         Chr(127) used to detect non-existing value since won&#039;t normally exist in a text file&lt;br /&gt;
;===============================================================================&lt;br /&gt;
Func _IniReadInit($filename, $section, $key, $default)&lt;br /&gt;
  Local $value = IniRead($filename, $section, $key, Chr(127))&lt;br /&gt;
    If $value = Chr(127) Then&lt;br /&gt;
      IniWrite($filename, $section, $key, $default)&lt;br /&gt;
      $value = $default&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $value&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsValidFileType ==&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(@ScriptFullPath &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@ScriptFullPath, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(@AutoItExe &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@AutoItExe, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a filepath matches an extension filetype. Based on the idea by guinness - http://www.autoitscript.com/forum/topic/123674-isvalidfiletype/&lt;br /&gt;
Func _IsValidFileType($sFilePath, $sList = &amp;quot;bat;cmd;exe&amp;quot;) ; By AZJIO - http://www.autoitscript.com/forum/topic/...filetype/page__view__findpost_&lt;br /&gt;
    Local $iDot = StringInStr($sFilePath, &amp;quot;.&amp;quot;, 0, -1)&lt;br /&gt;
    Return $iDot And StringInStr(&#039;;&#039; &amp;amp; $sList &amp;amp; &#039;;&#039;, &#039;;&#039; &amp;amp; StringTrimLeft($sFilePath, $iDot) &amp;amp; &#039;;&#039;) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsValidFileType&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;
; Example 2&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(@ScriptFullPath &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@ScriptFullPath, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(@AutoItExe &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@AutoItExe, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a filepath matches an extension filetype. Based on the idea by guinness - http://www.autoitscript.com/forum/topic/123674-isvalidfiletype/&lt;br /&gt;
Func _IsValidFileType($sFilePath, $sList = &amp;quot;bat;cmd;exe&amp;quot;, $iOpFast = 1) ; By Yashied.&lt;br /&gt;
    If StringStripWS($sList, 8) = &amp;quot;&amp;quot; Then&lt;br /&gt;
        $sList = &amp;quot;*&amp;quot;&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return _WinAPI_PathMatchSpec($sFilePath, StringReplace(&#039;;&#039; &amp;amp; $sList, &#039;;&#039;, &#039;;*.&#039;, 0, $iOpFast * 2))&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsValidFileType&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== File Open/Save/Folder Dialog Box ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 2709-mhz&lt;br /&gt;
 | AuthorName = MHz&lt;br /&gt;
 | AuthorURL2 = 4997-odklizec&lt;br /&gt;
 | AuthorName2 = odklizec&lt;br /&gt;
 | AuthorURL3 = 6756-danny35d&lt;br /&gt;
 | AuthorName3 = Danny35d&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Center - File Open/Save/Folder Dialog Box&lt;br /&gt;
; Author - odklizec, MHz, Danny35d&lt;br /&gt;
&lt;br /&gt;
 If StringInStr($cmdlineraw, &#039;/MoveWin&#039;) Then&lt;br /&gt;
	 Local $size, $PosX, $PosY&lt;br /&gt;
     $cmdlineraw = StringSplit(StringMid($cmdlineraw, StringInStr($cmdlineraw, &#039;/MoveWin&#039;)), &#039;:&#039;)&lt;br /&gt;
     While 1&lt;br /&gt;
         Select&lt;br /&gt;
         Case WinExists($cmdlineraw[2])&lt;br /&gt;
             $size=WinGetPos ($cmdlineraw[2])&lt;br /&gt;
             $PosX=@DesktopWidth/2 - $size[2]/2&lt;br /&gt;
             $PosY=@DesktopHeight/2 - $size[3]/2&lt;br /&gt;
             WinMove($cmdlineraw[2], &amp;quot;&amp;quot;, $PosX, $PosY)&lt;br /&gt;
             WinActivate($cmdlineraw[2])&lt;br /&gt;
             ExitLoop&lt;br /&gt;
         EndSelect&lt;br /&gt;
         Sleep(50)&lt;br /&gt;
     WEnd&lt;br /&gt;
     Exit&lt;br /&gt;
 EndIf&lt;br /&gt;
Global $PID, $Read_File, $Save_File&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Open file Dialog Box&#039;)&lt;br /&gt;
 $Read_File = FileOpenDialog ( &amp;quot;Open file Dialog Box&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\&amp;quot;, &amp;quot;AutoIt Files (*.au3)&amp;quot;,3,@ScriptFullPath)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Save file Dialog Box&#039;)&lt;br /&gt;
 $Save_File = FileSaveDialog( &amp;quot;Save file Dialog Box&amp;quot;, @ScriptDir, &amp;quot;Scripts (*.aut;*.au3)&amp;quot;, 3)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Browse for Folder&#039;)&lt;br /&gt;
 FileSelectFolder(&amp;quot;Choose a folder with plugins..&amp;quot;, &amp;quot;&amp;quot;,&amp;quot;4&amp;quot;,&amp;quot;c:\&amp;quot;)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
&lt;br /&gt;
 Func _FindBrowseWin($sTitle)&lt;br /&gt;
     If @Compiled Then&lt;br /&gt;
         Return(Run(@ScriptFullPath &amp;amp; &#039; /MoveWin:&#039; &amp;amp; $sTitle))&lt;br /&gt;
     Else&lt;br /&gt;
         Return(Run(@AutoItExe &amp;amp; &#039; &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot; /MoveWin:&#039; &amp;amp; $sTitle))&lt;br /&gt;
     EndIf&lt;br /&gt;
 EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _MoveFileOnReboot ==&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.2.0, Creation Date = 21/03/12.&lt;br /&gt;
&lt;br /&gt;
; Function to Move or Delete a file on next reboot!&lt;br /&gt;
Func _MoveFileOnReboot($sSourcePath, $sDestPath = &amp;quot;&amp;quot;); If $sDestPath = &amp;quot;&amp;quot; the file is deleted instead of moved.&lt;br /&gt;
    Local $iRet&lt;br /&gt;
&lt;br /&gt;
    ; PendingFileRenameOperations (HKLM\SYSTEM\CurrentControlSet\Control\Session Manager)&lt;br /&gt;
    If $DestPath = &amp;quot;&amp;quot; Then&lt;br /&gt;
        $iRet = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;MoveFileExA&amp;quot;, &amp;quot;str&amp;quot;, $sSourcePath, &amp;quot;int&amp;quot;, 0, &amp;quot;dword&amp;quot;, 4)&lt;br /&gt;
    Else&lt;br /&gt;
        $iRet = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;MoveFileExA&amp;quot;, &amp;quot;str&amp;quot;, $sSourcePath, &amp;quot;str&amp;quot;, $sDestPath, &amp;quot;dword&amp;quot;, 4)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return $iRet&lt;br /&gt;
EndFunc   ;==&amp;gt;_MoveFileOnReboot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _MultipleFileOpenDialog ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL =&lt;br /&gt;
 | AuthorName = /dev/null&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Local $message = &amp;quot;Hold down Ctrl or Shift to choose multiple files.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Local $filename = _MultipleFileOpenDialog($message,300,300)&lt;br /&gt;
&lt;br /&gt;
Local $var = FileOpenDialog($message, @WindowsDir &amp;amp; &amp;quot;\&amp;quot;, &amp;quot;Images (*.jpg;*.bmp)&amp;quot;, 1 + 4 )&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    MsgBox(4096,&amp;quot;&amp;quot;,&amp;quot;No File(s) chosen&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
    $var = StringReplace($var, &amp;quot;|&amp;quot;, @CRLF)&lt;br /&gt;
    MsgBox(4096,&amp;quot;&amp;quot;,&amp;quot;You chose &amp;quot; &amp;amp; $var)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
FileDelete($filename)&lt;br /&gt;
func _MultipleFileOpenDialog($title,$posx,$posy)&lt;br /&gt;
    Local $temp = EnvGet(&amp;quot;temp&amp;quot;)&lt;br /&gt;
    Local $filename = $temp &amp;amp; &amp;quot;\move_file_open_dialog.au3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    Local $script = &#039;Global $title = &amp;quot;&#039; &amp;amp; $title &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Global $pos_x = &#039; &amp;amp; $posx &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Global $pos_y = &#039; &amp;amp; $posy &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;AdlibRegister(&amp;quot;_Move&amp;quot;,10)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;while 1&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;    sleep(1000)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;wend&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Func _Move()&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;   if (WinActive($title)) Then&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;      WinMove($title,&amp;quot;&amp;quot;,$pos_x,$pos_y)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;      Exit&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;   EndIf&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;EndFunc&#039; &amp;amp; @CRLF&lt;br /&gt;
&lt;br /&gt;
    FileWrite($filename,$script)&lt;br /&gt;
    ;MsgBox(0,&amp;quot;&amp;quot;,$script &amp;amp; @CRLF &amp;amp; $filename)&lt;br /&gt;
    Run(@AutoItExe &amp;amp; &amp;quot; /AutoIt3ExecuteScript &amp;quot; &amp;amp; $filename)&lt;br /&gt;
    sleep(250)&lt;br /&gt;
    Return $filename&lt;br /&gt;
EndFunc ;==&amp;gt;_MultipleFileOpenDialog()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _OpenFolder ==&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;
#cs&lt;br /&gt;
    These have been declared in Global scope as you may wish to use them elsewhere in your script.&lt;br /&gt;
#ce&lt;br /&gt;
Global $ALTSTARTUP = 0x1d&lt;br /&gt;
Global $APPDATA = 0x1a&lt;br /&gt;
Global $BITBUCKET = 0x0a&lt;br /&gt;
Global $COMMONALTSTARTUP = 0x1e&lt;br /&gt;
Global $COMMONAPPDATA = 0x23&lt;br /&gt;
Global $COMMONDESKTOPDIR = 0x19&lt;br /&gt;
Global $COMMONFAVORITES = 0x1f&lt;br /&gt;
Global $COMMONPROGRAMS = 0x17&lt;br /&gt;
Global $COMMONSTARTMENU = 0x16&lt;br /&gt;
Global $COMMONSTARTUP = 0x18&lt;br /&gt;
Global $CONTROLS = 0x03&lt;br /&gt;
Global $COOKIES = 0x21&lt;br /&gt;
Global $DESKTOP = 0x00&lt;br /&gt;
Global $DESKTOPDIRECTORY = 0x10&lt;br /&gt;
Global $DRIVES = 0x11&lt;br /&gt;
Global $FAVORITES = 0x06&lt;br /&gt;
Global $FONTS = 0x14&lt;br /&gt;
Global $HISTORY = 0x22&lt;br /&gt;
Global $INTERNETCACHE = 0x20&lt;br /&gt;
Global $LOCALAPPDATA = 0x1c&lt;br /&gt;
Global $MYPICTURES = 0x27&lt;br /&gt;
Global $NETHOOD = 0x13&lt;br /&gt;
Global $NETWORK = 0x12&lt;br /&gt;
Global $PERSONAL = 0x05&lt;br /&gt;
Global $PRINTERS = 0x04&lt;br /&gt;
Global $PRINTHOOD = 0x1b&lt;br /&gt;
Global $PROFILE = 0x28&lt;br /&gt;
Global $PROGRAMFILES = 0x26&lt;br /&gt;
Global $PROGRAMFILESx86 = 0x30&lt;br /&gt;
Global $PROGRAMS = 0x02&lt;br /&gt;
Global $RECENT = 0x08&lt;br /&gt;
Global $SENDTO = 0x09&lt;br /&gt;
Global $STARTMENU = 0x0b&lt;br /&gt;
Global $STARTUP = 0x07&lt;br /&gt;
Global $SYSTEM = 0x25&lt;br /&gt;
Global $SYSTEMx86 = 0x29&lt;br /&gt;
Global $TEMPLATES = 0x15&lt;br /&gt;
Global $WINDOWS = 0x24&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_OpenFolder(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_OpenFolder($PRINTERS) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Open a folder or special folder variable, similar to using ShellExecute.&lt;br /&gt;
Func _OpenFolder($sFolderPath)&lt;br /&gt;
    Local $oShell = ObjCreate(&#039;shell.application&#039;)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $oShell.Open($sFolderPath)&lt;br /&gt;
    Return 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_OpenFolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _PathAppendToFilename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 31965-progandy&lt;br /&gt;
 | AuthorName = ProgAndy&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
$sOrg = &amp;quot;C:\Some.Folder\some.file.ext&amp;quot;&lt;br /&gt;
$sAdd = &amp;quot;_backup&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$sNew = _PathAppendToFilename($sOrg, $sAdd)&lt;br /&gt;
&lt;br /&gt;
$sStripped = _PathStripRightFromFilename($sNew, $sAdd)&lt;br /&gt;
&lt;br /&gt;
MsgBox(0, &amp;quot;&amp;quot;, $sOrg &amp;amp; @CRLF &amp;amp; $sAdd &amp;amp; @CRLF &amp;amp; $sNew &amp;amp; @CRLF &amp;amp; $sStripped)&lt;br /&gt;
&lt;br /&gt;
Func _PathAppendToFilename($sName, $sAppend)&lt;br /&gt;
    ; Author: ProgAndy&lt;br /&gt;
    If StringRegExp($sAppend, &#039;[\/\\:\?&amp;quot;&amp;lt;&amp;gt;\|\*]&#039;) Then Return SetError(1, 0, $sName)&lt;br /&gt;
    Return StringRegExpReplace($sName, &amp;quot;(\.[^\\/\.]+)$&amp;quot;, $sAppend &amp;amp; &amp;quot;\1&amp;quot;, 1)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _PathStripRightFromFilename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 31965-progandy&lt;br /&gt;
 | AuthorName = ProgAndy&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Func _PathStripRightFromFilename($sName, $sStrip)&lt;br /&gt;
    ; Author: ProgAndy&lt;br /&gt;
    If StringRegExp($sStrip, &#039;[\/\\:\?&amp;quot;&amp;lt;&amp;gt;\|\*]&#039;) Then Return SetError(1, 0, $sName)&lt;br /&gt;
    Return StringRegExpReplace($sName, &amp;quot;\Q&amp;quot; &amp;amp; $sStrip &amp;amp; &amp;quot;\E(\.[^\\/\.]+)$&amp;quot;, &amp;quot;\1&amp;quot;, 1)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SelfDelete ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 2709-mhz&lt;br /&gt;
 | AuthorName = MHz&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; This also removes the directory which the file is in&lt;br /&gt;
; Author MHz with the directory delete addition by The Kandie Man&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;:loop2&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;rmdir /q &amp;quot;&#039; &amp;amp; $dirToDelete &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;if exist &amp;quot;&#039; &amp;amp; $dirToDelete &amp;amp; &#039;&amp;quot; goto loop2&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;del &#039; &amp;amp; @TempDir &amp;amp; &#039;\scratch.bat&#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&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ShellExecuteFileSelectFolder ==&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(_ShellExecuteFileSelectFolder(&#039;Select a Folder&#039;, @HomeDrive) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Shell Execute a selected folder.&lt;br /&gt;
Func _ShellExecuteFileSelectFolder($sText, $sRoot, $iFlag = 0, $sInitialDir = &#039;&#039;, $hWnd = &#039;&#039;)&lt;br /&gt;
    Local $sFolder = FileSelectFolder($sText, $sRoot, $iFlag, $sInitialDir, $hWnd)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(@error, @extended, &#039;&#039;)&lt;br /&gt;
    EndIf&lt;br /&gt;
    ShellExecute($sFolder)&lt;br /&gt;
    Return $sFolder&lt;br /&gt;
EndFunc   ;==&amp;gt;_ShellExecuteFileSelectFolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SuiCide ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 28010-larrydalooza&lt;br /&gt;
 | AuthorName = LarryDalooza&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; IMPORTANT MAKE A COPY OF SCRIPT BEFORE DELETION&lt;br /&gt;
; Deletes the running script&lt;br /&gt;
&lt;br /&gt;
Func SuiCide()&lt;br /&gt;
	Local $sFilePath = @TempDir &amp;amp; &#039;\SuiCide.bat&#039;&lt;br /&gt;
	FileDelete($sFilePath)&lt;br /&gt;
	FileWrite($sFilePath, &#039;loop:&#039; &amp;amp; @CRLF &amp;amp; &#039;del &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
			&#039;ping -n 1 -w 250 zxywqxz_q&#039; &amp;amp; @CRLF &amp;amp; &#039;if exist &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; _&lt;br /&gt;
			&#039;&amp;quot; goto loop&#039; &amp;amp; @CRLF &amp;amp; &#039;del SuiCide.bat&#039; &amp;amp; @CRLF)&lt;br /&gt;
	Exit Run($sFilePath, @TempDir, @SW_HIDE)&lt;br /&gt;
EndFunc   ;==&amp;gt;SuiCide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _UniqueFilename ==&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;
&lt;br /&gt;
ConsoleWrite(_UniqueFilename(@ScriptDir, &#039;.au3&#039;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _UniqueFilename($sFilePath, $sExtension)&lt;br /&gt;
    Local $iRandom = 0, $sUnqiueFileName = &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
    $sExtension = &#039;.&#039; &amp;amp; StringRegExpReplace($sExtension, &#039;\A[\.]+&#039;, &#039;&#039;)&lt;br /&gt;
    $sFilePath = StringRegExpReplace($sFilePath, &#039;[\\/]+\z&#039;, &#039;&#039;) &amp;amp; &#039;\&#039;&lt;br /&gt;
    While 1&lt;br /&gt;
        $iRandom = Random(55, 116, 1)&lt;br /&gt;
        $sUnqiueFileName &amp;amp;= Chr($iRandom + 6 * ($iRandom &amp;gt; 90) - 7 * ($iRandom &amp;lt; 65))&lt;br /&gt;
        If FileExists($sFilePath &amp;amp; $sUnqiueFileName &amp;amp; $sExtension) = 0 And StringLen($sUnqiueFileName) &amp;gt; 7 Then&lt;br /&gt;
            ExitLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
    WEnd&lt;br /&gt;
    Return $sFilePath &amp;amp; $sUnqiueFileName &amp;amp; $sExtension&lt;br /&gt;
EndFunc   ;==&amp;gt;_UniqueFilename&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Windows - Copy With Progress ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 19-jos&lt;br /&gt;
 | AuthorName = Jos&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Windows - Copy With Progress&lt;br /&gt;
&lt;br /&gt;
;~ 4 Do not display a progress dialog box.&lt;br /&gt;
;~ 8 Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.&lt;br /&gt;
;~ 16 Respond with &amp;quot;Yes to All&amp;quot; for any dialog box that is displayed.&lt;br /&gt;
;~ 64 Preserve undo information, if possible.&lt;br /&gt;
;~ 128 Perform the operation on files only if a wildcard file name (*.*) is specified.&lt;br /&gt;
;~ 256 Display a progress dialog box but do not show the file names.&lt;br /&gt;
;~ 512 Do not confirm the creation of a new directory if the operation requires one to be created.&lt;br /&gt;
;~ 1024 Do not display a user interface if an error occurs.&lt;br /&gt;
;~ 2048 Version 4.71. Do not copy the security attributes of the file.&lt;br /&gt;
;~ 4096 Only operate in the local directory. Don&#039;t operate recursively into subdirectories.&lt;br /&gt;
;~ 8192 Version 5.0. Do not copy connected files as a group. Only copy the specified files.&lt;br /&gt;
&lt;br /&gt;
_FileCopy(&amp;quot;C:\Installed Apps\Patches\WindowsXP-KB835935-SP2-ENU.exe&amp;quot;,&amp;quot;C:\temp&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
; to copy a directory the destination directory must exist&lt;br /&gt;
&lt;br /&gt;
Func _FileCopy($fromFile,$tofile)&lt;br /&gt;
    Local $FOF_RESPOND_YES = 16&lt;br /&gt;
    Local $FOF_SIMPLEPROGRESS = 256&lt;br /&gt;
    $winShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
    $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_Files_%26_Folders_)&amp;diff=12405</id>
		<title>Snippets ( Files &amp; Folders )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_Files_%26_Folders_)&amp;diff=12405"/>
		<updated>2014-05-12T19:21:05Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* DropFiles */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
[[category:Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Snippet Credit Header}}&lt;br /&gt;
&lt;br /&gt;
== _ConvertFileToUTF16 ==&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;
_ConvertFileToUTF16(@ScriptDir &amp;amp; &amp;quot;\Example.xml&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func _ConvertFileToUTF16($sFilePath)&lt;br /&gt;
    Local $iEncoding = FileGetEncoding($sFilePath)&lt;br /&gt;
    Local $hFileOpen = FileOpen($sFilePath, $iEncoding)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $sData = FileRead($hFileOpen)&lt;br /&gt;
    FileClose($hFileOpen)&lt;br /&gt;
&lt;br /&gt;
    $hFileOpen = FileOpen($sFilePath, 2 + 32)&lt;br /&gt;
    If $hFileOpen = -1 Then&lt;br /&gt;
        Return SetError(2, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    FileWrite($hFileOpen, $sData)&lt;br /&gt;
    Return FileClose($hFileOpen)&lt;br /&gt;
EndFunc   ;==&amp;gt;_ConvertFileToUTF16&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== DropFiles ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 35302-guinness&lt;br /&gt;
 | AuthorName = guinness&lt;br /&gt;
 | Desc = Dropping multiple files onto a GUI&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Dropping multiple files onto a GUI&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;APIConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;Array.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $__aDropFiles&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
	Local $hGUI = GUICreate(&#039;&#039;, 500, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)&lt;br /&gt;
&lt;br /&gt;
	; Create a label that is transparent which will accept &#039;drop&#039; events.&lt;br /&gt;
	GUICtrlCreateLabel(&amp;quot;&amp;quot;, 0, 0, 500, 500)&lt;br /&gt;
	GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)&lt;br /&gt;
	GUICtrlSetResizing(-1, $GUI_DOCKALL)&lt;br /&gt;
	GUICtrlSetState(-1, $GUI_DROPACCEPTED)&lt;br /&gt;
&lt;br /&gt;
	GUIRegisterMsg($WM_DROPFILES, &amp;quot;WM_DROPFILES&amp;quot;)&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&lt;br /&gt;
				ExitLoop&lt;br /&gt;
&lt;br /&gt;
			Case $GUI_EVENT_DROPPED&lt;br /&gt;
				If $__aDropFiles[0] &amp;gt; 0 Then&lt;br /&gt;
					_ArrayDisplay($__aDropFiles)&lt;br /&gt;
				EndIf&lt;br /&gt;
&lt;br /&gt;
		EndSwitch&lt;br /&gt;
	WEnd&lt;br /&gt;
	GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func WM_DROPFILES($hWnd, $iMsg, $iwParam, $ilParam)&lt;br /&gt;
	#forceref $hWnd, $ilParam&lt;br /&gt;
	Switch $iMsg&lt;br /&gt;
		Case $WM_DROPFILES&lt;br /&gt;
			Local $aReturn = _WinAPI_DragQueryFileEx($iwParam)&lt;br /&gt;
			If IsArray($aReturn) Then&lt;br /&gt;
				$__aDropFiles = $aReturn&lt;br /&gt;
			Else&lt;br /&gt;
				Local $aError[1] = [0]&lt;br /&gt;
				$__aDropFiles = $aError&lt;br /&gt;
			EndIf&lt;br /&gt;
	EndSwitch&lt;br /&gt;
	Return $GUI_RUNDEFMSG&lt;br /&gt;
EndFunc   ;==&amp;gt;WM_DROPFILES&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ExitCheckTextChange ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 8007-negativenrg&lt;br /&gt;
 | AuthorName = NegativeNrG&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;Check(when Exit), if Text is not equal to $e_to Then, prompt the user to save or not save.&lt;br /&gt;
;_ExitCheckText Change $Edit Handle, $title of messagebox, $message of messagebox, $equal to(default = NULL).&lt;br /&gt;
&lt;br /&gt;
Func _ExitCheckTextChange($E_hnd,$title,$message,$e_to = &#039;&#039;)&lt;br /&gt;
	Local $buffer, $choice, $filetosave, $handle1&lt;br /&gt;
                $buffer = GUIctrlread($E_hnd)&lt;br /&gt;
        If $buffer &amp;lt;&amp;gt; $e_to Then&lt;br /&gt;
            $choice = Msgbox(4,$title,$message)&lt;br /&gt;
            If $choice = 6 Then&lt;br /&gt;
                $filetosave = FileSaveDialog(&#039;Choose File&#039;,@scriptdir,&#039;(*.au3)&#039;)&lt;br /&gt;
                $handle1 = FileOpen($filetosave,2)&lt;br /&gt;
                FileWrite($handle1,$buffer)&lt;br /&gt;
                Exit&lt;br /&gt;
            Elseif $choice &amp;lt;&amp;gt; 6 Then&lt;br /&gt;
            Exit&lt;br /&gt;
        EndIf&lt;br /&gt;
        Else&lt;br /&gt;
        Exit&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileDeleteEx ==&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;
; Ref: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;APIConstants.au3&amp;gt; ; Included with WinAPIEx.au3&lt;br /&gt;
#include &amp;lt;WinAPIEx.au3&amp;gt; ; Download From http://www.autoitscript.com/forum/topic/98712-winapiex-udf/ by Yashied.&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_FileDeleteEx(&amp;quot;C:\Example.dat&amp;quot;) &amp;amp; @LF)&lt;br /&gt;
&lt;br /&gt;
Func _FileDeleteEx($sFilePath)&lt;br /&gt;
    Local $iReturn = FileDelete($sFilePath)&lt;br /&gt;
    If $iReturn Then&lt;br /&gt;
        Return $iReturn&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return _WinAPI_MoveFileEx(FileGetShortName($sFilePath), &amp;quot;&amp;quot;, $MOVE_FILE_DELAY_UNTIL_REBOOT)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileDeleteEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileCheck ==&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;Date.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Check if the file was modified less than 24 hours ago.&lt;br /&gt;
ConsoleWrite( _FileCheck(@ScriptFullPath, 24) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _FileCheck($sFilePath, $iHours = 24)&lt;br /&gt;
    Local $aTime&lt;br /&gt;
    If FileExists($sFilePath) = 0 Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $aTime = FileGetTime($sFilePath, 0, 0)&lt;br /&gt;
    Return Number(_DateDiff(&amp;quot;h&amp;quot;, $aTime[0] &amp;amp; &amp;quot;/&amp;quot; &amp;amp; $aTime[1] &amp;amp; &amp;quot;/&amp;quot; &amp;amp; $aTime[2] &amp;amp; &amp;quot; &amp;quot; &amp;amp; $aTime[3] &amp;amp; &amp;quot;:&amp;quot; &amp;amp; $aTime[4] &amp;amp; &amp;quot;:&amp;quot; &amp;amp; $aTime[5], @YEAR &amp;amp; &amp;quot;/&amp;quot; &amp;amp; @MON &amp;amp; &amp;quot;/&amp;quot; &amp;amp; @MDAY &amp;amp; &amp;quot; &amp;quot; &amp;amp; @HOUR &amp;amp; &amp;quot;:&amp;quot; &amp;amp; @MIN &amp;amp; &amp;quot;:&amp;quot; &amp;amp; @SEC) &amp;lt; $iHours)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileCheck&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileCreateEx ==&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;
_FileCreateEx(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;, 42)&lt;br /&gt;
&lt;br /&gt;
; Create a blank file with a certain size in bytes.&lt;br /&gt;
Func _FileCreateEx($sFilePath, $iBytes = 0)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c fsutil file createnew &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot; &#039; &amp;amp; Int($iBytes), @WorkingDir, @SW_HIDE)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileCreateEx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileID ==&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;
FileClose(FileOpen(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;, 2))&lt;br /&gt;
ConsoleWrite(_FileID(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;) &amp;amp; @CRLF)&lt;br /&gt;
FileDelete(@ScriptDir &amp;amp; &#039;\ExampleFile.txt&#039;)&lt;br /&gt;
&lt;br /&gt;
; Rerieve the file id of a filepath.&lt;br /&gt;
Func _FileID($sFilePath)&lt;br /&gt;
    Local $iPID = Run(@ComSpec &amp;amp; &#039; /c fsutil file queryfileid &amp;quot;&#039; &amp;amp; $sFilePath &amp;amp; &#039;&amp;quot;&#039;, @SystemDir, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sReturn = &#039;&#039;&lt;br /&gt;
    While 1&lt;br /&gt;
        $sReturn &amp;amp;= StdoutRead($iPID)&lt;br /&gt;
        If @error Then&lt;br /&gt;
            ExitLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
    WEnd&lt;br /&gt;
    Return StringStripWS(StringRegExpReplace($sReturn, &#039;File\sID\sis\s(.*?)&#039;, &#039;$1&#039;), 8)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileExistsWithQuotes ==&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(_FileExistsWithQuotes(&#039;&amp;quot;&#039; &amp;amp; @ScriptDir &amp;amp; &#039;&amp;quot;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_FileExistsWithQuotes(&amp;quot;&#039;&amp;quot; &amp;amp; @ScriptDir &amp;amp; &amp;quot;&#039;&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_FileExistsWithQuotes(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Version: 1.00. AutoIt: V3.3.8.1&lt;br /&gt;
; Check a filepath ecists even if the path contains quotation marks.&lt;br /&gt;
Func _FileExistsWithQuotes($sFilePath)&lt;br /&gt;
    Return FileExists(StringRegExpReplace($sFilePath, &#039;^(&amp;quot;|&#039;&#039;)*([^&amp;quot;&#039;&#039;]+)(&amp;quot;|&#039;&#039;)*$&#039;, &#039;\2&#039;))&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileExistsWithQuotes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== FileLineCount ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 71214-mkish&lt;br /&gt;
 | AuthorName = MKISH&lt;br /&gt;
 | Desc = Checks the number of lines in a file (useful for larger files as well)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Author - MKISH&lt;br /&gt;
&lt;br /&gt;
; Checks the number of lines in a file (useful for larger files as well)&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local $FILE = &amp;quot;G:\WIN7\sources\boot.wim&amp;quot;&lt;br /&gt;
Local $COUNT = 0&lt;br /&gt;
Local $start = default&lt;br /&gt;
Local $res, $fLen, $err&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
	$res = _HexSearch($FILE, StringToBinary(&amp;quot;&amp;quot; &amp;amp; @crlf), $start)&lt;br /&gt;
	$start = $res + 2&lt;br /&gt;
	$COUNT = $COUNT + 1&lt;br /&gt;
	If $res = -1 then exitloop&lt;br /&gt;
Wend&lt;br /&gt;
&lt;br /&gt;
msgbox(64, &amp;quot;&amp;quot;, &amp;quot;Lines count: &amp;quot; &amp;amp; $COUNT)&lt;br /&gt;
&lt;br /&gt;
; _HexSearch function (originally written by Zinthose, modified by MKISH)&lt;br /&gt;
Func _HexSearch($FilePath, $BinaryValue, $StartOffset = Default)&lt;br /&gt;
        Local $Buffer, $ptr, $hFile, $Result, $Read, $SearchValue, $Pos, $BufferSize = 2048&lt;br /&gt;
            If $StartOffset = Default     Then $StartOffset = 0&lt;br /&gt;
            If Not FileExists($FilePath)    Then    Return SetError(1, @error, 0)&lt;br /&gt;
            $fLen = FileGetSize($FilePath)&lt;br /&gt;
            If $StartOffset &amp;gt; $fLen   Then   Return SetError(2, @error, 0)&lt;br /&gt;
            If Not IsBinary($BinaryValue)   Then    Return SetError(3, @error, 0)&lt;br /&gt;
            If Not IsNumber($StartOffset)   Then    Return SetError(4, @error, 0)&lt;br /&gt;
            $SearchValue = BinaryToString($BinaryValue)&lt;br /&gt;
            $Buffer = DllStructCreate(&amp;quot;byte[&amp;quot; &amp;amp; $BufferSize &amp;amp; &amp;quot;]&amp;quot;)&lt;br /&gt;
            $ptr = DllStructGetPtr($Buffer)&lt;br /&gt;
                $hFile = _WinAPI_CreateFile($FilePath, 2, 2, 1)&lt;br /&gt;
                If $hFile = 0 Then Return SetError(5, @error, 0)&lt;br /&gt;
            $Result = _WinAPI_SetFilePointer($hFile, $StartOffset)&lt;br /&gt;
            $err = @error&lt;br /&gt;
            If $Result = 0xFFFFFFFF Then&lt;br /&gt;
                _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                Return SetError(5, $err, 0)&lt;br /&gt;
            EndIf&lt;br /&gt;
            $Pos = $StartOffset&lt;br /&gt;
            While True&lt;br /&gt;
                    $Read = 0&lt;br /&gt;
                    $Result = _WinAPI_ReadFile($hFile, $ptr, $BufferSize, $Read)&lt;br /&gt;
                    $err = @error&lt;br /&gt;
                    If Not $Result Then&lt;br /&gt;
                        _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                        Return SetError(6, $err, 0)&lt;br /&gt;
                    EndIf&lt;br /&gt;
                    $Result = DllStructGetData($Buffer, 1)&lt;br /&gt;
                    $Result = BinaryToString($Result)&lt;br /&gt;
                    $Result = StringInStr($Result, $SearchValue)&lt;br /&gt;
                    If $Result &amp;gt; 0 Then ExitLoop&lt;br /&gt;
                    If $Read &amp;lt; $BufferSize Then&lt;br /&gt;
                        _WinAPI_CloseHandle($hFile)&lt;br /&gt;
                        Return -1&lt;br /&gt;
                    EndIf&lt;br /&gt;
                    $Pos += $Read&lt;br /&gt;
&lt;br /&gt;
            WEnd&lt;br /&gt;
            _WinAPI_CloseHandle($hFile)&lt;br /&gt;
            If Not $Result Then Return SetError(7, @error, 0)&lt;br /&gt;
            $Result = $Pos + $Result - 1&lt;br /&gt;
            Return $Result&lt;br /&gt;
    EndFunc; ==&amp;gt; _HexSearch&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileOpenDialog ==&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;
Local $sFilePath = _FileOpenDialog(&amp;quot;&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;Images (*.jpg;*.bmp)|Videos (*.avi;*.mpg)&amp;quot;, Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1), 1 + 4, &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(&#039;File = &#039; &amp;amp; $sFilePath &amp;amp; &#039;, @error = &#039; &amp;amp; @error &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; #FUNCTION# ====================================================================================================================&lt;br /&gt;
; Name ..........: _FileOpenDialog&lt;br /&gt;
; Description ...: Initiates a Open File Dialog with the option to set the position of the GUI.&lt;br /&gt;
; Syntax ........: _FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter[, $iLeft = -1[, $iTop = -1[, $iOptions = 0[,&lt;br /&gt;
;                  $sDefaultName = &amp;quot;&amp;quot;]]]])&lt;br /&gt;
; Parameters ....: $sTitle              - Title text of the Dialog GUI.&lt;br /&gt;
;                  $sIntitialDirectory  - Initial directory selected in the GUI file tree.&lt;br /&gt;
;                  $sFilter             - File type single filter such as &amp;quot;All (*.*)&amp;quot; or &amp;quot;Text files (*.txt)&amp;quot;.&lt;br /&gt;
;                  $iLeft               - [optional] The left side of the dialog box. By default (-1), the window is centered.&lt;br /&gt;
;                  $iTop                - [optional] The top of the dialog box. Default (-1) is centered&lt;br /&gt;
;                  $iOptions            - [optional] Dialog Options: To use more than one option, add the required values together. See FileOpenDialog. Default is 0.&lt;br /&gt;
;                  $sDefaultName        - [optional] Suggested file name for the user to open. Default is blank (&amp;quot;&amp;quot;).&lt;br /&gt;
; Return values .: Success: Returns the full path of the file(s) chosen. Results for multiple selections are &amp;quot;Directory|file1|file2|...&amp;quot;&lt;br /&gt;
;                  Failure: Sets @error to non-zero.&lt;br /&gt;
; Author ........: guinness&lt;br /&gt;
; Remarks........: This doesn&#039;t change the working directory of the script like FileOpenDialog does.&lt;br /&gt;
; Example .......: Yes&lt;br /&gt;
; ===============================================================================================================================&lt;br /&gt;
Func _FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter, $iLeft = -1, $iTop = -1, $iOptions = 0, $sDefaultName = &amp;quot;&amp;quot;)&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;, -1, -1, $iLeft, $iTop), $sWorkingDir = @WorkingDir&lt;br /&gt;
    Local $sFilePath = FileOpenDialog($sTitle, $sIntitialDirectory, $sFilter, $iOptions, $sDefaultName, $hGUI)&lt;br /&gt;
    Local $iError = @error&lt;br /&gt;
    FileChangeDir($sWorkingDir)&lt;br /&gt;
    Return SetError($iError, GUIDelete($hGUI), $sFilePath)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileOpenDialog()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _FileRename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 52374-johnone&lt;br /&gt;
 | AuthorName = JohnOne&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;### Rename a file ###&lt;br /&gt;
;$sFile = Full path to file&lt;br /&gt;
;$sRename = New Filename&lt;br /&gt;
;$iOverWrite = 0 or 1&lt;br /&gt;
&lt;br /&gt;
;Success returns 1&lt;br /&gt;
;failure, returns 0 and sets @error&lt;br /&gt;
; 1 if FileMove fails, &lt;br /&gt;
; 2 if $sFile does not exist&lt;br /&gt;
;@extended&lt;br /&gt;
; 0 if the new file does not already exist / existed&lt;br /&gt;
; 1 if the new file already exists / existed&lt;br /&gt;
&lt;br /&gt;
;#### Example ####&lt;br /&gt;
$File = @ScriptDir &amp;amp; &#039;\filetorename.txt&#039;&lt;br /&gt;
FileWrite($File, &#039;Test&#039;)&lt;br /&gt;
_FileRename($File, &#039;newname.txt&#039;)&lt;br /&gt;
If @error Then MsgBox(0, &amp;quot;Error&amp;quot;, @error)&lt;br /&gt;
&lt;br /&gt;
Func _FileRename($sFile, $sRename, $iOverWrite = 0)&lt;br /&gt;
    Local Const $FILENOTEXIST = 2&lt;br /&gt;
    If Not FileExists($sFile) Then Return SetError($FILENOTEXIST, 0, 0)&lt;br /&gt;
    Local $_StringLen = StringLen($sFile)&lt;br /&gt;
    Local $_StringInStr = StringInStr($sFile, &amp;quot;\&amp;quot;, 0, -1, $_StringLen)&lt;br /&gt;
    Local $_Count = $_StringLen - $_StringInStr&lt;br /&gt;
    Local $_Dir = StringLeft($sFile, $_StringInStr)&lt;br /&gt;
    Local $_NewFile = $_Dir &amp;amp; $sRename&lt;br /&gt;
    Local $_NewFileExists = FileExists($_NewFile)&lt;br /&gt;
    Local $_FileMove = FileMove($sFile, $_NewFile, $iOverWrite)&lt;br /&gt;
    Return SetError(Not $_FileMove, $_NewFileExists, $_FileMove)&lt;br /&gt;
EndFunc   ;==&amp;gt;_FileRename&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== _FileRename Alternative ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;FileRename(PathFile, RenameFile)&lt;br /&gt;
;JohnOne&lt;br /&gt;
&lt;br /&gt;
FileRename(@ScriptDir &amp;amp; &amp;quot;\rename.txt&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\renamed.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Func FileRename($FileName, $ReName)&lt;br /&gt;
&lt;br /&gt;
	Local $SHFILEOPSTRUCT, $SourceStruct, $DestStruct&lt;br /&gt;
	Local Const $FO_RENAME = 0x0004&lt;br /&gt;
	Local Const $FOF_SILENT = 0x0004&lt;br /&gt;
	Local Const $FOF_NOCONFIRMATION = 0x0010&lt;br /&gt;
	Local Const $FOF_NOERRORUI = 0x0400&lt;br /&gt;
	Local Const $FOF_NOCONFIRMMKDIR = 0x0200&lt;br /&gt;
	Local Const $NULL = 0&lt;br /&gt;
&lt;br /&gt;
	$SourceStruct = _StringToStruct($FileName)&lt;br /&gt;
	$DestStruct = _StringToStruct($ReName)&lt;br /&gt;
&lt;br /&gt;
	$SHFILEOPSTRUCT = DllStructCreate(&amp;quot;hwnd hWnd;uint wFunc;ptr pFrom;ptr pTo;int fFlags;int fAnyOperationsAborted;ptr hNameMappings;ptr lpszProgressTitle&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;hWnd&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;wFunc&amp;quot;, $FO_RENAME)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;pFrom&amp;quot;, DllStructGetPtr($SourceStruct))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;pTo&amp;quot;, DllStructGetPtr($DestStruct))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;fFlags&amp;quot;, BitOR($FOF_SILENT, $FOF_NOCONFIRMATION, $FOF_NOERRORUI, $FOF_NOCONFIRMMKDIR))&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;fAnyOperationsAborted&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;hNameMappings&amp;quot;, $NULL)&lt;br /&gt;
	DllStructSetData($SHFILEOPSTRUCT, &amp;quot;lpszProgressTitle&amp;quot;, $NULL)&lt;br /&gt;
&lt;br /&gt;
	$acall = DllCall(&amp;quot;shell32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;SHFileOperation&amp;quot;, &amp;quot;ptr&amp;quot;, DllStructGetPtr($SHFILEOPSTRUCT))&lt;br /&gt;
	If @error Then&lt;br /&gt;
		Return SetError(@error, @extended, 0)&lt;br /&gt;
	EndIf&lt;br /&gt;
	Return 1&lt;br /&gt;
EndFunc   ;==&amp;gt;FileRename&lt;br /&gt;
&lt;br /&gt;
Func _StringToStruct($string)&lt;br /&gt;
&lt;br /&gt;
	Local $iLen = StringLen($string)&lt;br /&gt;
	Local $Struct = DllStructCreate(&amp;quot;char[&amp;quot; &amp;amp; String($iLen + 2) &amp;amp; &amp;quot;]&amp;quot;)&lt;br /&gt;
	DllStructSetData($Struct, 1, $string)&lt;br /&gt;
	DllStructSetData($Struct, 1, 0, $iLen + 1)&lt;br /&gt;
	DllStructSetData($Struct, 1, 0, $iLen + 2)&lt;br /&gt;
&lt;br /&gt;
	Return $Struct&lt;br /&gt;
EndFunc   ;==&amp;gt;_StringToStruct&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFolderDepth ==&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;
; Autoit 3.3.5.4 and Below&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir &amp;amp; &#039;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the folder depth of a filepath.&lt;br /&gt;
Func _GetFolderDepth($sFilePath)&lt;br /&gt;
    If StringInStr($sFilePath, &#039;.&#039;, 2, -1) Then&lt;br /&gt;
        $sFilePath = StringLeft($sFilePath, StringInStr($sFilePath, &amp;quot;&amp;quot;, 2, -1) - 1)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Local $aArray = StringSplit(StringRegExpReplace($sFilePath, &#039;[/]+z&#039;, &#039;&#039;), &#039;&#039;)&lt;br /&gt;
    Return $aArray[0] - 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFolderDepth&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GetFolderDepth ==&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;
; Autoit 3.3.5.4 and Above&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir &amp;amp; &#039;&#039;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_GetFolderDepth(@ScriptFullPath) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Get the folder depth of a filepath. Works with V3.3.5.4+&lt;br /&gt;
Func _GetFolderDepth($sFilePath)&lt;br /&gt;
    If StringInStr($sFilePath, &#039;.&#039;, 2, -1) Then&lt;br /&gt;
        $sFilePath = StringLeft($sFilePath, StringInStr($sFilePath, &amp;quot;&amp;quot;, 2, -1) - 1)&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return StringSplit(StringRegExpReplace($sFilePath, &#039;[/]+z&#039;, &#039;&#039;), &#039;&#039;)[0] - 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_GetFolderDepth&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsDir ==&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;IsDir: Using a file - &amp;quot; &amp;amp; IsDir(@ScriptFullPath) &amp;amp; @CRLF) ; Return 0&lt;br /&gt;
ConsoleWrite(&amp;quot;IsFile: Using a file - &amp;quot; &amp;amp; IsFile(@ScriptFullPath) &amp;amp; @CRLF) ; Return 1&lt;br /&gt;
ConsoleWrite(&amp;quot;IsDir: Using a directory - &amp;quot; &amp;amp; IsDir(@ScriptDir) &amp;amp; @CRLF) ; Return 1&lt;br /&gt;
ConsoleWrite(&amp;quot;IsFile: Using a directory - &amp;quot; &amp;amp; IsFile(@ScriptDir) &amp;amp; @CRLF) ; Return 0&lt;br /&gt;
&lt;br /&gt;
Func IsDir($sFilePath)&lt;br /&gt;
    Return Number(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), &amp;quot;D&amp;quot;, 2, 1) &amp;gt; 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;IsDir&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFile ==&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;
Func IsFile($sFilePath)&lt;br /&gt;
    Return Number(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), &amp;quot;D&amp;quot;, 2, 1) = 0)&lt;br /&gt;
EndFunc   ;==&amp;gt;IsFile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileDiff ==&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(_IsFileDiff(@ScriptFullPath, @ScriptFullPath) &amp;amp; @CRLF) ; This will return False as the files are exactly the same.&lt;br /&gt;
ConsoleWrite(_IsFileDiff(@ScriptFullPath, @AutoItExe) &amp;amp; @CRLF) ; This will return True as the files are different.&lt;br /&gt;
&lt;br /&gt;
; Check if a file is different.&lt;br /&gt;
Func _IsFileDiff($sFilePath_1, $sFilePath_2)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c FC /B /W &amp;quot;&#039; &amp;amp; $sFilePath_1 &amp;amp; &#039;&amp;quot; &amp;quot;&#039; &amp;amp; $sFilePath_2 &amp;amp; &#039;&amp;quot;&#039;, @WorkingDir, @SW_HIDE) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileDiff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileOlder ==&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;Date.au3&amp;gt; ; Required for _DateDiff()&lt;br /&gt;
&lt;br /&gt;
; Check if the current script is older than 10 days.&lt;br /&gt;
If _IsFileOlder(@ScriptFullPath, 10) Then&lt;br /&gt;
	MsgBox(4096, &#039;&#039;, &#039;File is older than 10 days.&#039;)&lt;br /&gt;
Else&lt;br /&gt;
	MsgBox(4096, &#039;&#039;, &#039;File isn&#039;&#039;t older than 10 days.&#039;)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
; Is a file older than a certain number of days.&lt;br /&gt;
Func _IsFileOlder($sFilePath, $iDays)&lt;br /&gt;
	Local $aArray = FileGetTime($sFilePath, 0)&lt;br /&gt;
	Return _DateDiff(&#039;D&#039;, $aArray[0] &amp;amp; &#039;/&#039; &amp;amp; $aArray[1] &amp;amp; &#039;/&#039; &amp;amp; $aArray[2] &amp;amp; &#039; &#039; &amp;amp; $aArray[3] &amp;amp; &#039;:&#039; &amp;amp; $aArray[4] &amp;amp; &#039;:&#039; &amp;amp; $aArray[5], @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) &amp;gt;= $iDays&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileOlder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsFileSame ==&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(_IsFileSame(@ScriptFullPath, @ScriptFullPath) &amp;amp; @CRLF) ; This will return True as the files are exactly the same.&lt;br /&gt;
ConsoleWrite(_IsFileSame(@ScriptFullPath, @AutoItExe) &amp;amp; @CRLF) ; This will return False as the files are different.&lt;br /&gt;
&lt;br /&gt;
; Check if a file is the same.&lt;br /&gt;
Func _IsFileSame($sFilePath_1, $sFilePath_2)&lt;br /&gt;
    Return RunWait(@ComSpec &amp;amp; &#039; /c FC /B /W &amp;quot;&#039; &amp;amp; $sFilePath_1 &amp;amp; &#039;&amp;quot; &amp;quot;&#039; &amp;amp; $sFilePath_2 &amp;amp; &#039;&amp;quot;&#039;, @WorkingDir, @SW_HIDE) = 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsFileSame&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IniReadFile ==&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;Array.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__INIFileFill(@ScriptDir &amp;amp; &#039;\Example.ini&#039;) ; Create an INI file with random data.&lt;br /&gt;
&lt;br /&gt;
Local $aArray = _IniReadFile(@ScriptDir &amp;amp; &#039;\Example.ini&#039;)&lt;br /&gt;
FileDelete(@ScriptDir &amp;amp; &#039;\Example.ini&#039;)&lt;br /&gt;
_ArrayDisplay($aArray)&lt;br /&gt;
&lt;br /&gt;
Func _IniReadFile($sFilePath)&lt;br /&gt;
    Local $aReturn[1][3] = [[0, 3]], $aSectionArray, $aSectionNameArray, $iCount = 0&lt;br /&gt;
    $aSectionNameArray = IniReadSectionNames($sFilePath)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, $aReturn)&lt;br /&gt;
    EndIf&lt;br /&gt;
    For $A = 1 To $aSectionNameArray[0]&lt;br /&gt;
        $aSectionArray = IniReadSection($sFilePath, $aSectionNameArray[$A])&lt;br /&gt;
        If @error Then&lt;br /&gt;
            ContinueLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
        For $B = 1 To $aSectionArray[0][0]&lt;br /&gt;
            $aReturn[0][0] += 1&lt;br /&gt;
            $iCount += 1&lt;br /&gt;
            If $aReturn[0][0] &amp;lt;= $iCount + 1 Then&lt;br /&gt;
                ReDim $aReturn[$aReturn[0][0] * 2][$aReturn[0][1]]&lt;br /&gt;
            EndIf&lt;br /&gt;
            $aReturn[$iCount][0] = $aSectionArray[$B][0]&lt;br /&gt;
            $aReturn[$iCount][1] = $aSectionArray[$B][1]&lt;br /&gt;
            $aReturn[$iCount][2] = $aSectionNameArray[$A]&lt;br /&gt;
        Next&lt;br /&gt;
    Next&lt;br /&gt;
    ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1]] ; Remove empty entries.&lt;br /&gt;
    Return $aReturn&lt;br /&gt;
EndFunc   ;==&amp;gt;_IniReadFile&lt;br /&gt;
&lt;br /&gt;
Func __INIFileFill($sFilePath)&lt;br /&gt;
    Local $sData = &#039;&#039;, $sHeader = &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
    For $i = 1 To Random(1, 5, 1)&lt;br /&gt;
        $sHeader = _RandomText(Random(5, 25, 1))&lt;br /&gt;
        $sData = &amp;quot;&amp;quot;&lt;br /&gt;
        For $j = 1 To Random(1, 25, 1)&lt;br /&gt;
            $sData &amp;amp;= _RandomText(Random(5, 25, 1)) &amp;amp; &#039;=&#039; &amp;amp; _RandomText(Random(5, 25, 1)) &amp;amp; @LF&lt;br /&gt;
        Next&lt;br /&gt;
        IniWriteSection($sFilePath, $sHeader, $sData)&lt;br /&gt;
    Next&lt;br /&gt;
EndFunc   ;==&amp;gt;__FillINIFile&lt;br /&gt;
&lt;br /&gt;
Func _RandomText($iLength = 10)&lt;br /&gt;
    Local $sData = &#039;&#039;, $sRandom = &#039;&#039;&lt;br /&gt;
    For $i = 1 To $iLength&lt;br /&gt;
        $sRandom = Random(55, 116, 1)&lt;br /&gt;
        $sData &amp;amp;= Chr($sRandom + 6 * ($sRandom &amp;gt; 90) - 7 * ($sRandom &amp;lt; 65))&lt;br /&gt;
    Next&lt;br /&gt;
    Return $sData&lt;br /&gt;
EndFunc   ;==&amp;gt;_RandomText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IniReadInit ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 9370-mlowery&lt;br /&gt;
 | AuthorName = mlowery&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;===============================================================================&lt;br /&gt;
; Description:     Reads values from INI or creates INI with initial values.&lt;br /&gt;
;                  Intended to ensure all available INI settings are exposed&lt;br /&gt;
;                  and editable.&lt;br /&gt;
;                  Parameters are identical to IniRead()&lt;br /&gt;
; Parameter(s):    $filename  = filename of INI&lt;br /&gt;
;                  $section  = section name of INI&lt;br /&gt;
;                  $key      = key name in section&lt;br /&gt;
;                  $default  = default value (written to INI if not exists)&lt;br /&gt;
; Requirement(s):  None&lt;br /&gt;
; Return Value(s): Returns value from INI (or default if not defined)&lt;br /&gt;
; Note(s):         Chr(127) used to detect non-existing value since won&#039;t normally exist in a text file&lt;br /&gt;
;===============================================================================&lt;br /&gt;
Func _IniReadInit($filename, $section, $key, $default)&lt;br /&gt;
  Local $value = IniRead($filename, $section, $key, Chr(127))&lt;br /&gt;
    If $value = Chr(127) Then&lt;br /&gt;
      IniWrite($filename, $section, $key, $default)&lt;br /&gt;
      $value = $default&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return $value&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsValidFileType ==&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(@ScriptFullPath &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@ScriptFullPath, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(@AutoItExe &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@AutoItExe, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a filepath matches an extension filetype. Based on the idea by guinness - http://www.autoitscript.com/forum/topic/123674-isvalidfiletype/&lt;br /&gt;
Func _IsValidFileType($sFilePath, $sList = &amp;quot;bat;cmd;exe&amp;quot;) ; By AZJIO - http://www.autoitscript.com/forum/topic/...filetype/page__view__findpost_&lt;br /&gt;
    Local $iDot = StringInStr($sFilePath, &amp;quot;.&amp;quot;, 0, -1)&lt;br /&gt;
    Return $iDot And StringInStr(&#039;;&#039; &amp;amp; $sList &amp;amp; &#039;;&#039;, &#039;;&#039; &amp;amp; StringTrimLeft($sFilePath, $iDot) &amp;amp; &#039;;&#039;) &amp;gt; 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsValidFileType&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;
; Example 2&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;WinAPIEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(@ScriptFullPath &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@ScriptFullPath, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(@AutoItExe &amp;amp; &amp;quot; &amp;gt;&amp;gt; &amp;quot; &amp;amp; _IsValidFileType(@AutoItExe, &amp;quot;bat;cmd;au3&amp;quot;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Check if a filepath matches an extension filetype. Based on the idea by guinness - http://www.autoitscript.com/forum/topic/123674-isvalidfiletype/&lt;br /&gt;
Func _IsValidFileType($sFilePath, $sList = &amp;quot;bat;cmd;exe&amp;quot;, $iOpFast = 1) ; By Yashied.&lt;br /&gt;
    If StringStripWS($sList, 8) = &amp;quot;&amp;quot; Then&lt;br /&gt;
        $sList = &amp;quot;*&amp;quot;&lt;br /&gt;
    EndIf&lt;br /&gt;
    Return _WinAPI_PathMatchSpec($sFilePath, StringReplace(&#039;;&#039; &amp;amp; $sList, &#039;;&#039;, &#039;;*.&#039;, 0, $iOpFast * 2))&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsValidFileType&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== File Open/Save/Folder Dialog Box ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 2709-mhz&lt;br /&gt;
 | AuthorName = MHz&lt;br /&gt;
 | AuthorURL2 = 4997-odklizec&lt;br /&gt;
 | AuthorName2 = odklizec&lt;br /&gt;
 | AuthorURL3 = 6756-danny35d&lt;br /&gt;
 | AuthorName3 = Danny35d&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Center - File Open/Save/Folder Dialog Box&lt;br /&gt;
; Author - odklizec, MHz, Danny35d&lt;br /&gt;
&lt;br /&gt;
 If StringInStr($cmdlineraw, &#039;/MoveWin&#039;) Then&lt;br /&gt;
	 Local $size, $PosX, $PosY&lt;br /&gt;
     $cmdlineraw = StringSplit(StringMid($cmdlineraw, StringInStr($cmdlineraw, &#039;/MoveWin&#039;)), &#039;:&#039;)&lt;br /&gt;
     While 1&lt;br /&gt;
         Select&lt;br /&gt;
         Case WinExists($cmdlineraw[2])&lt;br /&gt;
             $size=WinGetPos ($cmdlineraw[2])&lt;br /&gt;
             $PosX=@DesktopWidth/2 - $size[2]/2&lt;br /&gt;
             $PosY=@DesktopHeight/2 - $size[3]/2&lt;br /&gt;
             WinMove($cmdlineraw[2], &amp;quot;&amp;quot;, $PosX, $PosY)&lt;br /&gt;
             WinActivate($cmdlineraw[2])&lt;br /&gt;
             ExitLoop&lt;br /&gt;
         EndSelect&lt;br /&gt;
         Sleep(50)&lt;br /&gt;
     WEnd&lt;br /&gt;
     Exit&lt;br /&gt;
 EndIf&lt;br /&gt;
Global $PID, $Read_File, $Save_File&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Open file Dialog Box&#039;)&lt;br /&gt;
 $Read_File = FileOpenDialog ( &amp;quot;Open file Dialog Box&amp;quot;, @ScriptDir &amp;amp; &amp;quot;\&amp;quot;, &amp;quot;AutoIt Files (*.au3)&amp;quot;,3,@ScriptFullPath)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Save file Dialog Box&#039;)&lt;br /&gt;
 $Save_File = FileSaveDialog( &amp;quot;Save file Dialog Box&amp;quot;, @ScriptDir, &amp;quot;Scripts (*.aut;*.au3)&amp;quot;, 3)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
 $PID = _FindBrowseWin(&#039;Browse for Folder&#039;)&lt;br /&gt;
 FileSelectFolder(&amp;quot;Choose a folder with plugins..&amp;quot;, &amp;quot;&amp;quot;,&amp;quot;4&amp;quot;,&amp;quot;c:\&amp;quot;)&lt;br /&gt;
 ProcessClose($PID)&lt;br /&gt;
&lt;br /&gt;
 Func _FindBrowseWin($sTitle)&lt;br /&gt;
     If @Compiled Then&lt;br /&gt;
         Return(Run(@ScriptFullPath &amp;amp; &#039; /MoveWin:&#039; &amp;amp; $sTitle))&lt;br /&gt;
     Else&lt;br /&gt;
         Return(Run(@AutoItExe &amp;amp; &#039; &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot; /MoveWin:&#039; &amp;amp; $sTitle))&lt;br /&gt;
     EndIf&lt;br /&gt;
 EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _MoveFileOnReboot ==&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.2.0, Creation Date = 21/03/12.&lt;br /&gt;
&lt;br /&gt;
; Function to Move or Delete a file on next reboot!&lt;br /&gt;
Func _MoveFileOnReboot($sSourcePath, $sDestPath = &amp;quot;&amp;quot;); If $sDestPath = &amp;quot;&amp;quot; the file is deleted instead of moved.&lt;br /&gt;
    Local $iRet&lt;br /&gt;
&lt;br /&gt;
    ; PendingFileRenameOperations (HKLM\SYSTEM\CurrentControlSet\Control\Session Manager)&lt;br /&gt;
    If $DestPath = &amp;quot;&amp;quot; Then&lt;br /&gt;
        $iRet = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;MoveFileExA&amp;quot;, &amp;quot;str&amp;quot;, $sSourcePath, &amp;quot;int&amp;quot;, 0, &amp;quot;dword&amp;quot;, 4)&lt;br /&gt;
    Else&lt;br /&gt;
        $iRet = DllCall(&amp;quot;kernel32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;MoveFileExA&amp;quot;, &amp;quot;str&amp;quot;, $sSourcePath, &amp;quot;str&amp;quot;, $sDestPath, &amp;quot;dword&amp;quot;, 4)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return $iRet&lt;br /&gt;
EndFunc   ;==&amp;gt;_MoveFileOnReboot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _MultipleFileOpenDialog ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL =&lt;br /&gt;
 | AuthorName = /dev/null&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Local $message = &amp;quot;Hold down Ctrl or Shift to choose multiple files.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Local $filename = _MultipleFileOpenDialog($message,300,300)&lt;br /&gt;
&lt;br /&gt;
Local $var = FileOpenDialog($message, @WindowsDir &amp;amp; &amp;quot;\&amp;quot;, &amp;quot;Images (*.jpg;*.bmp)&amp;quot;, 1 + 4 )&lt;br /&gt;
&lt;br /&gt;
If @error Then&lt;br /&gt;
    MsgBox(4096,&amp;quot;&amp;quot;,&amp;quot;No File(s) chosen&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
    $var = StringReplace($var, &amp;quot;|&amp;quot;, @CRLF)&lt;br /&gt;
    MsgBox(4096,&amp;quot;&amp;quot;,&amp;quot;You chose &amp;quot; &amp;amp; $var)&lt;br /&gt;
EndIf&lt;br /&gt;
&lt;br /&gt;
FileDelete($filename)&lt;br /&gt;
func _MultipleFileOpenDialog($title,$posx,$posy)&lt;br /&gt;
    Local $temp = EnvGet(&amp;quot;temp&amp;quot;)&lt;br /&gt;
    Local $filename = $temp &amp;amp; &amp;quot;\move_file_open_dialog.au3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    Local $script = &#039;Global $title = &amp;quot;&#039; &amp;amp; $title &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Global $pos_x = &#039; &amp;amp; $posx &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Global $pos_y = &#039; &amp;amp; $posy &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;AdlibRegister(&amp;quot;_Move&amp;quot;,10)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;while 1&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;    sleep(1000)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;wend&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;Func _Move()&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;   if (WinActive($title)) Then&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;      WinMove($title,&amp;quot;&amp;quot;,$pos_x,$pos_y)&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;      Exit&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;   EndIf&#039; &amp;amp; @CRLF&lt;br /&gt;
    $script &amp;amp;= &#039;EndFunc&#039; &amp;amp; @CRLF&lt;br /&gt;
&lt;br /&gt;
    FileWrite($filename,$script)&lt;br /&gt;
    ;MsgBox(0,&amp;quot;&amp;quot;,$script &amp;amp; @CRLF &amp;amp; $filename)&lt;br /&gt;
    Run(@AutoItExe &amp;amp; &amp;quot; /AutoIt3ExecuteScript &amp;quot; &amp;amp; $filename)&lt;br /&gt;
    sleep(250)&lt;br /&gt;
    Return $filename&lt;br /&gt;
EndFunc ;==&amp;gt;_MultipleFileOpenDialog()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _OpenFolder ==&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;
#cs&lt;br /&gt;
    These have been declared in Global scope as you may wish to use them elsewhere in your script.&lt;br /&gt;
#ce&lt;br /&gt;
Global $ALTSTARTUP = 0x1d&lt;br /&gt;
Global $APPDATA = 0x1a&lt;br /&gt;
Global $BITBUCKET = 0x0a&lt;br /&gt;
Global $COMMONALTSTARTUP = 0x1e&lt;br /&gt;
Global $COMMONAPPDATA = 0x23&lt;br /&gt;
Global $COMMONDESKTOPDIR = 0x19&lt;br /&gt;
Global $COMMONFAVORITES = 0x1f&lt;br /&gt;
Global $COMMONPROGRAMS = 0x17&lt;br /&gt;
Global $COMMONSTARTMENU = 0x16&lt;br /&gt;
Global $COMMONSTARTUP = 0x18&lt;br /&gt;
Global $CONTROLS = 0x03&lt;br /&gt;
Global $COOKIES = 0x21&lt;br /&gt;
Global $DESKTOP = 0x00&lt;br /&gt;
Global $DESKTOPDIRECTORY = 0x10&lt;br /&gt;
Global $DRIVES = 0x11&lt;br /&gt;
Global $FAVORITES = 0x06&lt;br /&gt;
Global $FONTS = 0x14&lt;br /&gt;
Global $HISTORY = 0x22&lt;br /&gt;
Global $INTERNETCACHE = 0x20&lt;br /&gt;
Global $LOCALAPPDATA = 0x1c&lt;br /&gt;
Global $MYPICTURES = 0x27&lt;br /&gt;
Global $NETHOOD = 0x13&lt;br /&gt;
Global $NETWORK = 0x12&lt;br /&gt;
Global $PERSONAL = 0x05&lt;br /&gt;
Global $PRINTERS = 0x04&lt;br /&gt;
Global $PRINTHOOD = 0x1b&lt;br /&gt;
Global $PROFILE = 0x28&lt;br /&gt;
Global $PROGRAMFILES = 0x26&lt;br /&gt;
Global $PROGRAMFILESx86 = 0x30&lt;br /&gt;
Global $PROGRAMS = 0x02&lt;br /&gt;
Global $RECENT = 0x08&lt;br /&gt;
Global $SENDTO = 0x09&lt;br /&gt;
Global $STARTMENU = 0x0b&lt;br /&gt;
Global $STARTUP = 0x07&lt;br /&gt;
Global $SYSTEM = 0x25&lt;br /&gt;
Global $SYSTEMx86 = 0x29&lt;br /&gt;
Global $TEMPLATES = 0x15&lt;br /&gt;
Global $WINDOWS = 0x24&lt;br /&gt;
&lt;br /&gt;
ConsoleWrite(_OpenFolder(@ScriptDir) &amp;amp; @CRLF)&lt;br /&gt;
ConsoleWrite(_OpenFolder($PRINTERS) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Open a folder or special folder variable, similar to using ShellExecute.&lt;br /&gt;
Func _OpenFolder($sFolderPath)&lt;br /&gt;
    Local $oShell = ObjCreate(&#039;shell.application&#039;)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(1, 0, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
    $oShell.Open($sFolderPath)&lt;br /&gt;
    Return 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_OpenFolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _PathAppendToFilename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 31965-progandy&lt;br /&gt;
 | AuthorName = ProgAndy&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
$sOrg = &amp;quot;C:\Some.Folder\some.file.ext&amp;quot;&lt;br /&gt;
$sAdd = &amp;quot;_backup&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$sNew = _PathAppendToFilename($sOrg, $sAdd)&lt;br /&gt;
&lt;br /&gt;
$sStripped = _PathStripRightFromFilename($sNew, $sAdd)&lt;br /&gt;
&lt;br /&gt;
MsgBox(0, &amp;quot;&amp;quot;, $sOrg &amp;amp; @CRLF &amp;amp; $sAdd &amp;amp; @CRLF &amp;amp; $sNew &amp;amp; @CRLF &amp;amp; $sStripped)&lt;br /&gt;
&lt;br /&gt;
Func _PathAppendToFilename($sName, $sAppend)&lt;br /&gt;
    ; Author: ProgAndy&lt;br /&gt;
    If StringRegExp($sAppend, &#039;[\/\\:\?&amp;quot;&amp;lt;&amp;gt;\|\*]&#039;) Then Return SetError(1, 0, $sName)&lt;br /&gt;
    Return StringRegExpReplace($sName, &amp;quot;(\.[^\\/\.]+)$&amp;quot;, $sAppend &amp;amp; &amp;quot;\1&amp;quot;, 1)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _PathStripRightFromFilename ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 31965-progandy&lt;br /&gt;
 | AuthorName = ProgAndy&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Func _PathStripRightFromFilename($sName, $sStrip)&lt;br /&gt;
    ; Author: ProgAndy&lt;br /&gt;
    If StringRegExp($sStrip, &#039;[\/\\:\?&amp;quot;&amp;lt;&amp;gt;\|\*]&#039;) Then Return SetError(1, 0, $sName)&lt;br /&gt;
    Return StringRegExpReplace($sName, &amp;quot;\Q&amp;quot; &amp;amp; $sStrip &amp;amp; &amp;quot;\E(\.[^\\/\.]+)$&amp;quot;, &amp;quot;\1&amp;quot;, 1)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SelfDelete ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 2709-mhz&lt;br /&gt;
 | AuthorName = MHz&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; This also removes the directory which the file is in&lt;br /&gt;
; Author MHz with the directory delete addition by The Kandie Man&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;:loop2&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;rmdir /q &amp;quot;&#039; &amp;amp; $dirToDelete &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;if exist &amp;quot;&#039; &amp;amp; $dirToDelete &amp;amp; &#039;&amp;quot; goto loop2&#039; &amp;amp; @CRLF _&lt;br /&gt;
            &amp;amp; &#039;del &#039; &amp;amp; @TempDir &amp;amp; &#039;\scratch.bat&#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&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ShellExecuteFileSelectFolder ==&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(_ShellExecuteFileSelectFolder(&#039;Select a Folder&#039;, @HomeDrive) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
; Shell Execute a selected folder.&lt;br /&gt;
Func _ShellExecuteFileSelectFolder($sText, $sRoot, $iFlag = 0, $sInitialDir = &#039;&#039;, $hWnd = &#039;&#039;)&lt;br /&gt;
    Local $sFolder = FileSelectFolder($sText, $sRoot, $iFlag, $sInitialDir, $hWnd)&lt;br /&gt;
    If @error Then&lt;br /&gt;
        Return SetError(@error, @extended, &#039;&#039;)&lt;br /&gt;
    EndIf&lt;br /&gt;
    ShellExecute($sFolder)&lt;br /&gt;
    Return $sFolder&lt;br /&gt;
EndFunc   ;==&amp;gt;_ShellExecuteFileSelectFolder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SuiCide ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 28010-larrydalooza&lt;br /&gt;
 | AuthorName = LarryDalooza&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; IMPORTANT MAKE A COPY OF SCRIPT BEFORE DELETION&lt;br /&gt;
; Deletes the running script&lt;br /&gt;
&lt;br /&gt;
Func SuiCide()&lt;br /&gt;
	Local $sFilePath = @TempDir &amp;amp; &#039;\SuiCide.bat&#039;&lt;br /&gt;
	FileDelete($sFilePath)&lt;br /&gt;
	FileWrite($sFilePath, &#039;loop:&#039; &amp;amp; @CRLF &amp;amp; &#039;del &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; &#039;&amp;quot;&#039; &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
			&#039;ping -n 1 -w 250 zxywqxz_q&#039; &amp;amp; @CRLF &amp;amp; &#039;if exist &amp;quot;&#039; &amp;amp; @ScriptFullPath &amp;amp; _&lt;br /&gt;
			&#039;&amp;quot; goto loop&#039; &amp;amp; @CRLF &amp;amp; &#039;del SuiCide.bat&#039; &amp;amp; @CRLF)&lt;br /&gt;
	Exit Run($sFilePath, @TempDir, @SW_HIDE)&lt;br /&gt;
EndFunc   ;==&amp;gt;SuiCide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _UniqueFilename ==&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;
&lt;br /&gt;
ConsoleWrite(_UniqueFilename(@ScriptDir, &#039;.au3&#039;) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
Func _UniqueFilename($sFilePath, $sExtension)&lt;br /&gt;
    Local $iRandom = 0, $sUnqiueFileName = &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
    $sExtension = &#039;.&#039; &amp;amp; StringRegExpReplace($sExtension, &#039;\A[\.]+&#039;, &#039;&#039;)&lt;br /&gt;
    $sFilePath = StringRegExpReplace($sFilePath, &#039;[\\/]+\z&#039;, &#039;&#039;) &amp;amp; &#039;\&#039;&lt;br /&gt;
    While 1&lt;br /&gt;
        $iRandom = Random(55, 116, 1)&lt;br /&gt;
        $sUnqiueFileName &amp;amp;= Chr($iRandom + 6 * ($iRandom &amp;gt; 90) - 7 * ($iRandom &amp;lt; 65))&lt;br /&gt;
        If FileExists($sFilePath &amp;amp; $sUnqiueFileName &amp;amp; $sExtension) = 0 And StringLen($sUnqiueFileName) &amp;gt; 7 Then&lt;br /&gt;
            ExitLoop&lt;br /&gt;
        EndIf&lt;br /&gt;
    WEnd&lt;br /&gt;
    Return $sFilePath &amp;amp; $sUnqiueFileName &amp;amp; $sExtension&lt;br /&gt;
EndFunc   ;==&amp;gt;_UniqueFilename&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Windows - Copy With Progress ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 19-jos&lt;br /&gt;
 | AuthorName = Jos&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Windows - Copy With Progress&lt;br /&gt;
&lt;br /&gt;
;~ 4 Do not display a progress dialog box.&lt;br /&gt;
;~ 8 Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.&lt;br /&gt;
;~ 16 Respond with &amp;quot;Yes to All&amp;quot; for any dialog box that is displayed.&lt;br /&gt;
;~ 64 Preserve undo information, if possible.&lt;br /&gt;
;~ 128 Perform the operation on files only if a wildcard file name (*.*) is specified.&lt;br /&gt;
;~ 256 Display a progress dialog box but do not show the file names.&lt;br /&gt;
;~ 512 Do not confirm the creation of a new directory if the operation requires one to be created.&lt;br /&gt;
;~ 1024 Do not display a user interface if an error occurs.&lt;br /&gt;
;~ 2048 Version 4.71. Do not copy the security attributes of the file.&lt;br /&gt;
;~ 4096 Only operate in the local directory. Don&#039;t operate recursively into subdirectories.&lt;br /&gt;
;~ 8192 Version 5.0. Do not copy connected files as a group. Only copy the specified files.&lt;br /&gt;
&lt;br /&gt;
_FileCopy(&amp;quot;C:\Installed Apps\Patches\WindowsXP-KB835935-SP2-ENU.exe&amp;quot;,&amp;quot;C:\temp&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
; to copy a directory the destination directory must exist&lt;br /&gt;
&lt;br /&gt;
Func _FileCopy($fromFile,$tofile)&lt;br /&gt;
    Local $FOF_RESPOND_YES = 16&lt;br /&gt;
    Local $FOF_SIMPLEPROGRESS = 256&lt;br /&gt;
    $winShell = ObjCreate(&amp;quot;shell.application&amp;quot;)&lt;br /&gt;
    $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Snippets_(_GUI_)&amp;diff=12324</id>
		<title>Snippets ( GUI )</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Snippets_(_GUI_)&amp;diff=12324"/>
		<updated>2014-03-15T21:53:35Z</updated>

		<summary type="html">&lt;p&gt;Guinness: /* Small Cue Banner */&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;
== _AlwaysOnTop ==&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;ButtonConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local Const $hGUI = GUICreate(&amp;quot;_AlwaysOnTop()&amp;quot;, 200, 200, -1, -1)&lt;br /&gt;
&lt;br /&gt;
    Local Const $iControlID = GUICtrlCreateCheckbox(&amp;quot;Always On Top&amp;quot;, 5, 10, 85, 25, BitOR($BS_CHECKBOX, $BS_AUTOCHECKBOX, $BS_PUSHLIKE, $WS_TABSTOP))&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                Exit&lt;br /&gt;
            Case $iControlID&lt;br /&gt;
                _AlwaysOnTop($hGUI, $iControlID)&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _AlwaysOnTop(Const $hHandle, Const $iControlID)&lt;br /&gt;
    Local $iState = 0&lt;br /&gt;
&lt;br /&gt;
    If GUICtrlRead($iControlID) = $GUI_CHECKED Then&lt;br /&gt;
        $iState = 1&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    WinSetOnTop($hHandle, &amp;quot;&amp;quot;, $iState)&lt;br /&gt;
&lt;br /&gt;
    Return $iState&lt;br /&gt;
EndFunc   ;==&amp;gt;_AlwaysOnTop&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Animate Display ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 5725-raindancer&lt;br /&gt;
 | AuthorName = Raindancer&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Animate Display&lt;br /&gt;
; Author Raindancer&lt;br /&gt;
&lt;br /&gt;
Global Const $hwnd = GUICreate(&amp;quot;Animate Window&amp;quot;, 300, 300)&lt;br /&gt;
&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00080000) ; fade-in&lt;br /&gt;
&lt;br /&gt;
GUISetState(@SW_SHOWNORMAL)&lt;br /&gt;
&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00090000) ; fade-out&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00040001) ; slide in from left&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00050002) ; slide out to left&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00040002) ; slide in from right&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00050001) ; slide out to right&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00040004) ; slide-in from top&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00050008) ; slide-out to top&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00040008) ; slide-in from bottom&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00050004) ; slide-out to bottom&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00040005) ; diag slide-in from Top-left&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x0005000a) ; diag slide-out to Top-left&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00040006) ; diag slide-in from Top-Right&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00050009) ; diag slide-out to Top-Right&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00040009) ; diag slide-in from Bottom-left&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00050006) ; diag slide-out to Bottom-left&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x0004000a) ; diag slide-in from Bottom-right&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00050005) ; diag slide-out to Bottom-right&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00040010) ; explode&lt;br /&gt;
DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;AnimateWindow&amp;quot;, &amp;quot;hwnd&amp;quot;, $hwnd, &amp;quot;int&amp;quot;, 1000, &amp;quot;long&amp;quot;, 0x00050010) ; implode&lt;br /&gt;
&lt;br /&gt;
#define AW_HOR_POSITIVE		0x00000001&lt;br /&gt;
#define AW_HOR_NEGATIVE		0x00000002&lt;br /&gt;
#define AW_VER_POSITIVE		0x00000004&lt;br /&gt;
#define AW_VER_NEGATIVE		0x00000008&lt;br /&gt;
#define AW_CENTER			0x00000010&lt;br /&gt;
#define AW_HIDE				0x00010000&lt;br /&gt;
#define AW_ACTIVATE         0x00020000&lt;br /&gt;
#define AW_SLIDE            0x00040000&lt;br /&gt;
#define AW_BLEND            0x00080000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Center Window on Screen ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 4920-valuater&lt;br /&gt;
 | AuthorName = Valuater&lt;br /&gt;
 | AuthorURL2 = 9669-cdkid&lt;br /&gt;
 | AuthorName2 = cdkid&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Center Window on Screen&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global Const $GUI = GUICreate(&amp;quot;Test Window&amp;quot;,300 ,300 ,100 ,100)&lt;br /&gt;
&lt;br /&gt;
GUISetState(@SW_SHOWNORMAL)&lt;br /&gt;
&lt;br /&gt;
Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
_Middle($GUI, &amp;quot;Test Window&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
	Switch GUIGetMsg()&lt;br /&gt;
		Case $GUI_EVENT_CLOSE&lt;br /&gt;
			ExitLoop&lt;br /&gt;
	EndSwitch&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func _Middle(Const $win, Const $txt)&lt;br /&gt;
    Local Const $size = WinGetClientSize($win, $txt)&lt;br /&gt;
&lt;br /&gt;
    Local Const $y = (@DesktopHeight / 2) - ($size[1] / 2)&lt;br /&gt;
&lt;br /&gt;
    Local Const $x = (@DesktopWidth / 2) - ($size[0] / 2)&lt;br /&gt;
&lt;br /&gt;
    Return WinMove($win, $txt, $x, $y)&lt;br /&gt;
EndFunc  ;==&amp;gt;_Middle&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ChildActivate ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 71214-mkish&lt;br /&gt;
 | AuthorName = MKISH&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;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
_ChildActivate(&amp;quot;Main Window Title&amp;quot;, &amp;quot;Child Window Title&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
; Set focus to Child-Window of a GUI&lt;br /&gt;
Func _ChildActivate(Const $appTitle, Const $formName)&lt;br /&gt;
    Local Const $hWnd = WinGetHandle($appTitle, $formName)&lt;br /&gt;
&lt;br /&gt;
    Local $array = WinList($appTitle)&lt;br /&gt;
&lt;br /&gt;
	#forceref $array&lt;br /&gt;
&lt;br /&gt;
    WinActive($hWnd)&lt;br /&gt;
&lt;br /&gt;
    Local Const $winarray = _WinAPI_EnumWindows(True, $hWnd)&lt;br /&gt;
&lt;br /&gt;
    Local $title&lt;br /&gt;
&lt;br /&gt;
	For $i = 1 to $winarray[0][0]&lt;br /&gt;
        $title = _WinAPI_GetWindowText($winarray[$i][0])&lt;br /&gt;
&lt;br /&gt;
		If ($title == $formName) or ($title == $formName &amp;amp; &amp;quot; *&amp;quot;) Then&lt;br /&gt;
            _WinAPI_ShowWindow($winarray[$i][0], @SW_MAXIMIZE)&lt;br /&gt;
            _WinAPI_ShowWindow($winarray[$i][0], @SW_SHOWNORMAL)&lt;br /&gt;
        EndIf&lt;br /&gt;
    Next&lt;br /&gt;
EndFunc ;&amp;gt;&amp;gt;&amp;gt; _ChildActivate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _ControlMove ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 38576-melba23&lt;br /&gt;
 | AuthorName = Melba23&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;GuiConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global Const $SC_MOVE = 0xF010&lt;br /&gt;
&lt;br /&gt;
Global Const $hGUI = GUICreate(&amp;quot;Test&amp;quot;, 300, 200)&lt;br /&gt;
&lt;br /&gt;
Globa Const $cLabel = GUICtrlCreateLabel(&amp;quot;Move me&amp;quot;, 100, 50, 60, 20)&lt;br /&gt;
&lt;br /&gt;
GUICtrlSetBkColor($cLabel, 0x00FF00)&lt;br /&gt;
&lt;br /&gt;
GUISetState(@SW_SHOWNORMAL)&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
    Switch GUIGetMsg()&lt;br /&gt;
        Case $GUI_EVENT_CLOSE&lt;br /&gt;
            Exit&lt;br /&gt;
        Case $GUI_EVENT_PRIMARYDOWN&lt;br /&gt;
            _ControlMove($cLabel)&lt;br /&gt;
    EndSwitch&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func _ControlMove(Const $cID)&lt;br /&gt;
    Local Const $aCurPos = GUIGetCursorInfo()&lt;br /&gt;
&lt;br /&gt;
    If @error Then Return False&lt;br /&gt;
&lt;br /&gt;
    If $aCurPos[4] = $cID Then&lt;br /&gt;
        GUICtrlSendMsg($cID, $WM_SYSCOMMAND, BitOR($SC_MOVE, $HTCAPTION), 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;_ControlMove&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Custom Tabs ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 20477-mrcreator&lt;br /&gt;
 | AuthorName = MrCreatoR&lt;br /&gt;
 | AuthorURL2 = 14325-kickassjoe&lt;br /&gt;
 | AuthorName2 = Kickassjoe&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Custom Tabs - controlled by a label, pic, etc&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;GUIConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
GUICreate(&amp;quot;Test&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Global $TabSwitcher[2]&lt;br /&gt;
&lt;br /&gt;
Global Const $TabSwitcher1 = GUICtrlCreateLabel(&amp;quot;Tab One&amp;quot;, 10, 10,60,20, $SS_SUNKEN +$SS_CENTER+ $SS_CENTERIMAGE)&lt;br /&gt;
GUICtrlSetBkColor(-1, 0xf0f0f0)&lt;br /&gt;
GUICtrlSetColor(-1, 0x000000)&lt;br /&gt;
&lt;br /&gt;
Global Const $TabSwitcher2 = GUICtrlCreateLabel(&amp;quot;Tab Two&amp;quot;, 72, 10,60,20, $SS_SUNKEN +$SS_CENTER+ $SS_CENTERIMAGE)&lt;br /&gt;
GUICtrlSetBkColor(-1, 0xc0c0c0)&lt;br /&gt;
GUICtrlSetColor(-1, 0x000000)&lt;br /&gt;
&lt;br /&gt;
Global Const $tab = GUICtrlCreateTab(10,40, 200, 200) ; can be placed anywhere, doesnt matter, not visible&lt;br /&gt;
GUICtrlSetState($tab, $GUI_HIDE)&lt;br /&gt;
&lt;br /&gt;
Global Const $tab1 = GUICtrlCreateTabItem(&amp;quot;tab1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
GUICtrlCreateButton(&amp;quot;button on tab 1&amp;quot;, 10, 70)&lt;br /&gt;
&lt;br /&gt;
Global Const $tab2 = GUICtrlCreateTabItem(&amp;quot;tab2&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
GUICtrlCreateButton(&amp;quot;button on tab 2&amp;quot;, 10, 70)&lt;br /&gt;
&lt;br /&gt;
GUISetState(@SW_SHOWNORMAL)&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
    Switch GUIGetMsg()&lt;br /&gt;
        Case $TabSwitcher1&lt;br /&gt;
            If GUICtrlRead($tab, 1) = $tab1 Then ContinueLoop ; To prevent the flickering and second state set.&lt;br /&gt;
            GUICtrlSetState($tab1, $GUI_SHOW)&lt;br /&gt;
            GUICtrlSetBkColor($TabSwitcher1, 0xf0f0f0)&lt;br /&gt;
            GUICtrlSetColor($TabSwitcher1, 0x000000)&lt;br /&gt;
            GUICtrlSetBkColor($TabSwitcher2, 0xc0c0c0)&lt;br /&gt;
            GUICtrlSetColor($TabSwitcher2, 0x000000)&lt;br /&gt;
&lt;br /&gt;
        Case $TabSwitcher2&lt;br /&gt;
            If GUICtrlRead($tab, 1) = $tab2 Then ContinueLoop ; To prevent the flickering and second state set.&lt;br /&gt;
            GUICtrlSetState($tab2, $GUI_SHOW)&lt;br /&gt;
            GUICtrlSetBkColor($TabSwitcher1, 0xc0c0c0)&lt;br /&gt;
            GUICtrlSetColor($TabSwitcher1, 0x000000)&lt;br /&gt;
            GUICtrlSetBkColor($TabSwitcher2, 0xf0f0f0)&lt;br /&gt;
            GUICtrlSetColor($TabSwitcher2, 0x000000)&lt;br /&gt;
&lt;br /&gt;
        Case $GUI_EVENT_CLOSE&lt;br /&gt;
            Exit&lt;br /&gt;
        Case Else&lt;br /&gt;
    EndSwitch&lt;br /&gt;
WEnd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Disable All Column Headers ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 38576-melba23&lt;br /&gt;
 | AuthorName = Melba23&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;GuiConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;GuiListView.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
_Main()&lt;br /&gt;
&lt;br /&gt;
Func _Main()&lt;br /&gt;
    Local $hGUI = GUICreate(&amp;quot;ListView Set Column Width&amp;quot;, 400, 300)&lt;br /&gt;
    Local $hListView = GUICtrlCreateListView(&amp;quot;Column 1|Column 2|Column 3|Column 4&amp;quot;, 2, 2, 394, 268)&lt;br /&gt;
    GUISetState()&lt;br /&gt;
&lt;br /&gt;
    ; Prevent resizing of columns&lt;br /&gt;
    ControlDisable($hGUI, &amp;quot;&amp;quot;, HWnd(_GUICtrlListView_GetHeader($hListView)))&lt;br /&gt;
&lt;br /&gt;
    ; Loop until user exits&lt;br /&gt;
    Do&lt;br /&gt;
    Until GUIGetMsg() = $GUI_EVENT_CLOSE&lt;br /&gt;
EndFunc   ;==&amp;gt;_Main&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Disable Specific Column Headers ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 38576-melba23&lt;br /&gt;
 | AuthorName = Melba23&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;GuiConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;GuiListView.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;HeaderConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; The 0-based column to be disabled&lt;br /&gt;
Global $iFix_Col&lt;br /&gt;
&lt;br /&gt;
_Main()&lt;br /&gt;
&lt;br /&gt;
Func _Main()&lt;br /&gt;
    Local Const $hGUI = GUICreate(&amp;quot;ListView Fix Column Width&amp;quot;, 400, 300)&lt;br /&gt;
&lt;br /&gt;
    Local Const $hListView = GUICtrlCreateListView(&amp;quot;Column 0|Column 1|Column 2|Column 3&amp;quot;, 2, 2, 394, 268)&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL)&lt;br /&gt;
&lt;br /&gt;
    ; Prevent resizing of column 1&lt;br /&gt;
    $iFix_Col = 1&lt;br /&gt;
&lt;br /&gt;
    GUIRegisterMsg($WM_NOTIFY, &amp;quot;_WM_NOTIFY&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    ; Loop until user exits&lt;br /&gt;
    Do&lt;br /&gt;
    Until GUIGetMsg() = $GUI_EVENT_CLOSE&lt;br /&gt;
EndFunc   ;==&amp;gt;_Main&lt;br /&gt;
&lt;br /&gt;
Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)&lt;br /&gt;
    #forceref $hWnd, $iMsg, $wParam&lt;br /&gt;
&lt;br /&gt;
    ; Get details of message&lt;br /&gt;
    Local Const $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)&lt;br /&gt;
&lt;br /&gt;
    ; Look for header resize code&lt;br /&gt;
    Local Const $iCode = DllStructGetData($tNMHEADER, &amp;quot;Code&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    Switch $iCode&lt;br /&gt;
        Case $HDN_BEGINTRACKW&lt;br /&gt;
            ; Now get column being resized&lt;br /&gt;
            Local $iCol = DllStructGetData($tNMHEADER, &amp;quot;Item&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
            If $iCol = $iFix_Col Then&lt;br /&gt;
                ; Prevent resizing&lt;br /&gt;
                Return True&lt;br /&gt;
            Else&lt;br /&gt;
                ; Allow resizing&lt;br /&gt;
                Return False&lt;br /&gt;
            EndIf&lt;br /&gt;
    EndSwitch&lt;br /&gt;
EndFunc   ;==&amp;gt;_WM_NOTIFY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _Flash ==&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;
; Change the background color of the GUI to a specified color&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local Const $bGreen = 0x00FF00&lt;br /&gt;
&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    If MsgBox(4 + 4096, &#039;&#039;, &#039;The following example contains flashing images.  If you are sensitive to such things then please select &amp;quot;No&amp;quot;.&#039; &amp;amp; @CRLF &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;Do you want to continue?&#039;) = 7 Then&lt;br /&gt;
        Return 0&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    ; Change the background color of the GUI to a specified color and then back to the default grey.&lt;br /&gt;
    For $i = 1 To 2&lt;br /&gt;
        _Flash($hGUI, $bGreen)&lt;br /&gt;
        Sleep(100)&lt;br /&gt;
    Next&lt;br /&gt;
&lt;br /&gt;
    ; Wait for 1 second to show the background color is changed to the default grey.&lt;br /&gt;
    Sleep(1000)&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _Flash(Const $hWnd, Const $bColor)&lt;br /&gt;
    For $A = 1 To 2&lt;br /&gt;
        If Mod($A, 2) Then ; Odd.&lt;br /&gt;
            GUISetBkColor($bColor, $hWnd)&lt;br /&gt;
        Else ; Even.&lt;br /&gt;
            GUISetBkColor(_WinAPI_GetSysColor($COLOR_MENU), $hWnd)&lt;br /&gt;
        EndIf&lt;br /&gt;
&lt;br /&gt;
        Sleep(100)&lt;br /&gt;
    Next&lt;br /&gt;
EndFunc   ;==&amp;gt;_Flash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== GUI Background Changer ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 69506-reaperx&lt;br /&gt;
 | AuthorName = ReaperX&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;GUIConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;Misc.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global Const $gui_choose_color = GUICreate(&amp;quot;Choose Color&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Global Const $button = GUICtrlCreateButton(&amp;quot;Choose Color&amp;quot;, 150, 150)&lt;br /&gt;
&lt;br /&gt;
GUISetState(@SW_SHOWNORMAL, $gui_choose_color)&lt;br /&gt;
&lt;br /&gt;
Global Const $iReturnType = 2&lt;br /&gt;
&lt;br /&gt;
Global $color&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
	Switch GUIGetMsg()&lt;br /&gt;
		Case $button&lt;br /&gt;
			$color = _ChooseColor($iReturnType)&lt;br /&gt;
			GUISetBkColor($color)&lt;br /&gt;
		Case $GUI_EVENT_CLOSE&lt;br /&gt;
			Exit&lt;br /&gt;
	EndSwitch&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Example 2&lt;br /&gt;
#include &amp;lt;GUIConstants.au3&lt;br /&gt;
&lt;br /&gt;
MainGUI()&lt;br /&gt;
&lt;br /&gt;
Func MainGUI()&lt;br /&gt;
	GUICreate(&amp;quot;ReaperX&#039;s Test GUI&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    Local Const $file = GUICtrlCreateMenu(&amp;quot;File&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	Local Const $file_notepad = GUICtrlCreateMenuItem(&amp;quot;Open Notepad&amp;quot;, $file)&lt;br /&gt;
&lt;br /&gt;
	Local Const $file_computer = GUICtrlCreateMenuItem(&amp;quot;Open My Computer&amp;quot;, $file)&lt;br /&gt;
&lt;br /&gt;
	Local Const $file_exit = GUICtrlCreateMenuItem(&amp;quot;Exit&amp;quot;, $file)&lt;br /&gt;
&lt;br /&gt;
	Local Const $actions = GUICtrlCreateMenu(&amp;quot;Actions&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	Local Const $actions_txt_file = GUICtrlCreateMenuItem(&amp;quot;Open Text File&amp;quot;, $actions)&lt;br /&gt;
&lt;br /&gt;
	Local Const $actions_calc = GUICtrlCreateMenuItem(&amp;quot;Open Calculator&amp;quot;, $actions)&lt;br /&gt;
&lt;br /&gt;
	Local Const $help = GUICtrlCreateMenu(&amp;quot;Help&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	Local Const $help_about = GUICtrlCreateMenuItem(&amp;quot;About&amp;quot;, $help)&lt;br /&gt;
&lt;br /&gt;
	Local Const $tab_set = GUICtrlCreateTab(110, 100, 135, 150)&lt;br /&gt;
&lt;br /&gt;
	Local Const $tab_1 = GUICtrlCreateTabItem(&amp;quot;Change BG&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	Local Const $bg_red_radio = GUICtrlCreateRadio(&amp;quot;Red&amp;quot;, 115, 125)&lt;br /&gt;
&lt;br /&gt;
	Local Const $bg_green_radio = GUICtrlCreateRadio(&amp;quot;Green&amp;quot;, 115, 145)&lt;br /&gt;
&lt;br /&gt;
	Local Const $bg_yellow_radio = GUICtrlCreateRadio(&amp;quot;Yellow&amp;quot;, 115, 165)&lt;br /&gt;
&lt;br /&gt;
	Local Const $tab_2 = GUICtrlCreateTabItem(&amp;quot;AutoIt Info&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL)&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
		Switch GUIGetMsg()&lt;br /&gt;
			Case $GUI_EVENT_CLOSE&lt;br /&gt;
				ExitLoop&lt;br /&gt;
			Case $file_notepad&lt;br /&gt;
				Run(&amp;quot;notepad.exe&amp;quot;)&lt;br /&gt;
			Case $file_computer&lt;br /&gt;
				Run(&amp;quot;explorer.exe&amp;quot;)&lt;br /&gt;
			Case $file_exit&lt;br /&gt;
				Exit&lt;br /&gt;
			Case $actions_txt_file&lt;br /&gt;
				Local Const $txt_file_1 = FileOpenDialog(&amp;quot;Choose a Text File to Open...&amp;quot;, @DesktopDir, &amp;quot;Text Files(*.txt)&amp;quot;)&lt;br /&gt;
				FileOpen($txt_file_1)&lt;br /&gt;
			Case $actions_calc&lt;br /&gt;
				Run(&amp;quot;calc.exe&amp;quot;)&lt;br /&gt;
			Case $help_about&lt;br /&gt;
				MsgBox(0, &amp;quot;About&amp;quot;, &amp;quot;This Test GUI Was Created by ReaperX&amp;quot;)&lt;br /&gt;
			Case $bg_red_radio&lt;br /&gt;
				GUISetBkColor(0xED1C24)&lt;br /&gt;
			Case $bg_green_radio&lt;br /&gt;
				GUISetBkColor(0x22B14C)&lt;br /&gt;
			Case $bg_yellow_radio&lt;br /&gt;
				GUISetBkColor(0xFFF200)&lt;br /&gt;
		EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== GUICtrlGetID ==&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;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local Const $hGUI = GUICreate(&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
    Local Const $iLabel = GUICtrlCreateLabel(&#039;&#039;, 0, 0, 500, 500)&lt;br /&gt;
&lt;br /&gt;
    Local Const $iComboBox = GUICtrlCreateCombo(&#039;&#039;, 0, 0, 500, 500)&lt;br /&gt;
&lt;br /&gt;
    GUISetState(@SW_SHOWNORMAL, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, _&lt;br /&gt;
	        &#039;AutoIt Label ID: &#039;                &amp;amp; $iLabel &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt Label ID From Handle: &#039;    &amp;amp; GUICtrlGetID(GUICtrlGetHandle($iLabel)) &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt ComboBox ID: &#039;             &amp;amp; $iComboBox &amp;amp; @CRLF &amp;amp; _&lt;br /&gt;
            &#039;AutoIt ComboBox ID From Handle: &#039; &amp;amp; GUICtrlGetID(GUICtrlGetHandle($iComboBox)) &amp;amp; @CRLF)&lt;br /&gt;
&lt;br /&gt;
    Return GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Retrieve the control id of an AutoIt native control using the handle returned by GUICtrlGetHandle.&lt;br /&gt;
Func GUICtrlGetID(Const $hWnd)&lt;br /&gt;
    Local Const $aResult = DllCall(&#039;user32.dll&#039;, &#039;int&#039;, &#039;GetDlgCtrlID&#039;, &#039;hwnd&#039;, $hWnd) ; _WinAPI_GetDlgItem in WinAPI.au3.&lt;br /&gt;
&lt;br /&gt;
	If @error Then&lt;br /&gt;
        Return SetError(@error, @extended, 0)&lt;br /&gt;
    EndIf&lt;br /&gt;
&lt;br /&gt;
    Return $aResult[0]&lt;br /&gt;
EndFunc   ;==&amp;gt;GUICtrlGetID&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _GUICtrlIpAddress_DisableField ==&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;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIIPAddress.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $hGUI, $hIPAddress&lt;br /&gt;
    $hGUI = GUICreate(&#039;IP Address Control Create Example&#039;, 400, 300)&lt;br /&gt;
    $hIPAddress = _GUICtrlIpAddress_Create($hGUI, 10, 10)&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    _GUICtrlIpAddress_Set($hIPAddress, &#039;127.0.0.1&#039;)&lt;br /&gt;
    _GUICtrlIpAddress_DisableField($hIPAddress, 0)&lt;br /&gt;
    _GUICtrlIpAddress_DisableField($hIPAddress, 3)&lt;br /&gt;
&lt;br /&gt;
    Do&lt;br /&gt;
    Until GUIGetMsg() = $GUI_EVENT_CLOSE&lt;br /&gt;
    _GUICtrlIpAddress_Destroy($hIPAddress)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Disable an octet field. First octet field starts from index 0.&lt;br /&gt;
Func _GUICtrlIpAddress_DisableField($hIPAddress, $iField) ; Idea by Rover.&lt;br /&gt;
    Local $aField[5] = [4, 3, 2, 1]&lt;br /&gt;
    Return ControlDisable($hIPAddress, &#039;&#039;, &#039;[CLASSNN:Edit&#039; &amp;amp; $aField[$iField] &amp;amp; &#039;]&#039;)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GUICtrlIpAddress_DisableField&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== GUI With Scrollable TabItem ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 46198-autobert&lt;br /&gt;
 | AuthorName = AutoBert&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; GUI With Scrollable TabItem&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;ScrollBarConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;GuiScrollBars.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;GuiTab.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global Const $hGui = GUICreate(&amp;quot;Gui with scrollable TabItem &amp;quot;, 633, 350, 190, 220&lt;br /&gt;
GUISetBkColor(0xFFFFFF)&lt;br /&gt;
&lt;br /&gt;
Global Const $idTab = GUICtrlCreateTab(10, 10, 613, 300)&lt;br /&gt;
&lt;br /&gt;
Global Const $idTab0 = GUICtrlCreateTabItem(&amp;quot;tab0&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Global Const $hChild = GUICreate(&amp;quot;Scrollbereich&amp;quot;, 588, 255, 26, 45, $WS_POPUP, $WS_EX_MDICHILD, $hGui)&lt;br /&gt;
&lt;br /&gt;
Global $x = 6 ; +22&lt;br /&gt;
Global $y = 8&lt;br /&gt;
&lt;br /&gt;
Global $aInputs[15]&lt;br /&gt;
&lt;br /&gt;
For $i = 0 To 14&lt;br /&gt;
	$aInputs[$i] = GUICtrlCreateInput(&#039;&#039;, $x, $y, 21, 20)&lt;br /&gt;
	$x += 22&lt;br /&gt;
	$y += 21&lt;br /&gt;
Next&lt;br /&gt;
&lt;br /&gt;
_GUIScrollBars_Init($hChild, -1)&lt;br /&gt;
_GUIScrollBars_ShowScrollBar($hChild, $SB_HORZ, False) ; horizontale Scrollbar verstecken&lt;br /&gt;
_GUIScrollBars_SetScrollRange($hChild, $SB_VERT, 3, 30)&lt;br /&gt;
&lt;br /&gt;
GUISetState(@SW_HIDE, $hChild)&lt;br /&gt;
&lt;br /&gt;
GUISwitch($hGui)&lt;br /&gt;
&lt;br /&gt;
Global Const $idTab1 = GUICtrlCreateTabItem(&amp;quot;tab----1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
GUICtrlCreateLabel(&amp;quot;label1&amp;quot;, 30, 80, 50, 20)&lt;br /&gt;
&lt;br /&gt;
Global Const $idTab1combo = GUICtrlCreateCombo(&amp;quot;&amp;quot;, 20, 50, 60, 120)&lt;br /&gt;
&lt;br /&gt;
GUICtrlSetData($idTab1combo, &amp;quot;Trids|CyberSlug|Larry|Jon|Tylo&amp;quot;, &amp;quot;Jon&amp;quot;); default Jon&lt;br /&gt;
&lt;br /&gt;
Global Const $idTab1OK = GUICtrlCreateButton(&amp;quot;OK1&amp;quot;, 80, 50, 50, 20)&lt;br /&gt;
&lt;br /&gt;
Global Const $idTab2 = GUICtrlCreateTabItem(&amp;quot;tab2&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
GUICtrlSetState($idTab2, $Gui_SHOW); will be display first&lt;br /&gt;
&lt;br /&gt;
GUICtrlCreateLabel(&amp;quot;label2&amp;quot;, 30, 80, 50, 20)&lt;br /&gt;
&lt;br /&gt;
Global Const $idTab2OK = GUICtrlCreateButton(&amp;quot;OK2&amp;quot;, 140, 50, 50)&lt;br /&gt;
&lt;br /&gt;
GUICtrlCreateTabItem(&amp;quot;&amp;quot;); end tabitem definition&lt;br /&gt;
&lt;br /&gt;
Global Const $idBtnBack = GUICtrlCreateButton(&amp;quot;&amp;amp;Zurueck&amp;quot;, 72, 320, 100, 25)&lt;br /&gt;
&lt;br /&gt;
Global Const $idBtnCancel = GUICtrlCreateButton(&amp;quot;&amp;amp;Beenden&amp;quot;, 264, 320, 100, 25)&lt;br /&gt;
&lt;br /&gt;
Global Const $idBtnContinue = GUICtrlCreateButton(&amp;quot;&amp;amp;Weiter&amp;quot;, 448, 320, 100, 25)&lt;br /&gt;
&lt;br /&gt;
GUISetState(@SW_SHOWNORMAL)&lt;br /&gt;
&lt;br /&gt;
GUIRegisterMsg($WM_VSCROLL, &amp;quot;WM_VSCROLL&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
	Switch GUIGetMsg()&lt;br /&gt;
		Case $GUI_EVENT_CLOSE&lt;br /&gt;
			Exit&lt;br /&gt;
		Case $idTab&lt;br /&gt;
			Switch _GUICtrlTab_GetCurSel($idTab)&lt;br /&gt;
				Case 0&lt;br /&gt;
					GUISetState(@SW_SHOW, $hChild)&lt;br /&gt;
				Case 1&lt;br /&gt;
					GUISetState(@SW_HIDE, $hChild)&lt;br /&gt;
			EndSwitch&lt;br /&gt;
	EndSwitch&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)&lt;br /&gt;
	#forceref $Msg, $wParam, $lParam&lt;br /&gt;
	Local $nScrollCode = BitAND($wParam, 0x0000FFFF)&lt;br /&gt;
	Local $index = -1, $yChar, $yPos&lt;br /&gt;
	Local $Min, $Max, $Page, $Pos, $TrackPos&lt;br /&gt;
&lt;br /&gt;
	For $x = 0 To UBound($aSB_WindowInfo) - 1&lt;br /&gt;
		If $aSB_WindowInfo[$x][0] = $hWnd Then&lt;br /&gt;
			$index = $x&lt;br /&gt;
			$yChar = $aSB_WindowInfo[$index][3]&lt;br /&gt;
			ExitLoop&lt;br /&gt;
		EndIf&lt;br /&gt;
	Next&lt;br /&gt;
&lt;br /&gt;
	If $index = -1 Then Return 0&lt;br /&gt;
&lt;br /&gt;
	; Get all the vertial scroll bar information&lt;br /&gt;
	Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)&lt;br /&gt;
	$Min = DllStructGetData($tSCROLLINFO, &amp;quot;nMin&amp;quot;)&lt;br /&gt;
	$Max = DllStructGetData($tSCROLLINFO, &amp;quot;nMax&amp;quot;)&lt;br /&gt;
	$Page = DllStructGetData($tSCROLLINFO, &amp;quot;nPage&amp;quot;)&lt;br /&gt;
	; Save the position for comparison later on&lt;br /&gt;
	$yPos = DllStructGetData($tSCROLLINFO, &amp;quot;nPos&amp;quot;)&lt;br /&gt;
	$Pos = $yPos&lt;br /&gt;
&lt;br /&gt;
	$TrackPos = DllStructGetData($tSCROLLINFO, &amp;quot;nTrackPos&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	Switch $nScrollCode&lt;br /&gt;
		Case $SB_TOP ; user clicked the HOME keyboard key&lt;br /&gt;
			DllStructSetData($tSCROLLINFO, &amp;quot;nPos&amp;quot;, $Min)&lt;br /&gt;
		Case $SB_BOTTOM ; user clicked the END keyboard key&lt;br /&gt;
			DllStructSetData($tSCROLLINFO, &amp;quot;nPos&amp;quot;, $Max)&lt;br /&gt;
		Case $SB_LINEUP ; user clicked the top arrow&lt;br /&gt;
			DllStructSetData($tSCROLLINFO, &amp;quot;nPos&amp;quot;, $Pos - 1)&lt;br /&gt;
		Case $SB_LINEDOWN ; user clicked the bottom arrow&lt;br /&gt;
			DllStructSetData($tSCROLLINFO, &amp;quot;nPos&amp;quot;, $Pos + 1)&lt;br /&gt;
		Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box&lt;br /&gt;
			DllStructSetData($tSCROLLINFO, &amp;quot;nPos&amp;quot;, $Pos - $Page)&lt;br /&gt;
		Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box&lt;br /&gt;
			DllStructSetData($tSCROLLINFO, &amp;quot;nPos&amp;quot;, $Pos + $Page)&lt;br /&gt;
		Case $SB_THUMBTRACK ; user dragged the scroll box&lt;br /&gt;
			DllStructSetData($tSCROLLINFO, &amp;quot;nPos&amp;quot;, $TrackPos)&lt;br /&gt;
	EndSwitch&lt;br /&gt;
&lt;br /&gt;
	; Set the position and then retrieve it.  Due to adjustments&lt;br /&gt;
	; by Windows it may not be the same as the value set.&lt;br /&gt;
	DllStructSetData($tSCROLLINFO, &amp;quot;fMask&amp;quot;, $SIF_POS)&lt;br /&gt;
	_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)&lt;br /&gt;
	_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)&lt;br /&gt;
	; If the position has changed, scroll the window and update it&lt;br /&gt;
	$Pos = DllStructGetData($tSCROLLINFO, &amp;quot;nPos&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	If $Pos &amp;lt;&amp;gt; $yPos Then&lt;br /&gt;
		_GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))&lt;br /&gt;
		$yPos = $Pos&lt;br /&gt;
	EndIf&lt;br /&gt;
&lt;br /&gt;
	Return $GUI_RUNDEFMSG&lt;br /&gt;
EndFunc   ;==&amp;gt;WM_VSCROLL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsAutoItGUI ==&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;WinAPI.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;
&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    ; Check if the handle is an AutoIt GUI.&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;Is the handle of the GUI an AutoIt window: &#039; &amp;amp; _IsAutoItGUI($hGUI))&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Check if a handle is an AutoIt GUI.&lt;br /&gt;
Func _IsAutoItGUI($hWnd)&lt;br /&gt;
    Return _WinAPI_GetClassName($hWnd) = &#039;AutoIt v3 GUI&#039;&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsAutoItGUI&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsEnabled ==&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;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    Local $aState[2] = [$GUI_ENABLE, $GUI_DISABLE]&lt;br /&gt;
    GUICreate(&#039;&#039;)&lt;br /&gt;
    Local $iButton = GUICtrlCreateButton(&#039;Button Example&#039;, 10, 10, 120, 25)&lt;br /&gt;
    GUICtrlSetState($iButton, $aState[Random(0, 1, 1)]) ; Randomise whether or not the Button is enabled.&lt;br /&gt;
    GUISetState(@SW_SHOW)&lt;br /&gt;
&lt;br /&gt;
    ; Check the state of the Button.&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;Is the Button enabled: &#039; &amp;amp; _IsEnabled($iButton))&lt;br /&gt;
&lt;br /&gt;
    While 1&lt;br /&gt;
        Switch GUIGetMsg()&lt;br /&gt;
            Case $GUI_EVENT_CLOSE&lt;br /&gt;
                ExitLoop&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _IsEnabled($iControlID)&lt;br /&gt;
    Return BitAND(GUICtrlGetState($iControlID), $GUI_ENABLE) = $GUI_ENABLE&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsEnabled&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _IsTransparent ==&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;WinAPI.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;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    ; Set the transparency of a GUI between 0 and 255. 255 = Solid, 0 = Invisible.&lt;br /&gt;
    WinSetTrans($hGUI, &#039;&#039;, Random(0, 255, 1))&lt;br /&gt;
&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;Check if the GUI is transparent: &#039; &amp;amp; _IsTransparent($hGUI))&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Check if the GUI is transparent.&lt;br /&gt;
Func _IsTransparent($sTitle, $sText = &#039;&#039;)&lt;br /&gt;
    Local $iTransColor = 0, $iTransparency = 255&lt;br /&gt;
    _WinAPI_GetLayeredWindowAttributes(WinGetHandle($sTitle, $sText), $iTransColor, $iTransparency)&lt;br /&gt;
    Return $iTransparency = 0&lt;br /&gt;
EndFunc   ;==&amp;gt;_IsTransparent&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
==  Limit GUI Resize ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 38576-melba23&lt;br /&gt;
 | AuthorName = Melba23&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; How to limit the minimum/maximum size of a resizable GUI&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
GUIRegisterMsg($WM_GETMINMAXINFO, &amp;quot;WM_GETMINMAXINFO&amp;quot;)&lt;br /&gt;
Global $hGUI = GUICreate(&amp;quot;Test&amp;quot;, 500, 500, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))&lt;br /&gt;
GUISetState()&lt;br /&gt;
Global $aPos = WinGetPos($hGUI)&lt;br /&gt;
While 1&lt;br /&gt;
    Switch GUIGetMsg()&lt;br /&gt;
        Case $GUI_EVENT_MAXIMIZE&lt;br /&gt;
            WinMove($hGUI, &amp;quot;&amp;quot;, $aPos[0], $aPos[1], $aPos[2], $aPos[3]) ; resets intial size&lt;br /&gt;
        Case $GUI_EVENT_CLOSE&lt;br /&gt;
            Exit&lt;br /&gt;
    EndSwitch&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam)&lt;br /&gt;
    #forceref $hwnd, $Msg, $wParam, $lParam&lt;br /&gt;
    Local $GUIMINWID = 300, $GUIMINHT = 100 ; set your restrictions here&lt;br /&gt;
    Local $GUIMAXWID = 800, $GUIMAXHT = 500&lt;br /&gt;
    Local $tagMaxinfo = DllStructCreate(&amp;quot;int;int;int;int;int;int;int;int;int;int&amp;quot;, $lParam)&lt;br /&gt;
    DllStructSetData($tagMaxinfo, 7, $GUIMINWID) ; min X&lt;br /&gt;
    DllStructSetData($tagMaxinfo, 8, $GUIMINHT) ; min Y&lt;br /&gt;
    DllStructSetData($tagMaxinfo, 9, $GUIMAXWID); max X&lt;br /&gt;
    DllStructSetData($tagMaxinfo, 10, $GUIMAXHT) ; max Y&lt;br /&gt;
    Return 0&lt;br /&gt;
EndFunc   ;==&amp;gt;WM_GETMINMAXINFO&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Mixed Colored List View ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 23675-siao&lt;br /&gt;
 | AuthorName = Siao&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;GuiConstantsEx.au3&amp;gt;&lt;br /&gt;
#Include &amp;lt;GuiListView.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;fonts for custom draw example&lt;br /&gt;
;bold&lt;br /&gt;
Global $aFont1 = DLLCall(&amp;quot;gdi32.dll&amp;quot;,&amp;quot;int&amp;quot;,&amp;quot;CreateFont&amp;quot;, &amp;quot;int&amp;quot;, 14, &amp;quot;int&amp;quot;, 0, &amp;quot;int&amp;quot;, 0, &amp;quot;int&amp;quot;, 0, &amp;quot;int&amp;quot;, 700, _&lt;br /&gt;
                        &amp;quot;dword&amp;quot;, 0, &amp;quot;dword&amp;quot;, 0, &amp;quot;dword&amp;quot;, 0, &amp;quot;dword&amp;quot;, 0, &amp;quot;dword&amp;quot;, 0, &amp;quot;dword&amp;quot;, 0, &amp;quot;dword&amp;quot;, 0, _&lt;br /&gt;
                        &amp;quot;dword&amp;quot;, 0, &amp;quot;str&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
;italic&lt;br /&gt;
Global $aFont2 = DLLCall(&amp;quot;gdi32.dll&amp;quot;,&amp;quot;int&amp;quot;,&amp;quot;CreateFont&amp;quot;, &amp;quot;int&amp;quot;, 14, &amp;quot;int&amp;quot;, 0, &amp;quot;int&amp;quot;, 0, &amp;quot;int&amp;quot;, 0, &amp;quot;int&amp;quot;, 400, _&lt;br /&gt;
                        &amp;quot;dword&amp;quot;, 1, &amp;quot;dword&amp;quot;, 0, &amp;quot;dword&amp;quot;, 0, &amp;quot;dword&amp;quot;, 0, &amp;quot;dword&amp;quot;, 0, &amp;quot;dword&amp;quot;, 0, &amp;quot;dword&amp;quot;, 0, _&lt;br /&gt;
                        &amp;quot;dword&amp;quot;, 0, &amp;quot;str&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
$GUI = GUICreate(&amp;quot;Listview Custom Draw&amp;quot;, 400, 300)&lt;br /&gt;
$cListView = GUICtrlCreateListView(&amp;quot;&amp;quot;, 2, 2, 394, 268)&lt;br /&gt;
$hListView = GUICtrlGetHandle($cListView)&lt;br /&gt;
;or&lt;br /&gt;
;~ $hListView = _GUICtrlListView_Create($GUI, &amp;quot;&amp;quot;, 2, 2, 394, 268)&lt;br /&gt;
&lt;br /&gt;
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))&lt;br /&gt;
_GUICtrlListView_InsertColumn($hListView, 0, &amp;quot;Column 1&amp;quot;, 100)&lt;br /&gt;
_GUICtrlListView_InsertColumn($hListView, 1, &amp;quot;Column 2&amp;quot;, 100)&lt;br /&gt;
_GUICtrlListView_InsertColumn($hListView, 2, &amp;quot;Column 3&amp;quot;, 100)&lt;br /&gt;
&lt;br /&gt;
; Add items&lt;br /&gt;
For $i = 1 To 30&lt;br /&gt;
    _GUICtrlListView_AddItem($hListView, &amp;quot;Row&amp;quot; &amp;amp; $i &amp;amp; &amp;quot;: Col 1&amp;quot;, $i-1)&lt;br /&gt;
    For $j = 1 To 2&lt;br /&gt;
        _GUICtrlListView_AddSubItem ($hListView, $i-1, &amp;quot;Row&amp;quot; &amp;amp; $i &amp;amp; &amp;quot;: Col &amp;quot; &amp;amp; $j+1, $j)&lt;br /&gt;
    Next&lt;br /&gt;
Next&lt;br /&gt;
GUIRegisterMsg($WM_NOTIFY, &amp;quot;WM_NOTIFY&amp;quot;)&lt;br /&gt;
GUISetState()&lt;br /&gt;
&lt;br /&gt;
Do&lt;br /&gt;
Until GUIGetMsg() = $GUI_EVENT_CLOSE&lt;br /&gt;
DLLCall(&amp;quot;gdi32.dll&amp;quot;,&amp;quot;int&amp;quot;,&amp;quot;DeleteObject&amp;quot;, &amp;quot;hwnd&amp;quot;, $aFont1[0])&lt;br /&gt;
DLLCall(&amp;quot;gdi32.dll&amp;quot;,&amp;quot;int&amp;quot;,&amp;quot;DeleteObject&amp;quot;, &amp;quot;hwnd&amp;quot;, $aFont2[0])&lt;br /&gt;
Exit&lt;br /&gt;
&lt;br /&gt;
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)&lt;br /&gt;
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR&lt;br /&gt;
&lt;br /&gt;
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)&lt;br /&gt;
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, &amp;quot;hWndFrom&amp;quot;))&lt;br /&gt;
    $iIDFrom = DllStructGetData($tNMHDR, &amp;quot;IDFrom&amp;quot;)&lt;br /&gt;
    $iCode = DllStructGetData($tNMHDR, &amp;quot;Code&amp;quot;)&lt;br /&gt;
    Switch $hWndFrom&lt;br /&gt;
        Case $hListView&lt;br /&gt;
            Switch $iCode&lt;br /&gt;
                Case $NM_CUSTOMDRAW&lt;br /&gt;
                    If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG&lt;br /&gt;
                     Local $tCustDraw = DllStructCreate(&#039;hwnd hwndFrom;int idFrom;int code;&#039; &amp;amp; _&lt;br /&gt;
                                        &#039;dword DrawStage;hwnd hdc;long rect[4];dword ItemSpec;int ItemState;dword Itemlparam;&#039; &amp;amp; _&lt;br /&gt;
                                        &#039;dword clrText;dword clrTextBk;int SubItem;&#039; &amp;amp; _&lt;br /&gt;
                                        &#039;dword ItemType;dword clrFace;int IconEffect;int IconPhase;int PartID;int StateID;long rectText[4];int Align&#039;, _ ;winxp or later&lt;br /&gt;
                                        $lParam), $iDrawStage, $iItem, $iSubitem, $hDC, $iColor1, $iColor2, $iColor3&lt;br /&gt;
                    $iDrawStage = DllStructGetData($tCustDraw, &#039;DrawStage&#039;)&lt;br /&gt;
                    If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW ;request custom drawing of items&lt;br /&gt;
                    If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW ;request drawing each cell separately&lt;br /&gt;
                    If Not BitAND($iDrawStage, $CDDS_SUBITEM) Then Return $CDRF_DODEFAULT&lt;br /&gt;
                    $iItem = DllStructGetData($tCustDraw, &#039;ItemSpec&#039;)&lt;br /&gt;
                    $iSubitem = DllStructGetData($tCustDraw, &#039;SubItem&#039;)&lt;br /&gt;
                    Switch $iItem&lt;br /&gt;
                        Case 0 To 9 ;for rows 1-10 lets do this&lt;br /&gt;
                            $iColor1 = RGB2BGR(0xFBFFD8)&lt;br /&gt;
                            $iColor2 = RGB2BGR(-1)&lt;br /&gt;
                            $iColor3 = RGB2BGR(0xFF0000)&lt;br /&gt;
                            If Mod($iSubitem, 2) Then ;odd columns&lt;br /&gt;
                                DllStructSetData($tCustDraw, &#039;clrTextBk&#039;, $iColor1)&lt;br /&gt;
                                DllStructSetData($tCustDraw, &#039;clrText&#039;, 0)&lt;br /&gt;
                            Else ;even columns&lt;br /&gt;
                                DllStructSetData($tCustDraw, &#039;clrTextBk&#039;, $iColor2)&lt;br /&gt;
                                DllStructSetData($tCustDraw, &#039;clrText&#039;, $iColor3)&lt;br /&gt;
                            EndIf&lt;br /&gt;
                        Case 10 To 19 ;for rows 11-20 lets do this&lt;br /&gt;
                            $iColor1 = RGB2BGR(0xFBFFD8)&lt;br /&gt;
                            $iColor2 = RGB2BGR(0x3DF8FF)&lt;br /&gt;
                            $hDC = DllStructGetData($tCustDraw, &#039;hdc&#039;)&lt;br /&gt;
                            If Mod($iItem, 2) Then&lt;br /&gt;
                                If Mod($iSubitem, 2) Then&lt;br /&gt;
                                    DllStructSetData($tCustDraw, &#039;clrTextBk&#039;, $iColor1)&lt;br /&gt;
                                Else&lt;br /&gt;
                                    DllStructSetData($tCustDraw, &#039;clrTextBk&#039;, $iColor2)&lt;br /&gt;
                                EndIf&lt;br /&gt;
                                DLLCall(&amp;quot;gdi32.dll&amp;quot;,&amp;quot;hwnd&amp;quot;,&amp;quot;SelectObject&amp;quot;, &amp;quot;hwnd&amp;quot;, $hDC, &amp;quot;hwnd&amp;quot;, $aFont1[0]) ;select our chosen font into DC&lt;br /&gt;
                            Else&lt;br /&gt;
                                If Mod($iSubitem, 2) Then&lt;br /&gt;
                                    DllStructSetData($tCustDraw, &#039;clrTextBk&#039;, $iColor2)&lt;br /&gt;
                                Else&lt;br /&gt;
                                    DllStructSetData($tCustDraw, &#039;clrTextBk&#039;, $iColor1)&lt;br /&gt;
                                EndIf&lt;br /&gt;
                                DLLCall(&amp;quot;gdi32.dll&amp;quot;,&amp;quot;hwnd&amp;quot;,&amp;quot;SelectObject&amp;quot;, &amp;quot;hwnd&amp;quot;, $hDC, &amp;quot;hwnd&amp;quot;, $aFont2[0])&lt;br /&gt;
                            EndIf&lt;br /&gt;
                        Case 20 To 29 ;for rows 21-30 lets do this&lt;br /&gt;
                            $iColor1 = RGB2BGR(0xFBFFD8)&lt;br /&gt;
                            $iColor2 = RGB2BGR(-1)&lt;br /&gt;
                            If Mod($iItem, 2) Then ;odd rows&lt;br /&gt;
                                DllStructSetData($tCustDraw, &#039;clrTextBk&#039;, $iColor2)&lt;br /&gt;
                            Else&lt;br /&gt;
                                DllStructSetData($tCustDraw, &#039;clrTextBk&#039;, $iColor1)&lt;br /&gt;
                            EndIf&lt;br /&gt;
                    EndSwitch&lt;br /&gt;
                    Return $CDRF_NEWFONT&lt;br /&gt;
            EndSwitch&lt;br /&gt;
    EndSwitch&lt;br /&gt;
    Return $GUI_RUNDEFMSG&lt;br /&gt;
EndFunc   ;==&amp;gt;WM_NOTIFY&lt;br /&gt;
&lt;br /&gt;
Func RGB2BGR($iColor)&lt;br /&gt;
    Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Move Message Box ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 423-herewasplato&lt;br /&gt;
 | AuthorName = herewasplato&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Move Message Box&lt;br /&gt;
&lt;br /&gt;
_MoveMsgBox(0, &amp;quot;testTitle&amp;quot;, &amp;quot;testText&amp;quot;, 0, 10)&lt;br /&gt;
&lt;br /&gt;
Func _MoveMsgBox($MBFlag, $MBTitle, $MBText, $x, $y)&lt;br /&gt;
    Local $file = FileOpen(EnvGet(&amp;quot;temp&amp;quot;) &amp;amp; &amp;quot;\MoveMB.au3&amp;quot;, 2)&lt;br /&gt;
    If $file = -1 Then Return;if error, give up on the move&lt;br /&gt;
&lt;br /&gt;
    Local $line1 = &#039;AutoItSetOption(&#039; &amp;amp; &#039;&amp;quot;WinWaitDelay&amp;quot;, 0&#039; &amp;amp; &#039;)&#039;&lt;br /&gt;
    Local $line2 = &#039;WinWait(&amp;quot;&#039; &amp;amp; $MBTitle &amp;amp; &#039;&amp;quot;, &amp;quot;&#039; &amp;amp; $MBText &amp;amp; &#039;&amp;quot;)&#039;&lt;br /&gt;
    Local $line3 = &#039;WinMove(&amp;quot;&#039; &amp;amp; $MBTitle &amp;amp; &#039;&amp;quot;, &amp;quot;&#039; &amp;amp; $MBText &amp;amp; &#039;&amp;quot;&#039; &amp;amp; &#039;, &#039; &amp;amp; $x &amp;amp; &#039;, &#039; &amp;amp; $y &amp;amp; &#039;)&#039;&lt;br /&gt;
    FileWrite($file, $line1 &amp;amp; @CRLF &amp;amp; $line2 &amp;amp; @CRLF &amp;amp; $line3)&lt;br /&gt;
    FileClose($file)&lt;br /&gt;
&lt;br /&gt;
    Run(@AutoItExe &amp;amp; &amp;quot; /AutoIt3ExecuteScript &amp;quot; &amp;amp; EnvGet(&amp;quot;temp&amp;quot;) &amp;amp; &amp;quot;\MoveMB.au3&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	Local $result = MsgBox($MBFlag, $MBTitle, $MBText)&lt;br /&gt;
;~     MsgBox($MBFlag, $MBTitle, $MBText)&lt;br /&gt;
&lt;br /&gt;
    FileDelete(EnvGet(&amp;quot;temp&amp;quot;) &amp;amp; &amp;quot;\MoveMB.au3&amp;quot;)&lt;br /&gt;
	Return ($result)&lt;br /&gt;
EndFunc;==&amp;gt;_MoveMsgBox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Search In A Listview ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 7108-xenobiologist&lt;br /&gt;
 | AuthorName = Xenobiologist&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Search in a Listview and show the row with the match as the top row in the listiview.&lt;br /&gt;
#include &amp;lt;GuiListView.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
_main()&lt;br /&gt;
&lt;br /&gt;
Func _main()&lt;br /&gt;
	Local $hGUI = GUICreate(&amp;quot;Test&amp;quot;, 500, 500)&lt;br /&gt;
	Local $hListView = GUICtrlCreateListView(&amp;quot;Items&amp;quot;, 10, 10, 480, 380)&lt;br /&gt;
	_GUICtrlListView_SetColumnWidth($hListView, 0, 450)&lt;br /&gt;
	For $i = 0 To 250&lt;br /&gt;
		Switch $i&lt;br /&gt;
			Case 50, 100, 150, 200&lt;br /&gt;
				GUICtrlCreateListViewItem(&amp;quot;Item 999&amp;quot;, $hListView)&lt;br /&gt;
			Case Else&lt;br /&gt;
				GUICtrlCreateListViewItem(&amp;quot;Item &amp;quot; &amp;amp; StringFormat(&amp;quot;%03i&amp;quot;, $i), $hListView)&lt;br /&gt;
		EndSwitch&lt;br /&gt;
	Next&lt;br /&gt;
	Local $hButton = GUICtrlCreateButton(&amp;quot;Search&amp;quot;, 10, 460, 100, 30, 0x0001) ; DEFAULT_BUTTON&lt;br /&gt;
	Local $hInput = GUICtrlCreateInput(&amp;quot;999&amp;quot;, 200, 460, 100, 30)&lt;br /&gt;
	GUICtrlSetState($hInput, 256) ; FOCUS&lt;br /&gt;
	GUICtrlCreateLabel(&amp;quot;Search for 999 - the listview will show the match as top row&amp;quot;, 10, 410, 470, 30)&lt;br /&gt;
	GUISetState()&lt;br /&gt;
	While 1&lt;br /&gt;
		Switch GUIGetMsg()&lt;br /&gt;
			Case -3 ; EVENT_CLOSE&lt;br /&gt;
				Exit&lt;br /&gt;
			Case $hButton&lt;br /&gt;
				_search($hListView, GUICtrlRead($hInput))&lt;br /&gt;
		EndSwitch&lt;br /&gt;
	WEnd&lt;br /&gt;
EndFunc   ;==&amp;gt;_main&lt;br /&gt;
Func _search($hLV, $startPos = 0)&lt;br /&gt;
	_GUICtrlListView_ClickItem($hLV, _GUICtrlListView_GetTopIndex($hLV)) ;&lt;br /&gt;
	Local $selIndex_A = _GUICtrlListView_GetSelectedIndices($hLV, True)&lt;br /&gt;
	Local $iIndex = _GUICtrlListView_FindInText($hLV, $startPos, $selIndex_A[1])&lt;br /&gt;
	; Scroll to bottom&lt;br /&gt;
	_GUICtrlListView_EnsureVisible($hLV, _GUICtrlListView_GetItemCount($hLV) - 1)&lt;br /&gt;
	; Now click item and we get it at the top - or as close as it will go&lt;br /&gt;
	_GUICtrlListView_SetItemFocused($hLV, $iIndex)&lt;br /&gt;
	_GUICtrlListView_ClickItem($hLV, $iIndex)&lt;br /&gt;
EndFunc   ;==&amp;gt;_search&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _SetWinTitle ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 52-geosoft&lt;br /&gt;
 | AuthorName = GEOSoft&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
Local $Frm_Main = GUICreate(&amp;quot;&amp;quot;)&lt;br /&gt;
_SetWinTitle($Frm_Main)&lt;br /&gt;
GUISetState()&lt;br /&gt;
While 1&lt;br /&gt;
	Local $Msg = GUIGetMsg()&lt;br /&gt;
	If @MIN = &#039;00&#039; Then _SetWinTitle($Frm_Main)&lt;br /&gt;
	If $Msg = -3 Then Exit&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func _SetWinTitle($hwnd)&lt;br /&gt;
	Local $Greet, $Ttl&lt;br /&gt;
	If @HOUR &amp;gt;= 5 And @HOUR &amp;lt;= 11 Then $Greet = &#039;Morning  &#039;&lt;br /&gt;
	If @HOUR &amp;gt;= 12 And @HOUR &amp;lt; 17 Then $Greet = &#039;Afternoon  &#039;&lt;br /&gt;
	If @HOUR &amp;gt;= 17 Then $Greet = &#039;Evening  &#039;&lt;br /&gt;
	If @HOUR &amp;lt; 5 Then&lt;br /&gt;
		$Ttl = &amp;quot;You&#039;re up a bit too late  &amp;quot; &amp;amp; @UserName&lt;br /&gt;
	Else&lt;br /&gt;
		$Ttl = &#039;Good &#039; &amp;amp; $Greet &amp;amp; @UserName&lt;br /&gt;
	EndIf&lt;br /&gt;
	WinSetTitle($hwnd, &#039;&#039;, $Ttl)&lt;br /&gt;
EndFunc   ;==&amp;gt;_SetWinTitle&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Small Cue Banner ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 35302-guinness&lt;br /&gt;
 | AuthorName = guinness&lt;br /&gt;
 | Desc = Idea by: [http://www.autoitscript.com/forum/user/70983-autolaser/ Autolaser]&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;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;GuiEdit.au3&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;
	Local $hGUI = GUICreate(&#039;Example&#039;, 300, 150)&lt;br /&gt;
	GUISetFont(9, 400, 0, &#039;Segoe UI&#039;)&lt;br /&gt;
&lt;br /&gt;
	Local $iUsername = GUICtrlCreateInput(&#039;&#039;, 10, 10, 125, 25)&lt;br /&gt;
	_GUICtrlEdit_SetCueBanner($iUsername, &amp;quot;Search folder&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	Local $iPassword = GUICtrlCreateInput(&#039;&#039;, 10, 40, 125, 25)&lt;br /&gt;
	_GUICtrlEdit_SetCueBanner($iPassword, &amp;quot;Search...&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	Local $iClose = GUICtrlCreateButton(&amp;quot;Close&amp;quot;, 210, 120, 85, 25)&lt;br /&gt;
	ControlFocus($hGUI, &amp;quot;&amp;quot;, $iClose)&lt;br /&gt;
&lt;br /&gt;
	GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, _GUICtrlEdit_GetCueBanner($iPassword))&lt;br /&gt;
&lt;br /&gt;
	While 1&lt;br /&gt;
		Switch GUIGetMsg()&lt;br /&gt;
			Case $GUI_EVENT_CLOSE, $iClose&lt;br /&gt;
				ExitLoop&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;
&lt;br /&gt;
Func _GUICtrlEdit_GetCueBanner($hWnd)&lt;br /&gt;
	If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)&lt;br /&gt;
&lt;br /&gt;
	Local $tText = DllStructCreate(&amp;quot;wchar[4096]&amp;quot;)&lt;br /&gt;
	If _SendMessage($hWnd, $EM_GETCUEBANNER, $tText, 4096, 0, &amp;quot;struct*&amp;quot;) &amp;lt;&amp;gt; 1 Then Return SetError(-1, 0, &amp;quot;&amp;quot;)&lt;br /&gt;
	Return _WinAPI_WideCharToMultiByte($tText)&lt;br /&gt;
EndFunc   ;==&amp;gt;_GUICtrlEdit_GetCueBanner&lt;br /&gt;
&lt;br /&gt;
Func _GUICtrlEdit_SetCueBanner($hWnd, $sText)&lt;br /&gt;
	If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)&lt;br /&gt;
&lt;br /&gt;
	Local $tText = _WinAPI_MultiByteToWideChar($sText)&lt;br /&gt;
&lt;br /&gt;
	Return _SendMessage($hWnd, $EM_SETCUEBANNER, False, $tText, 0, &amp;quot;wparam&amp;quot;, &amp;quot;struct*&amp;quot;) = 1&lt;br /&gt;
EndFunc   ;==&amp;gt;_GUICtrlEdit_SetCueBanner&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Snapped Window ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 126-lazycat&lt;br /&gt;
 | AuthorName = Lazycat&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;GUIConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global Const $WM_WINDOWPOSCHANGING = 0x0046&lt;br /&gt;
Global Const $SPI_GETWORKAREA = 0x30&lt;br /&gt;
Global $nGap = 20, $nEdge = BitOR(1, 2, 4, 8); Left, Top, Right, Bottom&lt;br /&gt;
&lt;br /&gt;
$hGUI = GUICreate(&amp;quot;Snapped Window&amp;quot;, 300, 200)&lt;br /&gt;
GUIRegisterMsg($WM_WINDOWPOSCHANGING, &amp;quot;MY_WM_WINDOWPOSCHANGING&amp;quot;)&lt;br /&gt;
GUISetState()&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
    $GUIMsg = GUIGetMsg()&lt;br /&gt;
&lt;br /&gt;
    Switch $GUIMsg&lt;br /&gt;
        Case $GUI_EVENT_CLOSE&lt;br /&gt;
            ExitLoop&lt;br /&gt;
    EndSwitch&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func MY_WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)&lt;br /&gt;
#cs&lt;br /&gt;
    HWND hwnd;&lt;br /&gt;
    HWND hwndInsertAfter;&lt;br /&gt;
    int x;&lt;br /&gt;
    int y;&lt;br /&gt;
    int cx;&lt;br /&gt;
    int cy;&lt;br /&gt;
    UINT flags;&lt;br /&gt;
#ce&lt;br /&gt;
    Local $stRect = DllStructCreate(&amp;quot;int;int;int;int&amp;quot;)&lt;br /&gt;
    Local $stWinPos = DllStructCreate(&amp;quot;uint;uint;int;int;int;int;uint&amp;quot;, $lParam)&lt;br /&gt;
    DllCall(&amp;quot;User32.dll&amp;quot;, &amp;quot;int&amp;quot;, &amp;quot;SystemParametersInfo&amp;quot;, &amp;quot;int&amp;quot;, $SPI_GETWORKAREA, &amp;quot;int&amp;quot;, 0, &amp;quot;ptr&amp;quot;, DllStructGetPtr($stRect), &amp;quot;int&amp;quot;, 0)&lt;br /&gt;
    Local $nLeft   = DllStructGetData($stRect, 1)&lt;br /&gt;
    Local $nTop = DllStructGetData($stRect, 2)&lt;br /&gt;
    Local $nRight  = DllStructGetData($stRect, 3) - DllStructGetData($stWinPos, 5)&lt;br /&gt;
    Local $nBottom = DllStructGetData($stRect, 4) - DllStructGetData($stWinPos, 6)&lt;br /&gt;
    If BitAND($nEdge, 1) and Abs($nLeft   - DllStructGetData($stWinPos, 3)) &amp;lt;= $nGap Then DllStructSetData($stWinPos, 3, $nLeft)&lt;br /&gt;
    If BitAND($nEdge, 2) and Abs($nTop  - DllStructGetData($stWinPos, 4)) &amp;lt;= $nGap Then DllStructSetData($stWinPos, 4, $nTop)&lt;br /&gt;
    If BitAND($nEdge, 4) and Abs($nRight  - DllStructGetData($stWinPos, 3)) &amp;lt;= $nGap Then DllStructSetData($stWinPos, 3, $nRight)&lt;br /&gt;
    If BitAND($nEdge, 8) and Abs($nBottom - DllStructGetData($stWinPos, 4)) &amp;lt;= $nGap Then DllStructSetData($stWinPos, 4, $nBottom)&lt;br /&gt;
    Return 0&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== GUI Snap To Corners ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 126-lazycat&lt;br /&gt;
 | AuthorName = Lazycat&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; GUI snap to corners&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;GUIConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global Const $WM_WINDOWPOSCHANGING = 0x0046&lt;br /&gt;
Global $nGap = 20&lt;br /&gt;
Global $ahGUI[3]&lt;br /&gt;
$ahGUI[0] = GUICreate(&amp;quot;Snapped window 1&amp;quot;, 300, 200, 100, 100)&lt;br /&gt;
GUISetState()&lt;br /&gt;
$ahGUI[1] = GUICreate(&amp;quot;Snapped window 2&amp;quot;, 300, 400, 300, 400)&lt;br /&gt;
GUISetState()&lt;br /&gt;
$ahGUI[2] = GUICreate(&amp;quot;Snapped window 3&amp;quot;, 150, 300, 500, 100)&lt;br /&gt;
GUISetState()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GUIRegisterMsg($WM_WINDOWPOSCHANGING, &amp;quot;MY_WM_WINDOWPOSCHANGING&amp;quot;)&lt;br /&gt;
While 1&lt;br /&gt;
    $GUIMsg = GUIGetMsg()&lt;br /&gt;
    Switch $GUIMsg&lt;br /&gt;
        Case $GUI_EVENT_CLOSE&lt;br /&gt;
            ExitLoop&lt;br /&gt;
    EndSwitch&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func MY_WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)&lt;br /&gt;
    Local $stWinPos = DllStructCreate(&amp;quot;uint;uint;int;int;int;int;uint&amp;quot;, $lParam)&lt;br /&gt;
    Local $nLeft   = DllStructGetData($stWinPos, 3)&lt;br /&gt;
    Local $nTop    = DllStructGetData($stWinPos, 4)&lt;br /&gt;
    $pos_cur = WinGetPos($hWnd)&lt;br /&gt;
    For $i = 0 To UBound($ahGUI) - 1&lt;br /&gt;
        If $hWnd = $ahGUI[$i] Then ContinueLoop&lt;br /&gt;
        $pos_win = WinGetPos($ahGUI[$i])&lt;br /&gt;
&lt;br /&gt;
        If Abs(($pos_win[0] + $pos_win[2]) - $nLeft) &amp;lt;= $nGap Then DllStructSetData($stWinPos, 3, $pos_win[0] + $pos_win[2])&lt;br /&gt;
        If Abs($nLeft + $pos_cur[2] - $pos_win[0]) &amp;lt;= $nGap Then DllStructSetData($stWinPos, 3, $pos_win[0] - $pos_cur[2])&lt;br /&gt;
&lt;br /&gt;
        If Abs(($pos_win[1] + $pos_win[3]) - $nTop) &amp;lt;= $nGap Then DllStructSetData($stWinPos, 4, $pos_win[1] + $pos_win[3])&lt;br /&gt;
        If Abs($nTop + $pos_cur[3] - $pos_win[1]) &amp;lt;= $nGap Then DllStructSetData($stWinPos, 4, $pos_win[1] - $pos_cur[3])&lt;br /&gt;
    Next&lt;br /&gt;
    Return 0&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== TAB On TAB Resize ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 52-geosoft&lt;br /&gt;
 | AuthorName = GEOSoft&lt;br /&gt;
 | AuthorURL2 = 3602-martin&lt;br /&gt;
 | AuthorName2 = martin&lt;br /&gt;
 | AuthorURL3 = 5169-refran&lt;br /&gt;
 | AuthorName3 = ReFran&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Example of TAB On TAB Resize&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;GUIConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global $mainGUI, $ok_button, $cancel_button&lt;br /&gt;
&lt;br /&gt;
; This window has 2 ok/cancel-buttons&lt;br /&gt;
$mainGUI = GUICreate(&amp;quot;Tab on Tab Resize&amp;quot;, 260, 250, 20, 10, $WS_OVERLAPPEDWINDOW + $WS_CLIPCHILDREN + $WS_CLIPSIBLINGS)&lt;br /&gt;
GUISetStyle(BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_SIZEBOX, $WS_POPUP, $WS_SYSMENU))&lt;br /&gt;
GUISetBkColor(0x5686A9)&lt;br /&gt;
$ok_button = GUICtrlCreateButton(&amp;quot;OK&amp;quot;, 40, 220, 70, 20)&lt;br /&gt;
$cancel_button = GUICtrlCreateButton(&amp;quot;Cancel&amp;quot;, 150, 220, 70, 20)&lt;br /&gt;
&lt;br /&gt;
; Create the first child window that is implemented into the main GUI&lt;br /&gt;
$child1 = GUICreate(&amp;quot;&amp;quot;, 230, 170, 15, 35, BitOR($WS_CHILD, $WS_TABSTOP), -1, $mainGUI)&lt;br /&gt;
&lt;br /&gt;
GUISetBkColor(0x46860A)&lt;br /&gt;
$child_tab = GUICtrlCreateTab(10, 10, 210, 150)&lt;br /&gt;
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)&lt;br /&gt;
$child11tab = GUICtrlCreateTabItem(&amp;quot;1&amp;quot;)&lt;br /&gt;
$child12tab = GUICtrlCreateTabItem(&amp;quot;2&amp;quot;)&lt;br /&gt;
GUICtrlCreateTabItem(&amp;quot;&amp;quot;)&lt;br /&gt;
GUISetState()&lt;br /&gt;
&lt;br /&gt;
; Create the second child window that is implemented into the main GUI&lt;br /&gt;
$child2 = GUICreate(&amp;quot;&amp;quot;, 230, 170, 15, 35, BitOR($WS_CHILD, $WS_TABSTOP), -1, $mainGUI)&lt;br /&gt;
GUISetBkColor(0x56869c)&lt;br /&gt;
$listview2 = GUICtrlCreateListView(&amp;quot;Col1|Col2&amp;quot;, 10, 10, 210, 150, -1, $WS_EX_CLIENTEDGE)&lt;br /&gt;
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)&lt;br /&gt;
GUICtrlCreateListViewItem(&amp;quot;ItemLong1|ItemLong12&amp;quot;, $listview2)&lt;br /&gt;
GUICtrlCreateListViewItem(&amp;quot;ItemLong2|Item22&amp;quot;, $listview2)&lt;br /&gt;
;GUISetState()&lt;br /&gt;
&lt;br /&gt;
; Switch back the main GUI and create the tabs&lt;br /&gt;
GUISwitch($mainGUI)&lt;br /&gt;
$main_tab = GUICtrlCreateTab(10, 10, 240, 200)&lt;br /&gt;
$child1tab = GUICtrlCreateTabItem(&amp;quot;Child1&amp;quot;)&lt;br /&gt;
$child2tab = GUICtrlCreateTabItem(&amp;quot;Child2&amp;quot;)&lt;br /&gt;
GUICtrlCreateTabItem(&amp;quot;&amp;quot;)&lt;br /&gt;
GUISetState()&lt;br /&gt;
&lt;br /&gt;
GUIRegisterMsg($WM_SIZE, &#039;WM_SIZE&#039;)&lt;br /&gt;
Dim $tabItemLast = 0&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
    $msg = GUIGetMsg(1)&lt;br /&gt;
    Switch $msg[0]&lt;br /&gt;
        Case $GUI_EVENT_CLOSE, $cancel_button&lt;br /&gt;
            ExitLoop&lt;br /&gt;
&lt;br /&gt;
        Case $main_tab&lt;br /&gt;
            $tabItem = GUICtrlRead($main_tab)&lt;br /&gt;
            If $tabItem &amp;lt;&amp;gt; $tabItemLast Then TabSwitch($tabItem)&lt;br /&gt;
&lt;br /&gt;
    EndSwitch&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func TabSwitch($tabItem)&lt;br /&gt;
    GUISetState(@SW_HIDE, $child1)&lt;br /&gt;
    GUISetState(@SW_HIDE, $child2)&lt;br /&gt;
&lt;br /&gt;
    If $tabItem = 0 Then GUISetState(@SW_SHOW, $child1)&lt;br /&gt;
    If $tabItem = 1 Then GUISetState(@SW_SHOW, $child2)&lt;br /&gt;
    $tabItemLast = $tabItem&lt;br /&gt;
EndFunc   ;==&amp;gt;TabSwitch&lt;br /&gt;
&lt;br /&gt;
Func WM_SIZE($hWnd, $iMsg, $iWParam, $iLParam)&lt;br /&gt;
    $aMGPos = WinGetClientSize($mainGUI)&lt;br /&gt;
    WinMove($child1, &amp;quot;&amp;quot;, 15, 35, +$aMGPos[0] - 30, +$aMGPos[1] - 80)&lt;br /&gt;
    WinMove($child2, &amp;quot;&amp;quot;, 15, 35, +$aMGPos[0] - 30, +$aMGPos[1] - 80)&lt;br /&gt;
    ;Guictrlsetpos($child_tab,10,10,+$aMGPos[0]-50,+$aMGPos[1]-100)&lt;br /&gt;
    GUICtrlSetPos($main_tab, 10, 10, +$aMGPos[0] - 20, +$aMGPos[1] - 50)&lt;br /&gt;
    GUICtrlSetPos($listview2, 10, 10, +$aMGPos[0] - 30 - 20, +$aMGPos[1] - 80 - 20)&lt;br /&gt;
&lt;br /&gt;
EndFunc   ;==&amp;gt;WM_SIZE&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _Toggle_CheckOrUnCheck ==&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;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;
    Local $iCheckBox = GUICtrlCreateCheckbox(&#039;Example&#039;, 5, 10, 85, 25)&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    ; The control is currently unchecked so this will toggle the state to checked.&lt;br /&gt;
    _Toggle_CheckOrUnCheck($iCheckBox)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    ; The control was changed to checked the last time _Toggle_CheckOrUnCheck was called, so now toggle the state to unchecked.&lt;br /&gt;
    _Toggle_CheckOrUnCheck($iCheckBox)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Toggle a control to either unchecked or checked, depending on it&#039;s current state.&lt;br /&gt;
Func _Toggle_CheckOrUnCheck($iControlID)&lt;br /&gt;
    Local $aState[2] = [$GUI_CHECKED, $GUI_UNCHECKED]&lt;br /&gt;
    GUICtrlSetState($iControlID, $aState[Number(BitAND(GUICtrlRead($iControlID), $aState[0]) = $aState[0])])&lt;br /&gt;
EndFunc   ;==&amp;gt;_Toggle_CheckOrUnCheck&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _Toggle_DropOrNoDrop ==&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;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WindowsConstants.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;, 500, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)&lt;br /&gt;
    Local $iLabel = GUICtrlCreateLabel(&#039;Example&#039;, 5, 10, 85, 25)&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    ; The control is currently accepting no files to be dropped on it so this will toggle the state to allow dropped files.&lt;br /&gt;
    _Toggle_DropOrNoDrop($iLabel)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    ; The control was changed to allow dropped files the last time _Toggle_DropOrNoDrop was called, so now toggle the state to accept no dropping of files.&lt;br /&gt;
    _Toggle_DropOrNoDrop($iLabel)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Toggle a control to either accept or not accept dropped files, depending on it&#039;s current state.&lt;br /&gt;
Func _Toggle_DropOrNoDrop($iControlID)&lt;br /&gt;
    Local $aState[2] = [$GUI_DROPACCEPTED, $GUI_NODROPACCEPTED]&lt;br /&gt;
    GUICtrlSetState($iControlID, $aState[Number(BitAND(GUICtrlGetState($iControlID), $aState[0]) = $aState[0])])&lt;br /&gt;
EndFunc   ;==&amp;gt;_Toggle_DropOrNoDrop&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _Toggle_EnableOrDisable ==&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;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;
    Local $iButton = GUICtrlCreateButton(&#039;Example&#039;, 5, 10, 85, 25)&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    ; The control is currently enabled so this will toggle the state to disabled.&lt;br /&gt;
    _Toggle_EnableOrDisable($iButton)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    ; The control was changed to disabled the last time _Toggle_EnableOrDisable was called, so now toggle the state to enabled.&lt;br /&gt;
    _Toggle_EnableOrDisable($iButton)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Toggle a control to either enabled or disabled, depending on it&#039;s current state.&lt;br /&gt;
Func _Toggle_EnableOrDisable($iControlID)&lt;br /&gt;
    Local $aState[2] = [$GUI_ENABLE, $GUI_DISABLE]&lt;br /&gt;
    GUICtrlSetState($iControlID, $aState[Number(BitAND(GUICtrlGetState($iControlID), $aState[0]) = $aState[0])])&lt;br /&gt;
EndFunc   ;==&amp;gt;_Toggle_EnableOrDisable&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _Toggle_FocusOrNoFocus ==&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;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;
    Local $iButton = GUICtrlCreateButton(&#039;Example&#039;, 5, 10, 85, 25)&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    ; The control is currently not focused so this will toggle the state to focused.&lt;br /&gt;
    _Toggle_FocusOrNoFocus($iButton)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    ; The control was changed to focused the last time _Toggle_FocusOrNoFocus was called, so now toggle the state to not focused.&lt;br /&gt;
    _Toggle_FocusOrNoFocus($iButton)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Toggle a control to either focused or not focused, depending on it&#039;s current state.&lt;br /&gt;
Func _Toggle_FocusOrNoFocus($iControlID)&lt;br /&gt;
    Local $aState[2] = [$GUI_FOCUS, $GUI_NOFOCUS]&lt;br /&gt;
    GUICtrlSetState($iControlID, $aState[Number(BitAND(GUICtrlGetState($iControlID), $aState[0]) = $aState[0])])&lt;br /&gt;
EndFunc   ;==&amp;gt;_Toggle_FocusOrNoFocus&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _Toggle_ShowOrHide ==&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;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;
    Local $iButton = GUICtrlCreateButton(&#039;Example&#039;, 5, 10, 85, 25)&lt;br /&gt;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    ; The control is currently shown so this will toggle the state to hide.&lt;br /&gt;
    _Toggle_ShowOrHide($iButton)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    ; The control was changed to hide the last time _Toggle_ShowOrHide was called, so now toggle the state to show.&lt;br /&gt;
    _Toggle_ShowOrHide($iButton)&lt;br /&gt;
&lt;br /&gt;
    ; Sleep for 2 seconds.&lt;br /&gt;
    Sleep(2000)&lt;br /&gt;
&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Toggle a control to either show or hide, depending on it&#039;s current state.&lt;br /&gt;
Func _Toggle_ShowOrHide($iControlID)&lt;br /&gt;
    Local $aState[2] = [$GUI_SHOW, $GUI_HIDE]&lt;br /&gt;
    GUICtrlSetState($iControlID, $aState[Number(BitAND(GUICtrlGetState($iControlID), $aState[0]) = $aState[0])])&lt;br /&gt;
EndFunc   ;==&amp;gt;_Toggle_ShowOrHide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Unmovable Window ==&lt;br /&gt;
&lt;br /&gt;
{{Snippet Header&lt;br /&gt;
 | AuthorURL = 19384-wemartiansarefriendly&lt;br /&gt;
 | AuthorName = WeMartiansAreFriendly&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;GUIConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global Const $WM_WINDOWPOSCHANGING = 0x0046&lt;br /&gt;
&lt;br /&gt;
Global $nConstXpos = @DesktopWidth/2        ;define the constant x position&lt;br /&gt;
Global $nConstYpos = @DesktopHeight/2   ;define the constant y position&lt;br /&gt;
&lt;br /&gt;
$hGUI = GUICreate(&amp;quot;Unmovable Window&amp;quot;, 300, 200, $nConstXpos, $nConstYpos)&lt;br /&gt;
&lt;br /&gt;
GUIRegisterMsg($WM_WINDOWPOSCHANGING, &amp;quot;MY_WM_WINDOWPOSCHANGING&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
GUISetState()&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
    $GUIMsg = GUIGetMsg()&lt;br /&gt;
&lt;br /&gt;
    Switch $GUIMsg&lt;br /&gt;
        Case $GUI_EVENT_CLOSE&lt;br /&gt;
            ExitLoop&lt;br /&gt;
    EndSwitch&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func MY_WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)&lt;br /&gt;
    Local $stWinPos = DllStructCreate(&amp;quot;uint hwnd;uint hwndInsertAfter;int x;int y;int cx;int cy;uint flags&amp;quot;, $lParam)&lt;br /&gt;
&lt;br /&gt;
    DllStructSetData($stWinPos, &amp;quot;x&amp;quot;, $nConstXpos)&lt;br /&gt;
    DllStructSetData($stWinPos, &amp;quot;y&amp;quot;, $nConstYpos)&lt;br /&gt;
    Return 0&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== Window Drag Using GUIRegister ==&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;
; Window Drag using GUIRegister&lt;br /&gt;
#include &amp;lt;GuiConstants.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global Const $WM_LBUTTONDOWN = 0x0201&lt;br /&gt;
;Global Const $WM_SYSCOMMAND = 0x0112&lt;br /&gt;
&lt;br /&gt;
$Gui = GuiCreate(&amp;quot;Test&amp;quot;, 200, 100, -1, -1, $WS_POPUP, $WS_EX_DLGMODALFRAME)&lt;br /&gt;
GuiRegisterMsg($WM_LBUTTONDOWN, &amp;quot;_WinMove&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
GUISetState()&lt;br /&gt;
&lt;br /&gt;
While 1&lt;br /&gt;
    $Msg = GUIGetMsg()&lt;br /&gt;
    Switch $Msg&lt;br /&gt;
        Case -3&lt;br /&gt;
            Exit&lt;br /&gt;
    EndSwitch&lt;br /&gt;
WEnd&lt;br /&gt;
&lt;br /&gt;
Func _WinMove($HWnd, $Command, $wParam, $lParam)&lt;br /&gt;
    If BitAND(WinGetState($HWnd), 32) Then Return $GUI_RUNDEFMSG&lt;br /&gt;
    DllCall(&amp;quot;user32.dll&amp;quot;, &amp;quot;long&amp;quot;, &amp;quot;SendMessage&amp;quot;, &amp;quot;hwnd&amp;quot;, $HWnd, &amp;quot;int&amp;quot;, $WM_SYSCOMMAND, &amp;quot;int&amp;quot;, 0xF009, &amp;quot;int&amp;quot;, 0)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== WinGetTrans ==&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;WinAPI.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;
    GUISetState(@SW_SHOW, $hGUI)&lt;br /&gt;
&lt;br /&gt;
    ; Set the transparency of a GUI between 0 and 255. 255 = Solid, 0 = Invisible.&lt;br /&gt;
    WinSetTrans($hGUI, &#039;&#039;, 100)&lt;br /&gt;
&lt;br /&gt;
    MsgBox(4096, &#039;&#039;, &#039;The transparency of the GUI is: &#039; &amp;amp; WinGetTrans($hGUI) &amp;amp; &#039;, this should be 100.&#039;)&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
; Find the transparency of a GUI.&lt;br /&gt;
Func WinGetTrans($sTitle, $sText = &#039;&#039;) ; By Valik - http://www.autoitscript.com/forum/topic/...gettrans/page__view__findpost_&lt;br /&gt;
    Local $iTransColor = 0, $iTransparency = 255&lt;br /&gt;
    _WinAPI_GetLayeredWindowAttributes(WinGetHandle($sTitle, $sText), $iTransColor, $iTransparency)&lt;br /&gt;
    Return $iTransparency&lt;br /&gt;
EndFunc   ;==&amp;gt;WinGetTrans&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;br /&gt;
&lt;br /&gt;
== _WorkingArea ==&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;APIConstants.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;GUIConstantsEx.au3&amp;gt;&lt;br /&gt;
#include &amp;lt;WinAPI.au3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example()&lt;br /&gt;
&lt;br /&gt;
Func Example()&lt;br /&gt;
    ; Set the working area of the Desktop, in this case 120px to the left and retaining the same height and width.&lt;br /&gt;
    Local $aWorkingArea = _WorkingArea(150, Default, Default, Default)&lt;br /&gt;
&lt;br /&gt;
    ; Create the GUI.&lt;br /&gt;
    Local $hGUI = GUICreate(&#039;&#039;, 150, $aWorkingArea[1], $aWorkingArea[2], $aWorkingArea[3], $WS_POPUP)&lt;br /&gt;
    Local $iClose = GUICtrlCreateButton(&#039;Close&#039;, 5, 5, 150 - 10, 25)&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, $iClose&lt;br /&gt;
                ExitLoop&lt;br /&gt;
&lt;br /&gt;
        EndSwitch&lt;br /&gt;
    WEnd&lt;br /&gt;
&lt;br /&gt;
    ; Delete the GUI.&lt;br /&gt;
    GUIDelete($hGUI)&lt;br /&gt;
&lt;br /&gt;
    ; Reset the working area to the previous values.&lt;br /&gt;
    _WorkingArea()&lt;br /&gt;
EndFunc   ;==&amp;gt;Example&lt;br /&gt;
&lt;br /&gt;
Func _WorkingArea($iLeft = Default, $iTop = Default, $iWidth = Default, $iHeight = Default)&lt;br /&gt;
    Local Static $tWorkArea = 0&lt;br /&gt;
    If IsDllStruct($tWorkArea) Then&lt;br /&gt;
        _WinAPI_SystemParametersInfo($SPI_SETWORKAREA, 0, DllStructGetPtr($tWorkArea), $SPIF_SENDCHANGE)&lt;br /&gt;
        $tWorkArea = 0&lt;br /&gt;
    Else&lt;br /&gt;
        $tWorkArea = DllStructCreate($tagRECT)&lt;br /&gt;
        _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($tWorkArea))&lt;br /&gt;
&lt;br /&gt;
        Local $tCurrentArea = DllStructCreate($tagRECT)&lt;br /&gt;
        Local $aArray[4] = [$iLeft, $iTop, $iWidth, $iHeight]&lt;br /&gt;
        For $i = 0 To 3&lt;br /&gt;
            If $aArray[$i] = Default Or $aArray[$i] &amp;lt; 0 Then&lt;br /&gt;
                $aArray[$i] = DllStructGetData($tWorkArea, $i + 1)&lt;br /&gt;
            EndIf&lt;br /&gt;
            DllStructSetData($tCurrentArea, $i + 1, $aArray[$i])&lt;br /&gt;
            $aArray[$i] = DllStructGetData($tWorkArea, $i + 1)&lt;br /&gt;
        Next&lt;br /&gt;
        _WinAPI_SystemParametersInfo($SPI_SETWORKAREA, 0, DllStructGetPtr($tCurrentArea), $SPIF_SENDCHANGE)&lt;br /&gt;
        $aArray[2] -= $aArray[0]&lt;br /&gt;
        $aArray[3] -= $aArray[1]&lt;br /&gt;
        Local $aReturn[4] = [$aArray[2], $aArray[3], $aArray[0], $aArray[1]]&lt;br /&gt;
        Return $aReturn&lt;br /&gt;
    EndIf&lt;br /&gt;
EndFunc   ;==&amp;gt;_WorkingArea&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#top | ReturnToContents]]&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Helpfile-Changes&amp;diff=12293</id>
		<title>Helpfile-Changes</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=Helpfile-Changes&amp;diff=12293"/>
		<updated>2014-01-20T16:51:21Z</updated>

		<summary type="html">&lt;p&gt;Guinness: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is for keeping track of changes currently in the process of being made to the AutoIt3 helpfile and UDFs by the MVPs.&lt;br /&gt;
&lt;br /&gt;
For reporting issues please refer to the [http://www.autoitscript.com/forum/topic/146560-report-help-file-issues-here/ Help File Issues] thread. Thanks.&lt;br /&gt;
&lt;br /&gt;
== Doc changes ==&lt;br /&gt;
* Magic number removal (Mat)&lt;br /&gt;
** Document existing constants (in progress)&lt;br /&gt;
** Create new constants where required (making a list)&lt;br /&gt;
&lt;br /&gt;
* [http://www.autoitscript.com/forum/topic/146560-report-help-file-issues-here/page__st__120#entry1048490 AZJIO post #135]&lt;br /&gt;
** RegRead type table (Mat), in progress [http://msdn.microsoft.com/en-us/library/windows/desktop/bb773476(v=vs.85).aspx - from guinness]&lt;br /&gt;
&lt;br /&gt;
* General Example improvements&lt;br /&gt;
** Make sure no permanent changes are made to system.&lt;br /&gt;
** Update examples to make use of new AutoIt features where appropriate.&lt;br /&gt;
** Re-write GUI examples&lt;br /&gt;
** Sort include statements in examples and remove duplicates. If duplicates are found then take advantage of multiple examples. (guinness)&lt;br /&gt;
** Remove unused functions.&lt;br /&gt;
&lt;br /&gt;
== UDF changes ==&lt;br /&gt;
&lt;br /&gt;
* Fixed buffer sizes (as per [http://www.autoitscript.com/forum/topic/147486-ticket-1336/ thread] and ticket 1336)&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=11833</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=11833"/>
		<updated>2013-08-15T18:22:38Z</updated>

		<summary type="html">&lt;p&gt;Guinness: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Outlined in this section is a detailed explanation of what is to be considered the best coding practices within AutoIt.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Variable Naming ==&lt;br /&gt;
The Hungarian notation is adopted however it&#039;s simplified and regroup all the types of numbers in one type.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! prefix !! covering type !! initialization&lt;br /&gt;
|-&lt;br /&gt;
| i || Numbers (any type) || $i = 0&lt;br /&gt;
|-&lt;br /&gt;
| a || Arrays || $a = 0 or $a[0]&lt;br /&gt;
|-&lt;br /&gt;
| s || Strings (chars included) || $s = &amp;quot;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| f || Booleans || $f = False or $f = True &lt;br /&gt;
|-&lt;br /&gt;
| b || Binaries || $b = &amp;quot;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| h || Handles (and GUI handles) || $h = 0&lt;br /&gt;
|-&lt;br /&gt;
| k (not decided) || Keywords || Null (not decided)&lt;br /&gt;
|-&lt;br /&gt;
| fu (not decided) || Functions || Null (not decided)&lt;br /&gt;
|-&lt;br /&gt;
| p || Pointers || $p = 0&lt;br /&gt;
|-&lt;br /&gt;
| tag || Structures definition || $tag = &amp;quot;&amp;quot; (should directly be filled)&lt;br /&gt;
|-&lt;br /&gt;
| t || Structures || $t = 0&lt;br /&gt;
|-&lt;br /&gt;
| o || Objects || $o = 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The variables are named following this schema :&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! type (lower case) !! [optional] subtype (lower case) !! var name (first letter in upper case)&lt;br /&gt;
|-&lt;br /&gt;
| i || f || MyFlag&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example :&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
; Assign a Local variable the number 5.&lt;br /&gt;
Local $iSomeVar = 5&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable the number 1.&lt;br /&gt;
Local $ifMyFlag = 1&lt;br /&gt;
&lt;br /&gt;
; Assign a Local variable an array of numbers.&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
; Re-declare the array to size and fill it.&lt;br /&gt;
Local $aiArray[3] = [0, 0.25, 3 / 4]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Always initialize a variable on it&#039;s declaration, and declare all the same type of variable on the same line.&lt;br /&gt;
&lt;br /&gt;
Example :&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;autoit&amp;quot;&amp;gt;&lt;br /&gt;
;good&lt;br /&gt;
Local $iSomeVar1 = 0, $iSomeVar2 = 5&lt;br /&gt;
Local $aiArray = 0&lt;br /&gt;
&lt;br /&gt;
;bad&lt;br /&gt;
Local $iSomeVar1, $aiArray = 0&lt;br /&gt;
Local $iSomeVar2 = 5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can still categorize your variables and declare for example the $iSomeVar2 on another line.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Scopes of variables ==&lt;br /&gt;
To make the transition, the variables are also 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;
| $__iSomeVar || $_iSomeVar || $iSomeVar&lt;br /&gt;
|}&lt;br /&gt;
Remark: With this method, you will avoid non wanted re-assignments.&lt;br /&gt;
&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;Constants.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 $_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 $_iSomeVar2.&lt;br /&gt;
	MsgBox($MB_SYSTEMMODAL, &amp;quot;&amp;quot;, &amp;quot;Value of $_iSomeVar2: &amp;quot; &amp;amp; $_iSomeVar2)&lt;br /&gt;
EndFunc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More coming soon :)&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=11812</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=11812"/>
		<updated>2013-08-15T12:32:47Z</updated>

		<summary type="html">&lt;p&gt;Guinness: &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.&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=11811</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=11811"/>
		<updated>2013-08-15T12:30:13Z</updated>

		<summary type="html">&lt;p&gt;Guinness: Created page with &amp;quot;Best coding practices.&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Best coding practices.&lt;/div&gt;</summary>
		<author><name>Guinness</name></author>
	</entry>
</feed>