Name
Array.IndexOf Method
Class
System.Array
Syntax
Array.IndexOf(Array,Value[,startIndex[,count]])
-
Array(required; any array) The array to be searched
-
Value(required; any) The object that is searched for
-
startIndex(optional; Integer) The index at which to start the search
-
count(optional; Integer) The number of items to search
Return Value
The index of the first occurrence of Value
in Array, or -1
Description
Returns an Integer representing the index of the first occurrence of
value in Array
Rules at a Glance
Arraymust be a one-dimensional array.By default, the IndexOf method searches for
Valuefrom the beginning to the end ofArray.If
startIndexis provided withoutcount, IndexOf searches fromstartIndexto the last element ofArray.If both
startIndexandcountare provided, the method searchescountelements starting atstartIndex. In other words, it searches fromarray(startIndex)toarray(startIndex + count-1).If
startIndexis present and is outside of the range of the elements inArray, the method returns -1.If
countis present andstartIndex + count-1exceeds the total number of elements inArray, the method call generates an ArgumentOutOfRangeException exception.
Example
The following code searches for a value in an Integer array:
Dim i As Integer
Dim a(99999) As Integer
For i = 0 To 99999
a(i) = CInt(Rnd( ) * 100000)
Next
MsgBox(Array.IndexOf(a, 36500))You can also specify the starting index for the search, as well as the number of elements to search. For example: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access