2
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 Hours 和 Subject name 时,我添加了一个用于输入主题标记的文本文件,现在我如何在 DataTable 中添加 Marks 列以及如何计算 persentage?

请帮助我,我将非常感激!!!

4

1 回答 1

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

编辑没有看到你问题的第二部分。你能澄清那部分吗

于 2012-11-22T21:44:56.790 回答