Dim xm (1 To 1000) As String, bj(1 To 1000) As Integer
Dim tc1 (1 To 1000) As String, tc2(1 To 1000) As String ,n As Integer
Private Sub Form Load( )
'从数据库中按班级、学号有序地读取学生的姓名、班级、中午套餐、晚上套餐,依次存入xm、bj、tc1、tc2数组中,总人数存入n中,部分代码如下,其余代码略
Dim conn As New ADODB.Conncction
Dim rs As New ADODB.Recordset
conn ConncctionString = "provider=Microsoft.ACE.OLEDB.12.0;data source=" + "jiucan.accdb"
conn.Open
Set rs.ActiveConnection = conn
End Sub
Private Sub Command1_Click()
Dim k As Integer, i As Integer, t As Integer, m As Integer, s1 As String, s2 As Integer Dim zc (1 To 4) As Integer, wc (1 To 4) As Integer '用于统计套餐数量
Dim bs (0 To 20) As Integer , ljs (0 To 20) As Integer
t = Val (Text1. Text):m = 0
For i = 1 To 4 '为数组赋初始值
zc(i) = 0: wc(i) = 0
Next i
For i = 0 To 20 '为数组赋初始值
bs(i) = 0: ljs(i) = 0
Next i
For i = 1 To n – 1 '按班级编号进行升序排序
For j = i To n- 1
If bj(j) < bj(k) Then k = j
Next j
s1 = xm(i): xm (i) = xm (k): xm (k) = s1
s2 = bj(i): bj (i) = bj (k): bj (k) = s2
s1 = tc1(i): tc1 (i) = tc1 (k): tc1 (k) = s1
s1 = tc2(i): tc2 (i) = tc2 (k): tc2 (k) = s1
bs(bj(i)) = bs(bj(i)) + 1
If bs(bj(i)) = 1 Then
Next i
bs(bj(i)) = bs(bj(i)) + 1
For i = 1 To m
Next i
For i = ljs(t) - bs(t) + 1 To ljs(t)
zc(fx(tc1(i))) = zc(fx(tc1(i))) + 1
wc(fx(tc2(i))) = wc(fx(tc2(i))) + 1
Next i
'查询班级的用餐情况,在列表框 List 中输出,代码略
End Sub
Function fx(a As String) As Integer
End Function