IndexOf Method

Returns the zero-based index of the first occurrence of a value in the ArrayList object.

Syntax

Object.IndexOf(Element,StartIndex)

Arguments:

  • Object: Required. Always the name of ArrayList object.

  • Element: Required. The Object to locate in the ArrayList object.

  • StartIndex: Required. The zero-based starting index of the search

Returns

The zero-based index of the first occurrence of value within the range of elements in the ArrayList that extends from StartIndex to the last element if found otherwise -1

Remarks

The following example illustrates the use of the IndexOf method.

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

'Get the Index of the Element
Index = Obj.IndexOf(40, 0)
'Output: 1
Index = Obj.IndexOf(50, 0)
'Output: -1