【加试题】2016年某书城的部分书籍销售数据存放在相应的数据表中,如图a所示。小明编写了一个VB程序,实现如下功能:在文本框Text1中输人图书类别,单击“查询”按钮Command1,程序从数据库读取相关数据进行处理,在列表框List中显示该类图书所有的销售数据(从高到低排序),在文本框Text2中显示该类图书的总销售量。VB程序运行界面如图b所示。实现上述功能的VB程序如下,请回答下列问题:
Dim num As Integer ‘变量num存储数据库实际的记录数
Dim book(1 to 5 000)As String
Dim content(1 To 5 000)As String,content1(1 To 5 000)As String ‘存储类别内容
Dim sales(1 To 5 000)As Long,sales1(1 To 5 000)As Long ‘存储销售量
Private Sub Form Load( )
Dim conn As New ADODB.Connection,rs As New ADODB.Recordset
Dim strSQL As String
conn. ConnectionString="Provider=Microsoft. ACE. OLEDB. 12. 0; Data Source="&App. Path&"\major. accdb"
conn. Open
strSQL="SEl.ECT*FROM count"
Set rs.ActiveConnection=conn
‘从数据表中读取图书类别、类别内容、销售量分别存储到数组book、content、sales中
‘数据库实际读取的记录数存储在变量num中
‘代码略
End Sub
Private Sub Command1_Click()
Dim m As String,n As String,c As Integer,s As Long
Dim i As Integer,j As Integer,k As Integer
List1.Clear
c=0:s=0
m=Text1.Text
For i=l To num ‘将符合的类别内容、销售量重新存储到数组content1、sales1中
If m=book(i)Then
c=c+1
content1(c)=content(i)
sales1(c)=sales(i)
‘①
EndIf
Next i
For i=1 To ‘②
List1.AddItem content1(i)&" "&Str(sales1(i))
Next i
Text2.Text=Str(s)
End Sub