Link to home
Start Free TrialLog in
Avatar of Mkelliny
Mkelliny

asked on

Parallel Array

I know what I need to do Just not sure of how to start it off, The program is supposed to have points entered and it should display the grade Letter corresponding to the points. I have the key press limitations and the clearing done. I just need a push in the right direction with linking the array. Here is what 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 Display_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        'assign array values
        Dim Points() As Integer = {450, 400, 350, 300, 0}
        Dim Grade() As String = {"A", "B", "C", "D", "F"}


    End Sub

    Private Sub txtPoints_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPoints.KeyPress
        ' allows the text box to accept 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

End Class

Open in new window

Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

When the "btnDisplay" button is clicked, you need to convert the string value in your "txtPoints" textbox to an integer so it can be compared to your "Points" array.
Avatar of Mkelliny
Mkelliny

ASKER

I am not sure I understand what you are saying, can you clarify?
SOLUTION
Avatar of brutaldev
brutaldev
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Are you required to use the "parallel arrays?...or can you use something else?
We are required to use the parallel arrays.
I would recommend using the Dictionary Object...


  Private Sub Display_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        lblGrade.text = GetGrade(Integer.Parse(txtPoints.Text))
    End Sub

    Private Function GetGrade(ByVal points_value As Integer) As String
        'assign array values
        Dim Points As Dictionary(Of Integer, String) = New Dictionary(Of Integer, String)
        Dim value As String = ""
        Dim blnSuccess = False

        Points.Add(450, "A")
        Points.Add(400, "B")
        Points.Add(350, "C")
        Points.Add(300, "D")
        Points.Add(0, "F")

        blnSuccess = Points.TryGetValue(points_value, value)    'returns a True or False if it was able to find, and set value = Grade

        
        If blnSuccess Then 'you can handle if it found it or not here

        Else

        End If
        GetGrade = value    'return value
    End Function

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, I followed your directions and I am getting a no source code available error?  Nothing is running
?

Post your current code...
Nevermind I worked it out I had the Arrays in the wrong place They where under the btnExit sub procedure.
Thank you Idle_Mind and BrutalDev I appreciate your guys help, I just kinda wish that I didn't get the answer would have liked to work it out on my own with an example or something, but you two are EXTREMELY appreciated nonetheless! Thank you so much!
Great help !
"I just kinda wish that I didn't get the answer would have liked to work it out on my own "

I agree and was working in that direction with my initial posts but brutaldev jumped the gun.  =)