评委打分的文本框名称为Text1,Text2,……,Text8,“最终得分”按钮的名称为CommandTotal,第二张幻灯片用来显示最后得分,名称为TotalScore。
2.全局变量设置
(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/ruanjianjc/)打开VBA编辑器(见图2)输入如下代码: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 erDim sum As Single'将8个评委的分数相加得出总分sumsum = 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 #1Print #1, AverageScoreClose #1End IfGroupNum = GroupNum + 1er:End Sub
3.建立评奖模块
(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/ruanjianjc/)在Microsoft Visual Basic中点击“插入→模块”来建立评奖模块,再写入如下代码:
Const Counter = 6'如评一等奖1名,二等奖2名,三等奖3名,故Counter设为6Public StrName(Counter) As StringPublic SngScore(Counter) As SinglePublic Sub ReadDataInp()'读取得分文件,并对得分加以排序On Error GoTo erOpen Path$ & "InpName.txt" For Input As #1For i = 1 To CounterInput #1, StrName(i)NextClose #1Open Path$ & "InpScore.txt" For Input As #2For i = 1 To CounterInput #2, SngScore(i)NextClose #2For i = 1 To CounterFor j = 1 To CounterIf SngScore(i) > SngScore(j) Thena = SngScore(i): SngScore(i) = SngScore(j): SngScore(j) = ab = StrName(i): StrName(i) = StrName(j): StrName(j) = bEnd IfNextNexter: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)
大家在制作时可以加入其他的幻灯片用做修饰,这样就能让赛场气氛非常热烈。源程序下载。