窗口中的两个文本框为Txt_time和Txt_player,分别用于录入提交答案的时间和选手编号。组合列表框Combo1提供题目编号(A~H),录入时从中选择。检查框Chk_yn用于输入解答是否正确信息。当单击“确定”按钮(Cmd_comfirm)时,录入的提交信息加入列表框List1中,排名情况在列表框List2输出。单击“关闭”按钮时退出应用程序。
在开发过程中,需要编写的部分程序代码如下:
【程序】
Private Type info
No As Integer ′选手编号
Num As Integer ′完成题目数量
Time As Integer ′完成题目的总用时
d(8)As Integer ′d用于记录提交第i个题目错误答案的次数
a(8)As Boolean ′a用于记录第i个题目是否已经提交正确答案
End Type
Dim R(201)As info ′R[j]用于统计编号为j的选手提交答案的情况
Dim Maxlndex As Integer ′Maxlndex记录提交答案的选手中编号最大者
Private Sub Form_Load()
For i = 1 to 8
Combo1. Addltem chr(
________
)
Next
Combo1. Text = Combo1. List(0):txt_time.Text =" ":txt_player.Text =" "
For i = 1 To 200
R(i) num=0:R(i).time =0:R(i).no=i
Forj = 1 To 8
R(i).d(j) =0:R(i).a(j) =False
Next j,i
End Sub
Private Sub cmd_confirm_Click()
Dim h, m, k, time As Integer, ch, pass, s1 As String
K = Instr(txt_time, text,": "):If k<2 Then Goto error1
H = Val(Left(txt_time. Text, k-1)):m = Val(Mid(txt_time. Text, k+1))
If h>11 Or h=11 And m>0 Or m>=60 Then goto errorl
Time=
________
′计算答题时间,以分钟为单位
If txt_plater, text<1 or txt_player, text>200 Then Goto errorl
ch=
________
pass = IIf(chk_yn.
________
=0,"N" ,"Y")
s1 = txt_time. Text+Space
____
+ txt_player. Text
s1 = s1 + Space(10 - Len(txt_player. Text))+ch+Space(8)+pass
List1. Additem s1
K = Val(txt_player. Text) ′k为选手编号
R(k). no =k ′编号为k的选手的提交信息记录在下标为k的数组
′元素中
If k>maxindex Then maxindex = k
M =Asc(ch)-Asc("a")
If pass< >"Y" Then ′编号为k的选手提交第m个题目的解答不正确
R(k).d(m)=R(k).d(m)+1
Else If R(k).a(m)< >True Then ′已经提交正确的题目的解答不再计算
R(k).a(m) =true:R(k).num=R(k).num+1
R(k).time = R(k). time +
________
Call statistic ′调用过程statistic进行实时排名和输出
End If
Exit Sub
error1: MsgBox "录入信息有错误!" ,vbOKOnly
End Sub