Array.IndexOf Method


Array.IndexOf Method

Class

System.Array

Syntax

     Dim result As Integer = Array.IndexOf(array, _       value[, startIndex[, count]]) 


array (required; any array)

The array to be searched.


value (required; any)

The object to be searched for in the array.


startIndex (optional; Integer)

The index at which to begin the search. If omitted, the search begins with the first element of the array.


count (optional; Integer)

The number of items to search. If omitted, the search continues to the end of the array.

Description

The IndexOf method returns the index of the first occurrence of value in array, or -1 if value was not found within the range searched.

Usage at a Glance

  • array must be a one-dimensional array.

  • Specifying a count value that goes past the end of the array results in an error.

Example

The following code searches for a value in an Integer array:

     Dim counter As Integer     Dim dataSet(99999) As Integer     For counter = 0 To 99999        dataSet(counter) = CInt(Rnd(  ) * 100000)     Next counter     MsgBox(Array.IndexOf(dataSet, 36500)) 

See Also

Array Class, Array.LastIndexOf Method




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net