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: 1 for Global variable or variable declared outside functions.
Special: -1 for Local variable.
Failure: 0 when no variable can be found.

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