Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

Exists

変数および配列内のサブノードの存在の状態を返します。

Synopsis

Exists(varname)

引数

varname 存在を評価する変数の名前、および配列のサブノードの名前、またはいずれかの名前。

概要

Exists 関数は、変数が定義されているか (1)、いないか (0) を示す整数コードを返します。変数が配列の場合は、指定されたノードの値が未定義で、サブノードが定義されているか (2)、指定されたノードの値が定義され、サブノードも定義されている (3) ことを返します。

これらの値は、0 = vbUndef、1 = vbHasValue、2 = vbHasArray のように定数で表現することもできます。3 の値は、vbHasValue かつ vbHasArray と等価です。詳細は、このドキュメントの "Node 定数" を参照してください。

varname 引数には式ではなく、変数を指定する必要があります。例えば、ME は式であるので、Exists(ME) ではコンパイル・エラーが生成されます。しかし、Exists(ME.Property) とすれば、Exists は有効になります。

以下の例は、Exists 関数の使用法を示しています。

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

上の例は、0, 1, 3, 2 の順に値を返します。

以下の例は、Exists 関数と配列ノードの詳しい使用法を示しています。

' 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
^User.TestData(3,1)="data"

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)"

関連項目

FeedbackOpens in a new tab