Keyword Reference
#include
Includes a file in the current script.
Parameters
| filename |
The filename of the current script to include. Path is optional. This must be a string--it cannot be a variable.
If "..." is used, the filename is taken to be relative to the current script.
If <...> is used the filename is taken to be relative to include library directory (usually C:\Program Files\AutoIt3\Include). The include library contains many pre-written user-functions for you to use! |
Remarks
In an AutoIt script, other scripts can be included using the #include" command.
For the include library syntax (#include <file>) to work AutoIt must have been installed using the supplied installer otherwise the installation directory will not be known and the current script directory (@ScriptDir\Include) will be used instead.
If you include the same file containing a user-function more than once you will get a "Duplicate function" error. When writing an include file that may be used in this way, make sure that the top line contains #include-once to prevent that file from being included more than once.
There is a special registry value that can be created at "HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt" called "Include". It should be a REG_SZ (string) value. The contents of this value are a semi-colon delimited list of directories that should be searched for files when resolving #include's in addition to the standard locations.
The search order used by AutoIt depends on which form of #include you use. The tables below show the order directories are searched using both forms.
Using #include <>
| Standard library |
The path of the currently running interpreter with "\Include" appended is searched. |
| User-defined libraries |
The registry value mentioned above is read and each directory is searched in the order they appear in. |
| Script directory |
The directory of the currently executing script. |
Using #include "" (This is the reverse of #include <>).
| Script directory |
The directory of the currently executing script. |
| User-defined libraries |
The registry value mentioned above is read and each directory is searched in the reverse order they appear in. |
| Standard library |
The path of the currently running interpreter with "\Include" appended is searched. |
A note about using the /AutoIt3ExecuteScript option. Since the standard library is searched for in the current interpreter's directory, the standard library functions will not be found; that library will only be found when run through AutoIt3.exe. It's recommended that you compile a script to the .a3x format before attempting to run it with /AutoIt3ExecuteScript.
Aut2Exe uses the same algorithm as AutoIt3.exe with the only difference being it looks for the Include sub-directory as being in a sibling directory to itself (..\Include).
If Opt("TrayIconDebug",1) only 64 include files name can be displayed in the traytooltip. for the other no filename will be displayed.
Related
#include-once, FileInstall
Example
;;; TIME.AU3 ;;;
MsgBox(0,"", "The time is " & @HOUR & ":" & @MIN & ":" & @SEC)
;;; SCRIPT.AU3 ;;;
#include "TIME.AU3"
MsgBox(0,"", "Example")
#include "TIME.AU3"
Exit
; Running script.au3 will output three message boxes:
; one with the time, one with 'Example', and another with the time.