(2)
请在画线处填入合适的代码。
Dim id(1 To 1 000)As Integer ‘存储记录的ID
Dim s(1 To 1 000)As String ‘存储车牌号
Dim D(1 To 1 000)As Single ‘存储排量
Dim cz(1 To 1 000)As String ‘存储车主信息
Dim zt(1 To 1 000)As String ‘存储车辆状态
Dim n As Integer,key As String
Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
conn.ConnectionString=“provider=Microsoft.Jet.OLEDB.4.0;Data Source=“+App.Path+”\car.mdb”
conn.Open
Set rs.ActiveConnection=conn
Dim sq1 As String
sq1=”SELECT*FROM qicheinfo”
rs.Open sq1
rs.MoveFirst
Do While Not rs.EOF
n=n+1
id(n)=rs.Fields(“ID”):s(n)=rs.Fields(“车牌号”)
p(n)=rs.Fields(“排量”):cz(n)=rs.Fields(“车主”)
zt(n)=rs.Fields(“状态”)
rs.MoveNext
Loop
End Sub
‘按排量查询车辆信息
Private Sub Command1_Click()
key=Val(Text1.Text)
If px(1)=True Then
List1.Clear
x=0
For i=1 To n
If p(i)>=key Then
List1.AddItem id(i)&“”& s(i)&“”&.p(i)&“”&.cz(i)
&“”& zt(i)
①
End If
Next i
If x>0 Then
List1.AddItem“共找到”+Str(x)&.”条记录!”
Else
List1.Additem”没找到相关信息!¨
End If
End If
End Sub
‘按车主信息查询车辆信息
Private Sub Command2_Click()
List1.Clear
Key=Text1.Text
If px(2) Then
i=chazhao(key)
If i>0 Then
List1.AddItem id(i) &””& s(i) &””&p(i)&””& cz(i)” &”
“&.zt(i)
Else
List1.AddItem”没找到相关信息!”
End If
End If
End Sub
Private Function px(m As Integer)As Boolean
Dim flag As Boolean
If m=1 Or m=2 Then
px=True
flag==False
For pa=1 To n-1
For pb=n To pa+1 Step-l
If m=1 Then flag=p(pb)
If m=2 Then flag=cz(pb)
If flag Then
tid=id(pb):id(pb)=id(pb-1):id(pb-1)=tid
ts=s(pb):s(pb)=s(pb-1):s(pb-1)=ts
tp=p(pb):p(pb)=p(pb-1):p(pb-1)=tp
tz=cz(pb):cz(pb)=cz(pb-1):cz(pb-)=tz
tzt=zt(pb):zt(pb)=zt(pb-1):zt(pb-1)=tzt
②
End If
Next pb
Next pa
Else
px=False
End If
End Function
Private Function chazhao(key As String)As Integer
Dim mk As Integer
I=1:j=n
Do While i
mk=(i+j)\2
If cz(mk)=key Then
③
Exit Do
Elself key
j=mk-1
Else
i=mk+1
End If
Loop
End Function
①________ ②________ ③________