Check if a variable has been declared.
IsDeclared ( expression )
expression | string representing name of the variable to be checked. |
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. |
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.
#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