<?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=Jpm</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=Jpm"/>
	<link rel="alternate" type="text/html" href="https://www.autoitscript.com/wiki/Special:Contributions/Jpm"/>
	<updated>2026-05-14T23:41:55Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=UDF-spec&amp;diff=12600</id>
		<title>UDF-spec</title>
		<link rel="alternate" type="text/html" href="https://www.autoitscript.com/w/index.php?title=UDF-spec&amp;diff=12600"/>
		<updated>2014-08-05T06:37:32Z</updated>

		<summary type="html">&lt;p&gt;Jpm: /* 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. 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;$m&amp;lt;/code&amp;gt; - Map collection.&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>Jpm</name></author>
	</entry>
	<entry>
		<id>https://www.autoitscript.com/w/index.php?title=Best_coding_practices&amp;diff=12593</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=12593"/>
		<updated>2014-07-29T12:13:41Z</updated>

		<summary type="html">&lt;p&gt;Jpm: /* 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 || 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>Jpm</name></author>
	</entry>
</feed>