Grade Point Average

  • Thread starter Thread starter Guest
  • Start date Start date
Yagger said:
My code won't work, can someone help me?

Yes, but you'll have to post some code and ask questions. "My code
won't work" doesn't really give us enough to go on.
 
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
 
<snip>

Well, now you've posted some code, but you haven't actually asked any
questions. It would also be useful if you'd post some *complete* code,
so that we can just compile and run it.

See http://www.pobox.com/~skeet/csharp/complete.html for what I mean.

I *suspect* the problem is your select/case, but without more
information I can't say for sure. I don't believe you can use
switch/case like that - but then, I'm more of a C# person than a VB
person. I believe you want to select c(i).grade, and then use

case 80 - 100

etc.
 
Hi Jon
when I run the program I get "Index was outside the bounds of the array

The line " Do until (count = 6) And (marks(count + 1).Text <> "") is highlighte
Linda
 
yagger said:
Hi Jon,
when I run the program I get "Index was outside the bounds of the array"

The line " Do until (count = 6) And (marks(count + 1).Text <> "") is
highlighted

Right. That would be because arrays are zero based, not one based.
 
Back
Top