Public Class FRM_GPACalculator
Dim dt As New DataTable
Dim j As Integer = 1
Dim sumOfCreditHours As Double = 0
Dim sumOfGPA As Double = 0
Sub calculateGpa()
sumOfCreditHours = 0
sumOfGPA = 0
For i As Integer = 0 To dt.Rows.Count - 1
sumOfCreditHours = sumOfCreditHours + DGV_GpaCalculation.Rows(i).Cells("Credit Hours").Value
sumOfGPA = sumOfGPA + DGV_GpaCalculation.Rows(i).Cells("GPA").Value
Next
LBL_TotalNumberOfSubjects.Text = j
LBL_TotalCreditHour.Text = sumOfCreditHours
LBL_TotalGPA.Text = sumOfGPA
LBL_GPA.Text = sumOfGPA / sumOfCreditHours
End Sub
Private Sub BTN_ADD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_Add.Click
Try
Dim values() As Object = {j, TXT_SubjectName.Text.ToString(), CDbl(TXT_Grade.Text), CDbl(TXT_CreditHour.Text), CDbl(TXT_Grade.Text) * CDbl(TXT_CreditHour.Text)}
dt.Rows.Add(values)
DGV_GpaCalculation.DataSource = dt
calculateGpa()
j = j + 1
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub FRM_GPACalculator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add("Index", Type.GetType("System.String"))
dt.Columns.Add("Subject Name", Type.GetType("System.String"))
dt.Columns.Add("Grade", Type.GetType("System.String"))
dt.Columns.Add("Credit Hours", Type.GetType("System.String"))
dt.Columns.Add("GPA", Type.GetType("System.String"))
End Sub
End Class
我在VB.NET中创建了一个GPA计算器,你也可以看到代码!!
在这里,您必须输入您的主题名称,GPA和学分时间,结果它会为您提供总GPA,学分和CGPA!
现在我如何添加一个可以清除所有内容的清除按钮? 当我们输入GPA,Cridete小时和主题名称时,我为主题的输入标记添加了一个文本,现在我如何在DataTable中添加Marks列以及如何计算persentage?
请帮助我,我将非常感谢!!!
答案 0 :(得分:0)
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
dt.Rows.Clear()
DataGridView1.Refresh()
End Sub
编辑没有看到你问题的第二部分。你能否澄清那部分