Function Reference


IsDeclared

Check if a variable has been declared.

IsDeclared ( expression )

Parameters

expression string representing name of the variable to be checked.

Return Value

Success: $DECLARED_GLOBAL (1) for Global variable or variable declared outside functions.
Special: $DECLARED_LOCAL (-1) for Local variable.
Failure: $DECLARED_UNKNOWN (0) when no variable can be found.

Constants are defined in AutoItConstants.au3

Remarks

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

Related

Assign, Eval

Example

#include <MsgBoxConstants.au3>

; Check if the variable $vVar is declared. As the variable isn't will display the error message.
If Not IsDeclared("vVar") Then
    MsgBox($MB_SYSTEMMODAL, "", "The variable $vVar is not declared.")

    Local $vVar = 0 ; Initialize the variable $vVar with data.
    If IsDeclared("vVar") Then ; Check if the variable $vVar is declared.
        MsgBox($MB_SYSTEMMODAL, "", "The variable $vVar is declared.")
    Else
        MsgBox($MB_SYSTEMMODAL, "", "The variable $vVar is not declared.")
    EndIf
EndIf