给你这个做参考,在窗体上放一个文本框text1和命令按钮command1两个控件。程序开始的时候往数组a中顺序放了0~~20这几个数,然后在文本框中输入要查找的数,单击命令按钮。如果找到打印出该数在数组中的位置,如果没找到则打印没找到该数。代码如下::Dim a(20) As IntegerPrivate Sub Command1_Click() Dim k, low, high, midd As Integer low = 0 high = 20 k = Val(Text1.Text) Do While low <= high midd = (low + high) / 2 If k = a(midd) Then Print midd "如果找到就打印出该数在数组中的位置 Exit Sub ElseIf k < a(midd) Then high = midd - 1 Else low = midd + 1 End If Loop Print "没找到这个数"End SubPrivate Sub Form_Load() dim i as integer For i = 0 To 20 a(i) = i Next iEnd Sub