Vb 6.0
Dim a As Integer
Dim i, j, k As Integer
Dim numbers(20) As Integer
Private Sub Command1_Click()
j = InputBox(" enter the number of elements in the array")
For i = 0 To j - 1
k = InputBox("enter the number:")
numbers(i) = k
Next i
MsgBox ("numbers successfully inserted")
a = InputBox("enter the number to be searched")
search12 (a)
End Sub
Private Function search12(b As Integer)
Dim Min As Integer
Dim Max As Integer
Dim Mid As Integer
Min = 0
Max = UBound(numbers)
Do While Min <= Max
Mid = Int((Min + Max) / 2)
If b = numbers(Mid) Then
' we have a match
MsgBox ("match found")
Exit Function
ElseIf b < numbers(Mid) Then
Max = Mid - 1
ElseIf b > numbers(Mid) Then
Min = Mid + 1
End If
Loop
'If (Min > Max) Then
' if we get here, the state was not found ...
MsgBox ("match not found")
'End If
Exit Function
End Function