vbs小铺

Function vbBinarySearch(vb_Array(),vb_Find)
    Dim SearchMin
    Dim SearchMax
    Dim i
    vbBinarySearch = -1
    SearchMin = LBound(vb_Array)
    SearchMax = UBound(vb_Array)
    Do
       i =(SearchMax + SearchMin) 2
       If vb_Array(i) = vb_Find Then
          vbBinarySearch = i
          Exit Do
       End If
       If vb_Array(i) > vb_Find Then
          SearchMax = i - 1
       Else
          SearchMin = i + 1
       End If
    Loop While SearchMax >= SearchMin
End Function

Sub Command_Click()
    Dim vbArr(127)
    For i = 0 To 127
        vbArr(i) = i
    Next

    i = vbBinarySearch(vbArr, 69) 在数组中查找69-->e
    MsgBox Chr(vbArr(i))
   
    i = vbBinarySearch(vbArr, 65) 在数组中查找a的数组序数
    MsgBox i
   
  
    i = vbBinarySearch(vbArr, 128) 在数组中查找108
    MsgBox i   i=-1
End Sub


Command_Click()