Search an Array
Search an array for a given value.
'search for first occurrence of TestValue in MyArray
'if you know the upper/lower limits of the array, just use them
'TestValue and MyArray should have the same type
Dim TestValue As String
TestValue = "searchstring"
For i = Lbound (MyArray) To Ubound (MyArray)
If MyArray(i) = TestValue Then
'value found, do something
Exit For 'stop searching
End If
next i
'search all elements of MyArray for TestValue
'if you know the upper/lower limits of the array, just use them
'TestValue and MyArray should have the same type
Dim TestValue As String
TestValue = "searchstring"
For i = Lbound (MyArray) To Ubound (MyArray)
If MyArray(i) = TestValue Then
'value found, do something, then continue searching
End If
next i
Special Instructions
This content is reprinted for archival purposes from Gary Beene's Information Center, with permission from Mr. Beene himself.
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.