Dim marks(6) As TextBox 'Refers to mark textboxe
Dim values(6) As TextBox 'Refers to values textboxe
Structure Grad
Dim grade As Double 'Grade for the mar
Dim values As Double 'Number of credit-value
End Structur
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
'Associate the textbox arrays with the textboxe
marks(1) = txtMark
marks(2) = txtMark
marks(3) = txtMark
marks(4) = txtMark
marks(5) = txtMark
marks(6) = txtMark
values(1) = txtValue
values(2) = txtValue
values(3) = txtValue
values(4) = txtValue
values(5) = txtValue
values(6) = txtValue
End Su
Private Sub btnDisplaygpa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplaygpa.Clic
'Calculate and display the grade point average
Dim grades(6) As Grade 'Holds the course
Dim count As Intege
'Read the data into the courses array until there is no more data
count =
Do Until (count = 6) And (marks(count + 1).Text <> ""
count += 1 'Increment the counte
grades(count).grade = marks(count).Tex
grades(count).values = CDbl(values(count).Text
Loo
If count > 0 The
'Redimension the array for the final count
ReDim Preserve grades(count
'Compute the GPA, and display the result
DisplayGPA(GPA(grades)
End I
End Su
Function GPA(ByVal c() As Grade) As Doubl
'Compute the GPA of a set of courses
Dim i As Intege
Dim points, credits As Doubl
'Add up the points and credits based upon the mark
For i = 1 To c.GetUpperBound(0
Select Case c(i).grade.ToStrin
Case "80 To 100
credits =
points = 4 * c(i).grad
Case "70 To 79
credits =
points = 3 * c(i).grad
Case "60 To 69
credits =
points = 2 * c(i).grad
Case "50 To 59
credits =
points = 1 * c(i).grad
Case "0 To 49
credits =
points =
End Selec
Nex
'The GPA is the points divided by the total credit values
If points = 0 The
Return
Els
Return points / credit
End I
End Functio
Sub DisplayGPA(ByVal gpa As Double
'Display the GPA
txtGPA.Text = FormatNumber(gpa, 2
End Su
End Clas