Well this is my problem..the code below is to display the grade that is associated with the points the user enters. Now, my problem is how can I have a message display an error message when the user enters a number above 500 or my array..any help is greatly appreciated.

Dim strGrades() As String =
            {"F", "D", "C", "B", "A"}

        Dim intPoints() As Integer =
            {0, 300, 350, 400, 450}

        Dim intSearchPoints As Integer

        Dim intSub As Integer

        Integer.TryParse(txtPoints.Text, intSearchPoints)


        Do Until intSub = intPoints.Length OrElse intSearchPoints < intPoints(intSub)
            intSub = intSub + 1
        Loop

        If intSub <= intPoints.Length Then
            lblGrade.Text = strGrades(intSub - 1).ToString
        Else
            lblGrade.Text = "Invalid Points"
        End If

You could do (pseudocode)

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

Dim intSearchPoints As Integer
Dim intSub As Integer = 0

Integer.TryParse(txtPoints.Text, intSearchPoints)

For Each entry As Integer In intPoints
    If intSearchPoints < entry Then Exit For
    intSub += 1
Next

If intSub < intPoints.Length Then
    lblGrade.Text = strGrades(intSub).ToString
Else
    lblGrade.Text = "Invalid Points"
End If

but you should type check and range check your value first. For example

if the entered value is numeric
    convert text to integer
    if number is 0-500
        convert to letter grade
    else
        "number out of range"
    end if
else
    "entered value is not a number"
end if
commented: Thank you Rev. for your quick response. Just need a little bit more help. +0

Ok, i think I got lost somewhere.. Your coding in way beyond my understadning from what I am looking for, but I will do my best to incorporate what u said in my code

you try to debug to see the problem..:)

The following loop looks at each entry in the intPoints array and exits when it finds the first one that is greater than or equal to the user entered score.

For Each entry As Integer In intPoints
    If intSearchPoints < entry Then Exit For
    intSub += 1
Next

Once we get here either intSub will point to an entry in intPoints (in which case the entered score was within 0-500 and therefore corresponds to a letter grade) or intSub is greater than the largest entry in insPoints (in which case the entered number was > 500 and therefore invalid).

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.