vb.net - 在 Visual Studio 的 2019 (VB) 中创建一个成绩计算器并在代码中挣扎一下
问题描述
我在 Visual Studio 2019 中使用 VB.Net 来帮助积累考试成绩数据。
我有一个名为 , 的标签和用于,的Score
文本框,它们都是只读的。我也按和分数,以及。Score Total
Score Count
Score Average
Add
Clear
Exit
我已经为 Clear Scores 和 Exit 按钮完成了代码,但我正在努力使用 Add 按钮并获取所有分数的输入和总和。
我的目标是显示方框中所有分数的总和、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
推荐阅读
- sql - Change number automatically with function
- java - JaCoCo(离线仪器)在
乐器 分析整个 pom.xml。但我只需要测试部分 - android - Layouts sometimes overlap in android fragment
- mysql - Determine customers that have spent money at the company for the first time, each month (mySQL)
- java - 查找数组 java 的最佳系数变量
- ionic-framework - 离子中的货币掩码
- javascript - How to take parameters from a URL
- ssis - 渐变维度向导历史属性选项 无开始日期可供选择
- javascript - 用 for 循环表示 Log(n) BigO 表示法的最简单代码是什么?
- c++ - iOS 13 崩溃 - 回溯不可用