|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Const Path$ = "C:\考试评分\"
'指定得分的统计文件路径
Dim sum As Single
'全局变量总分
Dim AverageScore As Single
'全局变量平均得分
Dim GroupNum As Integer
'全局变量记录组次
Private Sub CommandButton1_Click()
'清空得分
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Slide2.TotalScore.Caption = ""
'清空下一张幻灯片的最后总分
End Sub
Private Sub CommandTotal_Click()
'“最终得分”按钮
On Error GoTo er
Dim sum As Single
'将8个评委的分数相加得出总分sum
sum = sum + CSng(Text1.Text)
sum = sum + CSng(Text2.Text)
sum = sum + CSng(Text3.Text)
sum = sum + CSng(Text4.Text)
sum = sum + CSng(Text5.Text)
sum = sum + CSng(Text6.Text)
sum = sum + CSng(Text7.Text)
sum = sum + CSng(Text8.Text)
AverageScore = Format(sum / 8, "#.###")
'计算出最后得分(平均分),精确到小数点后3位
Slide2.TotalScore.Caption = AverageScore
'第二张幻灯片显示最后得分
If GroupNum>=1 AND GroupNum <= 5 Then
'写入最后得分
Open Path$ & "InpScore.txt" For Append As #1
Print #1, AverageScore
Close #1
End If
GroupNum = GroupNum + 1
er:
End Sub
3.建立评奖模块
在Microsoft Visual Basic中点击“插入→模块”来建立评奖模块,再写入如下代码:
Const Counter = 6
'如评一等奖1名,二等奖2名,三等奖3名,故Counter设为6
Public StrName(Counter) As String
Public SngScore(Counter) As Single
Public Sub ReadDataInp()
'读取得分文件,并对得分加以排序
On Error GoTo er
Open Path$ & "InpName.txt" For Input As #1
For i = 1 To Counter
Input #1, StrName(i)
Next
Close #1
Open Path$ & "InpScore.txt" For Input As #2
For i = 1 To Counter
Input #2, SngScore(i)
Next
Close #2
For i = 1 To Counter
For j = 1 To Counter
If SngScore(i) > SngScore(j) Then
a = SngScore(i): SngScore(i) = SngScore(j): SngScore(j) = a
b = StrName(i): StrName(i) = StrName(j): StrName(j) = b
End If
Next
Next
er:
End Sub
4.建立显示获奖名单
回到PPT中新建一张幻灯片,用于显示获奖名单,按钮名称为CmdDisply,6个文本框的名称为Prize1,……,Prize6。代码如下:
Private Sub CmdDisply_Click()
ReadDataInp
'因为分数从高到低排序,因此先输出最后三组
Prize1.Text = StrName(4)
Prize2.Text = StrName(5)
Prize3.Text = StrName(6)
想去掉一个最高,一个最低怎么写啊 |
|