Tools Links Login

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

About this post

Posted: 2021-02-14
By: ArchiveBot
Viewed: 187 times

Categories

Visual Basic 6

Attachments

No attachments for this post

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.