⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 code228a.txt

📁 VB大全(精华版)源代码
💻 TXT
字号:
Option Explicit

Public Function BinSearch(ByRef SearchArray As Variant, ByVal _
    SearchFor As Variant, ByVal StartPoint As Integer, ByVal _
    EndPoint As Integer) As Integer
  Dim MidPoint As Integer

  MidPoint = ((EndPoint - StartPoint) / 2) + StartPoint
  If MidPoint < 1 Then
    BinSearch = -1
    Exit Function
  End If
  If SearchArray(MidPoint) < SearchFor Then
    StartPoint = MidPoint
    BinSearch = BinSearch(SearchArray, SearchFor, StartPoint, _
        EndPoint)
  ElseIf SearchArray(MidPoint) > SearchFor Then
    EndPoint = MidPoint
    BinSearch = BinSearch(SearchArray, SearchFor, StartPoint, _
        EndPoint)
  Else
    BinSearch = MidPoint
  End If
End Function

Public Sub Main()
  Dim Int_Values(4) As Integer
  Dim Float_Values(4) As Single
  Dim I As Integer, Match As Integer
  Const Int_Search = 3
  Const Float_Search = 4.5

  For I = 0 To 4
    Int_Values(I) = I + 1
    Float_Values(I) = I + 1.5
  Next
    Match = BinSearch(Int_Values, Int_Search, 0, 4)
  If Match > -1 Then
    Debug.Print "Value "; Int_Search; " found at: "; Match
  Else
    Debug.Print "Value "; Int_Search; " Not Found."
  End If
  Match = BinSearch(Float_Values, Float_Search, 0, 4)
  If Match > -1 Then
    Debug.Print "Value "; Float_Search; " found at: "; Match
  Else
    Debug.Print "Value "; Float_Search; " Not Found."
  End If
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -