Help with Parallel array coding Visual Basic

Here I have the code for this visual basic exercise I am working on. I need help coding the btnDisplay event. I need to store the minimum points I have listed below into a 5-element, one-dimensional integer array named intPoints. Also, for the grades that I have listed below I need a 5-element, one-dimensional string array named strGrades. The arrays should be parallel arrays. The procedure should search the intPoints array for for the number of points entered by the user, and then display the corresponding grade from the strGrades array.

Minimum Points                            Maximum Points                    Grade
               0                                                         299                                        F
           
             300                                                      349                                        D
 
              350                                                    399                                         C
 
             400                                                      449                                        B

             450                                                     500                                         A




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 txtPoints_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPoints.Enter
        txtPoints.SelectAll()
    End Sub

    Private Sub txtPoints_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPoints.KeyPress
        ' accepts only numbers and the Backspace key

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

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

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








    End Sub

End Class
anault24Asked:
Who is Participating?
 
Duy PhamFreelance IT ConsultantCommented:
You can store the Upper-bound Point of Grades into intPoints array, so one way to implement your btnDisplay event could be:

Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
    Dim intPoints As Integer() = New Integer() { 299, 349, 399, 449, 500 }
    Dim strGrades As String() = New String() { "F", "D", "C", "B", "A" }

    Dim enteredPoint As Integer = CInt(txtPoints.Text.Trim)
    Dim idx As Integer = 0
    
    Do While (enteredPoint > intPoints(idx)) And (idx < 4)
        idx = idx + 1
    Loop

    lblGrade.Text = strGrades(idx)
End Sub

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.