Okay, here is my problem. The instructions are I would have to store the minimum points and grades in a five row two column array. The procedure should display the grade corresponding to the number of points entered by the user.

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

This is the code I have, and the book is somewhat helpful..my problem is when I enter the points, nothing is being displayed..what I am I doing wrong? Also, we have not discussed the Exit format yet..Any help and specific explaination is greatly appreciated.

Dim strGrades(,) As String = {{"F", "0"},
                                        {"D", "300"},
                                        {"C", "350"},
                                        {"B", "400"},
                                       {"A", "450"}}
        Dim intSearchPoints As Integer
        Dim intRow As Integer
        Dim intNumRows As Integer
        Dim intFound As Integer

        Integer.TryParse(txtPoints.Text, intSearchPoints)
        intRow = 0
        intFound = "600"
        intNumRows = strGrades.GetUpperBound(0) + 1

        Do Until intFound = "500" OrElse intRow = intNumRows
            If strGrades(intRow, 0) = intSearchPoints Then
                intFound = "500"
            Else
                intRow = intRow + 1
            End If
        Loop
        If intFound = "500" Then
            lblGrade.Text = strGrades(intRow, 1).ToString
        Else
            lblGrade.Text = "Invalid Points"
        End If

A couple of things:

use the boolean result of TryParse to test if there is a number being entered,

Dim ValidTest as Boolean = Integer.TryParse(txtPoints.Text, intSearchPoints)
If Not ValidTest Then
    MsgBox "Please Enter a Valid Number"
    Exit Sub
End If

use a for loop whenever you know the exact number of items to check, then simply check if the value at the loop variable index is greater than intSearchPoints, if so the grade is the value at the loop variable minus 1 index, something like this should work:

lblGrade.Text = "Invalid Points(0-500 only)"
For I = 1 to strGrades.Count -1
    If Val(strGrades(I,1)) > intSearchPoints Then
        lblGrade.Text = strGrades(I-1, 0)
        Exit Sub
    End If
Next
If intSearchPoints <= 500 Then
    lblGrade.Text = strGrades(strGrades.Count-1,0)
End If
commented: I will test that out and post the final result..thanks again +0

Here is what I came up with..The maximum value doesnt display the grade, but it was satisfactory effort..according to my instructor :), but I really do appreciate the help

Dim strGrades(,) As String = {{"F", "0"},
                                        {"D", "300"},
                                        {"C", "350"},
                                        {"B", "400"},
                                       {"A", "450"}}

        'declaring variables
        Dim intPoints As Integer
        Dim intRows As Integer
        Dim intNumRows As Integer
        Dim intFound As Boolean
        'converting text variable to integer
        Integer.TryParse(txtPoints.Text, intPoints)
        'search for the point in the frist colum of the array
        'continue searching until the point is or each
        'row has been searched
        intRows = 0
        intFound = False

        intNumRows = strGrades.GetUpperBound(0) + 1
        Do Until intFound = True OrElse intRows = intNumRows
            If strGrades(intRows, 1) = intPoints Then
                intFound = True
            Else
                intRows = intRows + 1
            End If

        Loop
        'determine whether the point was found
        'displays outcome
        If intFound = True Then
            lblGrade.Text = strGrades(intRows, 0)
        Else
            MessageBox.Show("Valid Points are 0 to 450. Thank You.")
        End If
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.