Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have a linq statement where i turned letter grades into numbers to calculate a gpa can anyone tell me why no matter what grade i click i get the same gpa of 68 for each one? maybe someone can look over my code and give me an answer or hint thanks






VB
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click


        Dim dic As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)
        dic.Add("A", 4)
        dic.Add("B", 3)
        dic.Add("C", 2)
        dic.Add("D", 1)
        dic.Add("F", 0)

        Dim gpa = Aggregate Grade In CoursesDataSet.tblCourses.AsEnumerable()
           Select Grade.Field(Of Integer)("CreditHours") * dic(Grade.Field(Of String)("Grade"))
           Into Sum()


        MessageBox.Show("GPa:" & gpa.ToString("C2"),
                      "College Courses", MessageBoxButtons.OK,
MessageBoxIcon.Information)
    End Sub

End Class



this url is a pic of how the grades are shown on the database
http://i59.tinypic.com/2vinzeo.jpg[^]
Posted
Comments
Sascha Lefèvre 6-May-15 14:41pm    
What do you mean by "no matter what grade i click" ? There's nothing obvious to see in your code that gets influenced by some click. To me it looks like it's always operating with the same input data.
karodhill 6-May-15 14:54pm    
Thats why i uploaded the picture the grades are already on the database with a button you click call gradedisplay the grades are displayed already on the form
Sascha Lefèvre 6-May-15 15:07pm    
Yes I saw it. But I think you're leaving some info out. You say "no matter what grade you click" - but there's nothing to see in your code that depends on a "grade-click". What effect does/should a "grade-click" have?
karodhill 6-May-15 15:16pm    
hmm I didnt think that would matter because there is a previous and nextbutton so i thought whatever its on as long as i say grade* hours it would compute now im really confused
Sascha Lefèvre 6-May-15 15:20pm    
Just explain a bit more in detail how it *should* work :-)

1 solution

All you need is Where[^] instruction inside query ;)

VB
Dim sID As String = "ValueFromDataGridViewCell" 'for example: CS100 
Dim gpa = Aggregate Grade In CoursesDataSet.tblCourses.AsEnumerable()
   Where Grade.Field(Of String)("ID").Contains(sId)
   Select Grade.Field(Of Integer)("CreditHours") * dic(Grade.Field(Of String)("Grade"))
   Into Sum()
 
Share this answer
 
v2
Comments
Sascha Lefèvre 6-May-15 15:47pm    
Pretty sure that's what he wants, so my 5!
Maciej Los 6-May-15 15:51pm    
Thank you, Sascha ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900