VB输入N个学生的学号和成绩,打印出成绩最高者的学号和成绩 5
我用5个学生来设计,用结构体,效果图如下:
Private Type stu
id As Integer
fs As Long
End Type
Dim a(4) As stu
Dim i As Integer
Private Sub Command1_Click()
Picture1.AutoRedraw = True
If i >= 5 Then
MsgBox ("最多只能输入5个学生信息"): Text1.Text = "": Text2.Text = ""
Text1.Locked = True: Text2.Locked = True
Else
If Text1 = "" Or Text2 = "" Then
N = MsgBox("请认真填写学生的基本信息", 0 + 48, "提示")
If Text1 = "" Then Text1.SetFocus
If Text2 = "" Then Text2.SetFocus
Else
With a(i)
.id = Val(Text1)
.fs = Val(Text2)
Picture1.Print i + 1; Tab(6); .id; Tab(13); .fs
End With
Text1 = "": Text2 = ""
i = i + 1
End If
End If
End Sub
Private 郑氏慧Sub Command2_Click()
Dim t As stu
Picture2.Cls
Picture2.AutoRedraw = 核液True
imax = 0
For N = 1 To i - 1
If a(N).fs > a(imax).fs Then imax = N
Next N
Picture2.Print "成绩最喊答高分是学号"; a(m).id; Spc(2); "分数为"; a(m).fs
b = 0
For i = 1 To Adodc1.Recordset.RecordCount
a = Adodc1.Recordset("成绩")
If b <闭氏卜 a Then
b = a
End If
If Not Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveNext
End If
Next i
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.Filter = "成绩= '" & b & " ' "
End Sub
Private Sub Form_Load()
Adodc1.ConnectionString = "核纳Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Persist Security Info=False"
Adodc1.CommandType = adCmdTable
Adodc1.RecordSource = "数据表"
Adodc1.Refresh
Adodc1.Recordset.MoveFirst
Set DataGrid1.DataSource = Adodc1
End Sub
建立db1.mdb 建立一个数据表,字轿穗段名为 姓名 学号 成绩