Skip to main content


Returns the existence status of variables and their array subnodes.




varname Name of a variable to test for existence, and/or the presence of array subnodes.


The Exists function returns an integer code indicating whether a variable is defined (1) or not (0). If the variable is an array, Exists returns an integer code indicating that the specified node’s value is undefined but the node has defined subnodes (2), or that the specified node’s value is defined and the node has defined subnodes (3).

These values can also be represented by the following constants: 0 = vbUndef; 1 = vbHasValue; 2 = vbHasArray. The 3 value is equivalent to vbHasValue and vbHasArray. Refer to the Node Constants page of this manual.

The varname argument must contain a variable, not an expression. For example, ME is an expression, so Exists(ME) generates a compile error. However, Exists(ME.Property) is a valid use of Exists.


The following example demonstrates the use of the Exists function:

Println "x is: ",Exists(x)  ' x is undefined
x = 7
Println "x is: ",Exists(x)  ' x is defined
x(1) = 6
Println "x(1) is: ",Exists(x)  ' x & x(1) defined
y(1) = 55
Println "y(1) is: ",Exists(y)  ' y(1) defined, y not

The above example returns (in sequence): 0, 1, 3, 2.

The following example further demonstrate use of the Exists function with array nodes:

' Erase previously existing data
Erase ^User.TestData 
' Create some demonstration global data
^User.TestData(1)="data"    ' Node 1 is defined but no subnodes
^User.TestData(2,1)="data"  ' Node 2 is not defined but has subnodes
^User.TestData(3)="data"    ' Node 3 is defined and has subnodes

Status = Exists(^User.TestData(1,1)) ' prints vbUndef  0
Println Status," Undefined subnode"
Status = Exists(^User.TestData(1)) ' prints vbHasValue  1
Println Status," Defined node without subnodes"
Status = Exists(^User.TestData(2,1)) ' prints vbHasValue  1
Println Status," Defined subnode without subnodes"
Status = Exists(^User.TestData(2)) ' prints vbHasArray  2
Println Status," Valueless node with defined subnode(s)"
Status = Exists(^User.TestData(3)) ' prints  3,
                                  ' (vbHasValue + vbHasArray)
Println Status," Defined node with defined subnode(s)"

See Also

FeedbackOpens in a new tab