Containsメソッド

要素がArrayListオブジェクト内にあるかどうかを判別します。

構文

Object.Contains(Element)

引数:

  • Object: 必須。常にArrayListオブジェクトの名前。

  • Element: 必須ArrayListオブジェクトで検索する要素。

戻り値

ArrayListオブジェクト内で要素が見つかった場合はTrue、それ以外の場合はFalse

備考

次の例では、Containsメソッドの使用方法を示します。

例1:

'Create ArrayList Object
Dim Obj
Set Obj = CreateObject("System.Collections.ArrayList")

'Add Elements to the end of the ArrayList Object
Dim Index
Index = Obj.Add(10)
Index = Obj.Add(40)
Index = Obj.Add(20)

'Determines whether an element is in the ArrayList object
If Obj.Contains(40) Then 'Returns True
        'Operations based on the requirement when ArrayList contains 40 
Else
        'Operations based on the requirement when ArrayList doesn’t contains 40 
End If
'Output: True (Obj contains 40)