Const n=3500 ’存储单词的总数
Dim a(1 To n)As String ’依次存储每个英语单词
Dim b(1 To n) As Strin9 ’依次存储每个英语单词的中文含义
Private Sub Command1_Click()
Dim Conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
conn.ConnectionString=“Provider=Microsoft.ACE.OLEDB.12.0;Data source=”&App.Path&“\dictionary1.accdb”
strSQL=”select*from list”
conn.Open
Set rs.ActiveConnection=conn
rs.Open strSQL
num=0
Do While Not rs.EOF
num=num+1
a(mum)=rs.Fields(“英语单词”)
b(num)=rs.Fields(“中文含义”)
rs.MoveNext
Loop
rs.Close
conn.Close
Set rs=Nothing
Set conn=Nothing
For i==1 To n
List1.AddItem a(i)+“ ”+b(i)
Next i
End Sub
Private Sub Command2_Click()
Dim s As String
S=Text1.Text
If search(s)=-1 Then
Text2.text=“找不到该单词”
Else
Text2.Text= ①
End If
End Sub
Function search(key As String)As Integer
Dim i,j As Integer
Dim mid1,mid2 As Integer
i=1:j=n
search=-1
Do While i<=j
mid1=Int(j+(j—i)/3)
mid2=Int(j-(j-i)/3)
If key=a(mid1)Then
search=mid1
Exit Do
ElseIf key<a(mid1)Then
j=mid1-1
ElseIf key=a(mid2)Then
search=mid2
Exit Do
Elself key>a(mid2)Then
i=mid2+1
Else
i=mid1+1
②
End If
Loop
End Function
① ②