题型:综合题 题类:常考题 难易度:困难
高中信息技术综合库——循环语句1
Dim sType(1 To 200)As string '存放图书类别
Dim sNumber(1 To 200)As Integer '存放图书数量
Dim n As Integer
Private Sub Command1_Click( )
Dim conn As New ADODB Connection
Dim rs As New ADODB Recordset
conn. Connection String="Provider=Microsoft.AC
A.OLEDB.12.0;DATA Source="& App. Path &"\ALibrary. accdb"
conn. Open
Set rs. Active Connection=conn
rs. Open"Select*From Book"
'本过程从数据库中读取图书数据,存储在相应的变量中,并在List1中显示
'代码略
End Sub
Private Sub Command2_Chck()
Dim i As Integer, j As Integer, t As Integer, y As Integer
Dim x As String, s As String
Dim flag As Boolean
List2. Clear
x=Text1. Text
y=Val(Text2. Text)
flag=True
For i=1 To n
If sType(i)=x Then
flag=False
Exit for
End If
Next i
If flag Then
sType(n)=x
sNumber(n)=y
End If
For i=1 To n-1
For j=i+1 To n
If Then
t=sNumber (j):s Number(j)=sNumber(i):sNtmaber (i)=t
s=sType(j):sType(j)=sType(i):sType(i)=s
End If
Next j
Next i
List2. AddItem("类别数量")
For i=1 To n
List2. AddItem sType(i)&" "&Str(sNumber(i))
Next i
End sub
原始数据 | 65 | 57 | 59 | 44 | 45 | 69 |
第1遍 | 44 | 65 | 57 | 59 | 45 | 69 |
第2遍 | 44 | 45 | 55 | 57 | 59 | 69 |
第3遍 | 44 | 45 | 57 | 65 | 59 | 69 |
… | … | … | … | … | … | … |
试题篮