Parallel Array- VB Coding If/Then/Else Statement

ADMINISTRATOR: THIS IS NOT AN ACADEMIC ASSIGNMENT. THIS IS FROM THE PROGRAMMING WITH MICROSOFT VISUAL BASIC 2008 BOOK!!!!

Here I have the code for this visual basic exercise I am working on in the visual basic 2008 book which I AM NOT USING FOR ACADEMIC (SCHOOL) USE. I need help coding the btnDisplay event. I was wondering how to use an If/Then/Else Statement and a parallel array. 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.

Thanks for all the help you experts do!!



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


Here is the code I have so far

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

Open in new window

anault24Asked:
Who is Participating?
 
Fernando SotoRetiredCommented:
Hi anault24;

Seeming that you have clarified your question in this post try this.

Public Class Form1

    Dim minPoints() As Integer = {0, 300, 350, 400, 450}
    Dim maxPoints() As Integer = {299, 349, 399, 449, 500}
    Dim strGrades() As String = {"F", "D", "C", "B", "A"}
    
    '' Your other code here
    
    Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click

      Dim pointsEntered As Integer = 0
      
      If Integer.TryParse(txtPoints.Text, pointsEntered) Then
          If Not (pointsEntered >= minPoints(0) AndAlso pointsEntered <= maxPoints(maxPoints.Length - 1)) Then
              lblGrade.Text = "Outside the given limits"
          End If
          For index As Integer = 0 To minPoints.Length - 1
              If pointsEntered >= minPoints(index) AndAlso pointsEntered <= maxPoints(index) Then
                  lblGrade.Text = strGrades(index)
              End If
          Next
      End If
      
    End Sub

End Class

Open in new window

0
 
Fernando SotoRetiredCommented:
Did that help you out @anault24?
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.