LastIndexOf Method

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

Syntax

Object.LastIndexOf(Element)

Arguments:

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

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

Returns

The zero-based index of the last occurrence of value within the entire the ArrayList, if found; otherwise, -1.

Remarks

The following example illustrates the use of the LastIndexOf method.

Example 1:


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

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

'Get Last Index of the Element
Index = Obj.LastIndexOf(40)
'Output: 3
Index = Obj.LastIndexOf(50) 
'Output: -1