• No results found

include-once

In document Auto It 3 (Page 92-99)

Specifies that the current file may only be included once.

#include-once

 

Parameters None.

 

Remarks

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.

 

Related

#include  

Example

;;; LIBRARY.AU3 ;;;

#include-once Func myFunc()

    MsgBox(0,"", "Hello from library.au3") EndFunc

;;; SCRIPT.AU3 ;;;

#include "Library.au3"

#include "Library.au3"  ;throws an error if #include-once was not used MsgBox(0, "Example", "This is from 'script.au3' file")

myFunc() Exit

; Running script.au3 will output the two message boxes:

; one saying "This is from 'script.au3' file"

; and another saying "Hello from library.au3"

 

Keyword Reference

#NoTrayIcon

Indicates that the AutoIt tray icon will not be shown when the script starts.

#NoTrayIcon

 

Parameters None.

 

Remarks

It is possible to use Opt("TrayIconHide", 1) to remove the AutoIt tray icon but it will still be visible for a second when the script starts. Placing the #NoTrayIcon directive at the top of your script will stop the icon from being shown at startup.

You may still turn the icon back on later in the script using Opt("TrayIconHide", 0)  

Related

TrayIconHide (Option)  

Example

#NoTrayIcon

MsgBox(4096,"Click OK","Show the tray icon for 5 seconds...") Opt("TrayIconHide", 0) ;un-hide the icon

Sleep(5000)  

Keyword Reference

#OnAutoItStartRegister

Registers a function to be called when AutoIt starts.

#OnAutoItStartRegister "function"

 

Parameters

 

Remarks

 

Related  

Example

#OnAutoItStartRegister "MyTestFunc"

#OnAutoItStartRegister "MyTestFunc2"

Sleep(1000)

Func MyTestFunc()

    MsgBox(64, "Start Results 2", 'Start Message from MyTestFunc()') EndFunc

Func MyTestFunc2()

    MsgBox(64, "Start Results 3", 'Start Message from MyTestFunc()') EndFunc

 

function The name of the user function to call.

Keyword Reference

#NoAutoIt3Execute

Specifies that the current compiled script cannot run with /AutoIt3ExecuteLine or /AutoIt3ExecuteScript switch.

#NoAutoIt3Execute

 

Parameters None.

 

Remarks

Launching a compiled script is terminated with exit code = -1 if /AutoIt3ExecuteLine or /AutoIt3ExecuteScript are used.

 

Related None.

 

Keyword Reference

#RequireAdmin

Specifies that the current script requires full administrator rights to run.

#RequireAdmin

 

Parameters None.

 

Remarks

This function was primarily aimed at allowing AutoIt scripts to work correctly with Windows Vista User Account Control (UAC) (However, will also work on Windows 2000 and Windows XP).

For more details see AutoIt on Windows Vista.

As this function launch a new process, some functions as Consolewrite() cannot be captured (Scite will not display anything).

 

Related IsAdmin  

Example

#RequireAdmin

MsgBox(4096,"Info","Now running with admin rights")

 

Keyword Reference Func...Return...EndFunc

Defines a user-defined function that takes zero or more arguments and optionally returns a result.

Func functioname ( [Const] [ByRef] $param1, ..., [Const] [ByRef] $paramN, $optionalpar1 = value, ...)

    ...

    [Return [value]]

EndFunc

 

Parameters

The parameters are set by you. You later call the function like any other built-in function.

 

Remarks

The Const keyword is optional and indicates that the value of the parameter will not change during the

execution of the function. A variable declared Const can only be passed to a function using a Const parameter.

The ByRef keyword indicates the parameter should be treated as a reference to the original object. The default behavior copies the parameter into a new variable however ByRef links the new variable to the original

parameter. ByRef is typically preferred when a function expects large amounts of data, such as a large array, where copying all the data would impose a significant performance penalty. Note that not only a named variable can be passed for a ByRef parameter; unnamed temporary variables, such as function return values, may be passed as ByRef parameters as well. A literal can not be passed to a ByRef parameter.

If using both keywords ByRef and Const with a function parameter, the order of the keywords is not important, so long as they are both in front of the variable they modify.

Entire arrays can be passed to functions (and returned from them) by simply using the array name without any brackets. Arrays should be passed to user-defined functions using the ByRef keyword to avoid the overhead of copying all the data in the array.

Optional parameters are defined by assigning a default value to them. The value may be a global variable, macro or literal value. Optional parameters always appear last in the function definition. All parameters added after the first optional parameter must also be optional. Inside the function, the number of parameters given when the function was called can be retrieved with the @NUMPARAMS macro (see example 2).

Use the Return keyword to exit the function. Unlike built-in functions, user-defined functions return 0 unless another return value is specified.

Note that function declarations cannot appear inside other function declarations.

 

Related

Dim/Global/Local, #include, Const  

Example

Opt('MustDeclareVars', 1)

Example1() Example2()

; example1

Func Example1()

; Sample script with three user-defined functions

; Notice the use of variables, ByRef, and Return

Local $foo = 2

Local $bar = 5

msgBox(0,"Today is " & today(), "$foo equals " & $foo) swap($foo, $bar)

msgBox(0,"After swapping $foo and $bar", "$foo now contains " & $foo) msgBox(0,"Finally", "The larger of 3 and 4 is " & max(3,4))

EndFunc   ;==>Example1

Func swap(ByRef $a, ByRef $b)  ;swap the contents of two variables     Local $t

    $t = $a     $a = $b     $b = $t EndFunc

Func today()  ;Return the current date in mm/dd/yyyy form     return (@MON & "/" & @MDAY & "/" & @YEAR)

EndFunc

Func max($x, $y)  ;Return the larger of two numbers     If $x > $y Then

        return $x     Else

        return $y     EndIf

EndFunc

;End of sample script 1

; example2

Func Example2()

; Sample scriptusing @NumParams macro

    Test_Numparams(1,2,3,4,5,6,7,8,9,10,11,12,13,14) EndFunc   ;==>Example2

Func Test_Numparams($v1 = 0, $v2 = 0, $v3 = 0, $v4 = 0, $v5 = 0, $v6 = 0, $v7 = 0, $v8 = 0,

$v9 = 0, _

    $v10 = 0, $v11 = 0, $v12 = 0, $v13 = 0, $v14 = 0, $v15 = 0, $v16 = 0, $v17 = 0, $v18 = 0, $v19 = 0)

    Local $val

    For $i = 1 To @NumParams

        $val &= Eval("v" & $i) & " "

    Next

    MsgBox(0, "@NumParams example", "@NumParams =" & @NumParams & @CRLF & @CRLF & $val) EndFunc

 

;End of sample script 2  

 

Keyword Reference

In document Auto It 3 (Page 92-99)

Related documents