I have been trying to figure this out as the instructor is of no help in his teaching. Need to declare variables for the average score and the letter grade. Calculate the average, use IF/ElseIF statements to determine the letter grade, and return the letter grade. The Private Function CalculateGrade is where this needs placed. Create a subprocedure for the click event for btnDisplay button. It should call the CalculateGrade function with three arguments( the three test scores from the text boxes), and display the returned value in the lblGrade box. A=> 90, B =80 but < 90, C =70 < 80, D =60 < 70 and F <60
The attached file is what the program looks like.

Public Class frmMain

    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub txtTest1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTest1.KeyPress
        ' allows the text box to accept only numbers, the period, and the Backspace key

        If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> "." _
            AndAlso e.KeyChar <> ControlChars.Back Then
            e.Handled = True
        End If
    End Sub

    Private Sub txtTest2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTest2.KeyPress
        ' allows the text box to accept only numbers, the period, and the Backspace key

        If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> "." _
            AndAlso e.KeyChar <> ControlChars.Back Then
            e.Handled = True
        End If
    End Sub

    Private Sub txtTest3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTest3.KeyPress
        ' allows the text box to accept only numbers, the period, and the Backspace key

        If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> "." _
            AndAlso e.KeyChar <> ControlChars.Back Then
            e.Handled = True
        End If
    End Sub

    Private Sub txtTest1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTest1.TextChanged
        lblGrade.Text = String.Empty
    End Sub

    Private Sub txtTest2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTest2.TextChanged
        lblGrade.Text = String.Empty
    End Sub

    Private Sub txtTest3_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTest3.TextChanged
        lblGrade.Text = String.Empty
    End Sub

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

    End Sub

    Private Function CalculateGrade(ByVal testScore1 As Decimal, ByVal testScore2 As Decimal, ByVal testScore3 As Decimal) As String
        

        End
    End Function
End Class

Recommended Answers

All 3 Replies

See if this helps.

Public Class frmMain

    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    ' allows the TEXT BOXES to accept only numbers, the period, and the Backspace key
    Private Sub txtTest1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
                                        Handles txtTest1.KeyPress, txtTest2.KeyPress, txtTest3.KeyPress

        If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> "." _
        AndAlso e.KeyChar <> ControlChars.Back Then
            e.Handled = True
        End If
    End Sub

    '// clear the Label on TextBoxes' TextChanged.
    Private Sub txtTest1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
                                            Handles txtTest1.TextChanged, txtTest2.TextChanged, txtTest3.TextChanged

        lblGrade.Text = String.Empty
    End Sub

    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        '// send the TextBoxes values to the function.
        CalculateGrade(txtTest1.Text, txtTest2.Text, txtTest3.Text)
    End Sub

    Private Function CalculateGrade(ByVal testScore1 As Decimal, ByVal testScore2 As Decimal, ByVal testScore3 As Decimal) As String
        Dim myGradeAverage As Decimal = testScore1 + testScore2 + testScore3 '// add grades.
        '// return result.
        If myGradeAverage < 60 Then lblGrade.Text = "F"
        If myGradeAverage >= 60 Then lblGrade.Text = "D"
        If myGradeAverage >= 70 Then lblGrade.Text = "C"
        If myGradeAverage >= 80 Then lblGrade.Text = "B"
        If myGradeAverage >= 90 Then lblGrade.Text = "A"
        Return False
    End Function
End Class

I have added all the TextBoxes to use one event if returning similar code.

Also, the Function could be done a little better to not overwork the "lblGrade", but since you are a student and needs to learn, have fun. :)

Name:         Grades Project
' Purpose:      Display the number of times a grade appears in the array
' Programmer:  happpy on <current date>

Public Class frmMain

    Dim inSubscript As Object

    Private Property intSubscript As Integer

    Private Property IconConverter As Integer

    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        'searches the array a letter grade, then displays the
        'number of times the letter grade appears in the array
        Me.Close()

        Dim strGrades() As String = {"C", "B", "C", "A", "B", "A", _
                                       "F", "A", "B", "B", "C"}
        Dim strSearchFor As String
        Dim intCounter As Integer 'counter

        strSearchFor = txtLettertGrade.Text.ToUpper
        intCounter = 0

        For intSubscript As Integer = 0 To strGrades.Length - 1

why want my code work?

psa112269@yahoo, try removing the Me.Close() from your btnExit.Click and add it as the last line of code in that Sub.

If you still have issues, start a new thread of your own, for your "own" questions.
Do not spam other members' alerts with your replies. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.