Dim b(1 To 20) As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer, m As Integer
i = 1: j = 20
Key = Val(Text1.Text)
Do While (1)
m = (i + j + 1) \ 2
If b(i) < b(m) Then
If (2) Then
j = m - 1
Else
i = m + 1
ElseIf Key = b(m) Then
Exit Do
Else
If Key > b(m) And Key <= b(j) Then
i = m + 1
Else
j = m - 1
End If
Loop
If (3) Then
Label2.Caption = "数组中无此数"
Else
Do While m > 0
If Key = b(m) Then m = m - 1 Else Exit Do
Loop
Label2.Caption = "此数在第" + Str(m + 1) + "个位置"
End If
End Sub