1.某文本文件以下列格式存储若干学生的学号和两门课成绩,编写单击窗体的事件过程:

来源:百度知道 编辑:UC知道 时间:2024/06/18 14:41:19
(1)用通用对话框控件Commondialog1选择该文件;
(2)在Label1(0)~Label1(1)显示总分最高的学生之学号、总分。
文本文件格式
“05010101”,78,89
“05010102”,83,79
……
请求帮助

Private Sub Form_Click()

Dim xh As
String, cj1 As Integer, cj2 As Integer
Dim topxh As
String, topcj As Integer

CommonDialog1.ShowOpen '显示打开文件对话框
Open CommonDialog1.FileName For Input As #1 '打开对话框中选中的文件,打开方式为Input
Do While Not EOF(1) '如果没遇到文件结尾,继续循环
Input #1, xh, cj1, cj2 '从文件读入三个变量到xh,cj1,cj2
If cj1 + cj2 > topcj Then '计算总分高者,成绩总分存到
topcj 中,学号存入 topxh 中
topcj = cj1 + cj2

topxh = xh
End If
Loop
Close #1
Label1(0).Caption = topxh

Label1(1).Caption = topcj
End Sub

3