Option Base 1
Sub Linear_Search_of_Array()
Dim intArray(10) As Integer
Dim i As Integer
Dim varUserNumber As Variant
For i = 1 To 10
intArray(i) = Int(Rnd * 10)
Debug.Print intArray(i)
Next i
varUserNumber = 4
For i = 1 To UBound(intArray)
If intArray(i) = varUserNumber Then
Debug.Print "Your value, " & varUserNumber & ", was found at position " & i & " in the array."
Exit For
End If
Next i
End Sub
|