VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   1920
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3750
   LinkTopic       =   "Form1"
   ScaleHeight     =   1920
   ScaleWidth      =   3750
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   375
      Left            =   1080
      TabIndex        =   0
      Top             =   1320
      Width           =   1455
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Sub birsearch(a(), ByVal low%, ByVal high%, ByVal key, index%)
  Dim mid As Integer
    mid = (low + high) \ 2                      ' 取查找区间的中点
    If a(mid) = key Then
      index = mid                           ' 查找到，返回查找到的下标
      Exit Sub
    ElseIf low > high Then                   ' 二分法查找区间无元素，查找不到
       index = -1
      Exit Sub
  End If
  If key < a(mid) Then                       ' 查找区间在上半部
      high = mid - 1
    Else
      low = mid + 1                          ' 查找区间在下半部
    End If
    Call birsearch(a, low, high, key, index)        ' 递归调用查找函数
End Sub
'主调程序调用:
Private Sub Command1_Click()
  Dim b() As Variant
      b = Array(5, 13, 19, 21, 37, 56, 64, 75, 80, 88, 92)
  Call birsearch(b, LBound(b), UBound(b), 21, n%)
  Print n
End Sub

