Hi everyone, I am working on a window that will calculate an average grade from 3 grades typed in by user then display it's appropriate grade letter. This is what I have so far and well it isn't working. Can anyone point me into the right direction as to what I am doing wrong. It is making me nuts :) Right now when I run to app and type in 10 for each grade, it returns 1010 and displays B as the grade.
Thank you to all who can assist me.

Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        
      
         Dim dbltotalaverage As Double


        dbltotalaverage = Val(txtTestscore1.Text + txtTestscore2.Text + txtTestscore3.Text) / 3
        lblthree.Text = dbltotalaverage.ToString


        If dbltotalaverage <= 90 Then
            txtgrade.Text = "A"
        ElseIf dbltotalaverage >= 80 Then
            txtgrade.Text = "B"
        ElseIf dbltotalaverage >= 70 Then
            txtgrade.Text = "C"
        ElseIf dbltotalaverage >= 60 Then
            txtgrade.Text = "D"
        Else
            txtgrade.Text = "F"


        End If


    End Sub
End Class

Hi horseygal,
you have to split your calculation..
For example:

dbltotalaverage = (Val(txtTestscore1.Text) + Val(txtTestscore2.Text) + Val(txtTestscore3.Text)) / 3

Its not necessary to convert the value to string.
lblthree.Text = dbltotalaverage.ToString

Also your if clause should be like this:

If dbltotalaverage >= 90 Then
                txtgrade.Text = "A"
            ElseIf dbltotalaverage >= 80 And dbltotalaverage <90 Then
                txtgrade.Text = "B"
            ElseIf dbltotalaverage >= 70 And dbltotalaverage <80 Then
                txtgrade.Text = "C"
            ElseIf dbltotalaverage >= 60 And dbltotalaverage <70 Then
                txtgrade.Text = "D"
            Else
                txtgrade.Text = "F"
            End If

Good luck..

Also your if clause should be like this:

If dbltotalaverage >= 90 Then
                txtgrade.Text = "A"
            ElseIf dbltotalaverage >= 80 And dbltotalaverage <90 Then
                txtgrade.Text = "B"
            ElseIf dbltotalaverage >= 70 And dbltotalaverage <80 Then
                txtgrade.Text = "C"
            ElseIf dbltotalaverage >= 60 And dbltotalaverage <70 Then
                txtgrade.Text = "D"
            Else
                txtgrade.Text = "F"
            End If

Not really. This should suffice:

If dbltotalaverage >= 90 Then
      txtgrade.Text = "A"
   ElseIf dbltotalaverage >= 80  Then
      txtgrade.Text = "B"
   ElseIf dbltotalaverage >= 70  Then
      txtgrade.Text = "C"
   ElseIf dbltotalaverage >= 60  Then
      txtgrade.Text = "D"
   Else
      txtgrade.Text = "F"
End If

The second part is not necessary because the comparison preceeding takes the < into account already.

Thank you! It works man I owe you big time. It was totally driving me insane and it was so simple, I guess you try so hard sometimes you miss things.

Thanks again!!!:);)

Your code would probably be more efficient and more readable with a Select Case block instead of the IF, ElseIf.

Select Case dbltotalaverage
    Case 90 To 100
        txtgrade.Text = "A"
    Case 80 To 89
        txtgrade.Text = "B"
   Case 70 To 79
        txtgrade.Text = "C"
   Case 60 To 69
        txtgrade.Text = "D"
   Case Else
        txtgrade.Text = "F"
End Select
This question has already been answered. Start a new discussion instead.