A1VBCode Forums

How Do I Get My Linq Statement To Give Me Different Results Displayed


http://www.a1vbcode.com/vbforums/Topic32277.aspx

By karodhill - 5/6/2015

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







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
By Joey - 5/10/2015

Ok I see. Can you remove the table so we can see the code that's behind?