在Visual Studio的2019(VB)中创建成绩计算器,并在代码上挣扎了一下



我使用的是VB。. Net在Visual Studio 2019中帮助积累考试成绩数据。

我有一个名为Score的标签,Score Total,Score CountScore Average的文本框都是只读的。我也点击AddClear的分数,以及Exit

我已经完成了清除分数和退出按钮的代码,但我正在努力添加按钮,并获得所有的分数输入和总结。

我的目标是显示Score Total框中所有分数的总和,Score Count框中分数的数量,以及Score Average框中分数的平均值。

这是我目前为止写的:

Public Class GradeCalculator
Dim score As Integer
Dim ScoreTotal As Decimal
Dim ScoreCount As Decimal
Dim Average As Integer
Private Sub frmClearScores_Click(sender As Object, e As EventArgs) Handles frmClearScores.Click
score = 0
ScoreTotal = 0
ScoreCount = 0
Average = 0
txtscore.Text = ""
txtscoretotal.Text = ""
txtscorecount.Text = ""
txtaverage.Text = ""
txtscore.Select()
End Sub
' This is the "Add" button
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class

我怎样才能完成这个?

Public Class GradeCalculator
Dim ScoreTotal As Integer = 0
Dim ScoreCount As Integer = 0
Private Sub frmClearScores_Click(sender As Object, e As EventArgs) Handles frmClearScores.Click
ScoreTotal = 0
ScoreCount = 0
txtscore.Text = ""
txtscoretotal.Text = ""
txtscorecount.Text = ""
txtaverage.Text = ""
txtscore.Select()
End Sub
' This is the "Add" button
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ScoreTotal += CInt(txtscore.Text)
ScoreCount += 1
txtscore.Text = ""
txtscoretotal.Text = ScoreTotal.ToString()
txtscorecount.Text = ScoreCount.ToString()
txtaverage.Text = (CDec(ScoreTotal)/ScoreCount).ToString()
txtscore.Select()
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class

相关内容

最新更新