为了了解选科预选情况,统计选科组合种类及每种组合人数。小王设计并制作了VB程序。运行该程序,单击“读取”按钮,从数据库中读取信息并显示在列表框List1中;单击“统计”按钮,在列表框List2中显示每种选科组合人数(无人选择的组合不显示)及选科组合种类。程序运行界面如图b所示。
Dim cla(1 To 1000) As Integer ‘班级号
Dim snum(1 To 1000) As String ‘学号
Dim sname(1 To 1000) As String ‘姓名
Dim xinxi(1 To 1000) As String ‘选科信息二进制编号
Dim xknum(1 To 127) As Integer ‘各选科组合人数
Dim n As Integer
Private Sub Command1_Click()
‘从数据库中读取n名学生的班级、学号、姓名和选科信息分别存储在数组cla、snum、sname和xinxi中,并输出在列表框List1中,代码略。
End Sub
Private Sub Command2_ Click ( )
Dim t As Integer, i As Integer, count As Integer
For i=1 To n
t = BtoD(xinxi(i))
Next i
count = 0
For i=127 To 1 Step-1 ‘选科组合十进制编号的范围
If Then
count = count + 1
List2.AddItem change(i) +””+ Str (xknum(i)
End If
Next i
List2. AddItem“选科组合种类共有:”+ Str (count) + “种”
End Sub
Function BtoD(s As String) As Integer ‘将选科信息二进制编号转换为十进制编号
Dim x As Integer, i As Integer
x=0
For i=1 To 7
If Mid(s,i,1) = “1” Then
x=
End If
Next i
BtoD = x
End Function
Function change(c As Integer) As String
‘该函数的功能是将选科十进制编号转换成对应的组合名称,代码略。
End Function