Public Class 综合应用
    '下面变量在窗体级声明，整个模块所有过程都可以访问
    Public Structure STUDENT
        Dim xh As String
        Dim xm As String
        Dim xb As String
        Dim nl As Integer
        Dim bj As String
        Dim cj As Single
    End Structure
    Dim stu As STUDENT
    Dim stucol As New Collection
    Dim strtitle As String = "学号" & vbTab & "姓名" & vbTab & "性别" & vbTab & "年龄" & vbTab & "班级" & vbTab & "成绩" & vbCrLf
    '输入数据命令代码
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        With stu
            .xh = TextBox1.Text
            .xm = TextBox2.Text
            .xb = TextBox3.Text
            .nl = TextBox4.Text
            .bj = TextBox5.Text
            .cj = TextBox6.Text
        End With
        stucol.Add(stu, stu.xh)
        Dim x As Object
        For Each x In Controls    'Controls是一个窗体控件集合，每个窗体都有一个Controls集合对象，存储窗台上所有控件
            If UCase(TypeName(x)) = "TEXTBOX" Then
                x.text = ""
            End If
        Next
    End Sub
    '输出数据命令代码
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim strtemp As String = ""
        Dim x As STUDENT
        For Each x In stucol
            strtemp = strtemp & x.xh & vbTab & x.xm & vbTab & x.xb & vbTab & x.nl & vbTab & x.bj & vbTab & x.cj & vbCrLf
        Next
        TextBox7.Text = strtitle & strtemp
    End Sub

    '最高成绩命令代码
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim i, maxindex As Integer
        Dim strtemp As String = ""
        If stucol.Count = 0 Then
            MsgBox("集合中没有学生信息")
            Exit Sub
        End If
        maxindex = 1
        For i = 2 To stucol.Count
            If stucol.Item(maxindex).cj < stucol.Item(i).cj Then
                maxindex = i
            End If
        Next
        strtemp = strtemp & stucol.Item(maxindex).xh & vbTab & stucol.Item(maxindex).xm & vbTab & stucol.Item(maxindex).xb & _
                  vbTab & stucol.Item(maxindex).nl & vbTab & stucol.Item(maxindex).bj & vbTab & stucol.Item(maxindex).cj & vbCrLf
        TextBox7.Text = ""
        TextBox7.Text = strtitle & strtemp
    End Sub

    '最底成绩命令代码
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

    End Sub

    '平均成绩命令代码
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim sum As Single
        Dim x As Object
        If stucol.Count = 0 Then
            MsgBox("集合中没有学生信息")
            Exit Sub
        End If
        For Each x In stucol
            sum = sum + x.cj
        Next
        TextBox7.Text = ""
        TextBox7.Text = sum / stucol.Count
    End Sub
End Class