How to Create a GPA Calculator in Visual Basic 2008
Visual Basic is an application development language created by Microsoft that's used to develop desktop software applications. Like most programming languages, VB can be used to execute mathematical equations, such as average calculations used to calculate grade point averages. By following the steps in this article, you can create a GPA calculator that allows the user to enter a grade and save it to the application's database, where it will be averaged.
Instructions
-
-
1
Launch the Visual Studio 2008 application to open a new VB document, with which you will code your GPA calculator application.
-
2
Create a new form that will take in the grades and class names:
Public Class Form
Dim Credits As Double
Dim GPA As Double -
-
3
Create a subroutine to record the entry of grades and class names:
Private Sub btnRecord_Click(byVal sender as System.Object, System.EventArgs) Handles btnRecord.Click
-
4
Define the formula that will compute the GPA by adding the following code:
GPA += Grade()
Grade = Credits += CDbl(Credits.text) -
5
Create the arguments for each of the possible grade options and assign them a numerical value, for example:
If Grade.Text = "A" Then GPA += 4
End IfIf Grade.Text = "B" Then GPA += 3
End IfIf Grade.Text = "C" Then GPA += 2
End IfIf Grade.Text = "D" Then GPA += 1
End If -
6
Close the subroutine for the calculator and create a new one that's responsible for saving the results of the calculator:
End Sub
Private Sub btnCalculate_Click(ByVal sender as System.Object, As System.EventArgs) Handles btnCalculate.Click
Dim averageGPA As Double = GPA / Credits
textGPA.Text = CStr((GPA))
End Sub
End Class -
7
Save the VB code and compile it using your preferred code compiler so that you can execute the code as a desktop application.
-
1