Function Reference


Assigns a variable by name with the data.

Assign ( "varname", "data" [, flag = 0] )


varname The name of the variable you wish to assign. Cannot be an array element and must only contain letters, digits and underscore characters (as per normal variable naming conventions).
data The data you wish to assign to the variable.
flag [optional] controls the way that variables are assigned (add required options together):
    $ASSIGN_CREATE (0) = (default) Create variable if required
    $ASSIGN_FORCELOCAL (1) = Force creation in local scope
    $ASSIGN_FORCEGLOBAL (2) = Force creation in global scope
    $ASSIGN_EXISTFAIL (4) = Fail if variable does not already exist

Constants are defined in AutoItConstants.au3

Return Value

Success: 1.
Failure: 0 if unable to create/assign the variable.


If there is a need to use Assign() to create/write to a variable, then in most situations, Eval() should be used to read the variable and IsDeclared() should be used to check that the variable exists.


Eval, Execute, IsDeclared


#include <MsgBoxConstants.au3>

; Assign the variable string sString with data.
Assign("sString", "This is a string which is declared using the function Assign")

; Find the value of the variable string sString and assign to the variable $sEvalString.
Local $sEvalString = Eval("sString")

; Display the value of $sEvalString. This should be the same value as $sString.
MsgBox($MB_SYSTEMMODAL, "", $sEvalString)