Skip to content

Exists

如果指定的键存在于 Collection 对象中,则返回 True;否则返回 False

语法:object.Exists( key )

object
必需 一个计算结果为 Collection 对象的对象表达式。
key
必需 一个 String 值,标识要在集合中查找的项。

INFO

Exists 是 twinBASIC 扩展;经典 VBA 的 Collection 对象没有 Exists 方法。在 VBA 中要实现相同效果,需要在错误处理块中调用 Item

键比较由 KeyCompareMode 属性控制。

示例

vb
Dim MyCollection As New Collection
MyCollection.Add "alpha", Key:="a"
MyCollection.Add "beta",  Key:="b"

If MyCollection.Exists("a") Then
    Debug.Print "Key 'a' is in the collection."
End If

If Not MyCollection.Exists("z") Then
    Debug.Print "Key 'z' is not in the collection."
End If

另请参阅

twinBASIC及其LOGO版权为作者"韦恩"所有