GPA Calculator using Visual Basic.Net

Posted by Samath
  643
February 07, 2017

 

This is a GPA calculator that was programmed using visual basic. It calculate the grades for 5 courses. Feel free to modify the program, add more courses or more features. If you have any question leave it in the comment section below. 

Public Class frmMain

    Dim lettergrd As String
    Dim credit As Double
    Dim caltimes As Double = 0
    Dim totalcal As Double = 0
    Dim totalcredit As Double = 0
    Dim finalgpa As Double = 0
    Dim A As Double = 4.0
    Dim AMINUS As Double = 3.67
    Dim BPLUS As Double = 3.33
    Dim B As Double = 3.0
    Dim BMINUS As Double = 2.67
    Dim CPLUS As Double = 2.33
    Dim C As Double = 2.0
    Dim CMINUS As Double = 1.67
    Dim D As Double = 1.0
    Dim F As Double = 0.0
    Private Sub btncalculateGPA_Click(sender As Object, e As EventArgs) Handles btncalculateGPA.Click
        lettergrd = ""
        credit = 0
        caltimes = 0
        totalcal = 0
        totalcredit = 0
        finalgpa = 0
        Dim defaultcombo = New ComboBox()
        Dim defaultnumeric = New NumericUpDown()
        For i As Integer = 1 To 5

            Select Case i
                Case 1
                    defaultcombo = cmbCourse1
                    defaultnumeric = numCourse1
                    Exit Select
                Case 2
                    defaultcombo = cmbCourse2
                    defaultnumeric = numCourse2
                    Exit Select
                Case 3
                    defaultcombo = cmbCourse3
                    defaultnumeric = numCourse3
                    Exit Select
                Case 4
                    defaultcombo = cmbCourse4
                    defaultnumeric = numCourse4
                    Exit Select
                Case 5
                    defaultcombo = cmbCourse5
                    defaultnumeric = numCourse5
                    Exit Select
            End Select

            lettergrd = defaultcombo.Text
            credit = [Double].Parse(defaultnumeric.Value.ToString())


            If lettergrd <> [String].Empty AndAlso credit <> 0 Then

                Select Case lettergrd
                    Case "A"
                        caltimes = credit * A
                        Exit Select
                    Case "A-"
                        caltimes = credit * AMINUS
                        Exit Select
                    Case "B+"
                        caltimes = credit * BPLUS
                        Exit Select
                    Case "B"
                        caltimes = credit * B
                        Exit Select
                    Case "B-"
                        caltimes = credit * BMINUS
                        Exit Select
                    Case "C+"
                        caltimes = credit * CPLUS
                        Exit Select
                    Case "C"
                        caltimes = credit * C
                        Exit Select
                    Case "C-"
                        caltimes = credit * CMINUS
                        Exit Select
                    Case "D"
                        caltimes = credit * D
                        Exit Select
                    Case "F"
                        caltimes = credit * F
                        Exit Select

                End Select

                totalcredit = totalcredit + credit
                totalcal = totalcal + caltimes

            End If
        Next

        finalgpa = totalcal / totalcredit

        lblfinalgpa.Text = finalgpa.ToString("#.00")


    End Sub

    Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        cmbCourse1.ResetText()
        cmbCourse2.ResetText()
        cmbCourse3.ResetText()
        cmbCourse4.ResetText()
        cmbCourse5.ResetText()

        numCourse1.ResetText()
        numCourse2.ResetText()
        numCourse3.ResetText()
        numCourse4.ResetText()
        numCourse5.ResetText()

        lblfinalgpa.Text = "0.00"
    End Sub
End Class