Hi I am a newb but I am an AS student who has tried with the assignment that follows:
A program that will allow examination scores (out of 100) to be typed in and will display the grade for each score, in descending order. Grades are awarded as follows: Between 0-39= U, 40-59=C 60-79=B 80-100=A.
The program then displays the results in desending order and then will ask the user wether they will The program will check that all numbers entered are valid whole numbers between 0 and 100"
I have designed the visuals just the code I am difficulty with

Public Class Form1
    Dim maths As String = TextBox3.Text
    Dim science As String = TextBox1.Text
    Dim english As String = TextBox2.Text
    Dim Score1 As String = TextBox4.Text
    Dim Score2 As String = TextBox6.Text
    Dim Score3 As String = TextBox7.Text

   Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
if <= 39 If <= 40 Thenmsgbox.Text = ("U") end if >=40
if <= 40 if <59 thenmsgbox.Text = ("C") end if >=60
if <=60 if <=79 thenmsgbox.text = ("B") end if >=80
if <=80 if <=100 then msgbox.text = ("A") end if >100 then msgbox.text = ("Error") 
    End Sub
    Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
if <= 39 If <= 40 Thenmsgbox.Text = ("U") end if >=40
if <= 40 if <59 thenmsgbox.Text = ("C") end if >=60
if <=60 if <=79 thenmsgbox.text = ("B") end if >=80
if <=80 if <=100 then msgbox.text = ("A") end if >100 then msgbox.text = ("Error") 
    End Sub
    Private Sub TextBox7_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox7.TextChanged
if <= 39 If <= 40 Thenmsgbox.Text = ("U") end if >=40
if <= 40 if <59 thenmsgbox.Text = ("C") end if >=60
if <=60 if <=79 thenmsgbox.text = ("B") end if >=80
if <=80 if <=100 then msgbox.text = ("A") end if >100 then msgbox.text = ("Error") 
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox4.Text = TextBox5.Text & maths
        TextBox5.Text = TextBox5.Text & " " & science
        TextBox7.Text = TextBox5.Text & " " & english
    End Sub
End Class

Recommended Answers

All 4 Replies

Not sure what exactly you mean by "displays the results in descending order", or why you're using MessageBox to display it, but have you tried something simple like this? Maybe I'm way off here. This simply uses 3 TextBoxes and 6 Labels. It could, however, be modified to use the MessageBox.Show method pretty easily.

PrivateSub txtScience_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtScience.TextChanged
Dim sScience As String = Val(txtScience.Text)
If sScience <= 39 Then
lblDisplayScience.Text = "U"
ElseIf sScience <= 59 Then
lblDisplayScience.Text = "C"
ElseIf sScience <= 79 Then
lblDisplayScience.Text = "B"
ElseIf sScience <= 100 Then
lblDisplayScience.Text = "A"
Else
lblDisplayScience.Text = "Invalid"
End If
End Sub
Private Sub txtEnglish_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEnglish.TextChanged
Dim sEnglish As String = Val(txtEnglish.Text)
If sEnglish <= 39 Then
lblDisplayEnglish.Text = "U"
ElseIf sEnglish <= 59 Then
lblDisplayEnglish.Text = "C"
ElseIf sEnglish <= 79 Then
lblDisplayEnglish.Text = "B"
ElseIf sEnglish <= 100 Then
lblDisplayEnglish.Text = "A"
Else
lblDisplayEnglish.Text = "Invalid"
End If
End Sub
Private Sub txtMath_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMath.TextChanged
Dim sMath As String = Val(txtMath.Text)
If sMath <= 39 Then
lblDisplayMath.Text = "U"
ElseIf sMath <= 59 Then
lblDisplayMath.Text = "C"
ElseIf sMath <= 79 Then
lblDisplayMath.Text = "B"
ElseIf sMath <= 100 Then
lblDisplayMath.Text = "A"
Else
lblDisplayMath.Text = "Invalid"
End If
End Sub

If I completely missed your purpose here, I apologize in advance.

Not to take anything away from kristinaswan but I like short code. :cheesy:
Here I combined what she wrote into a more compact code.

Public Class Form1
    ' combine all the textboxes in one TextChanged Event
    Private Sub txtScience_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles txtScience.TextChanged, txtEnglish.TextChanged, txtMath.TextChanged

        ' set a txt object to the textbox that is clicked
        Dim txtObj As TextBox = CType(sender, TextBox)
        ' get the value of the textbox
        Dim GradeValue As Integer = Integer.Parse(txtObj.Text)
        ' now determine which textbox it is and calculate the grade for that textbox
        Select Case txtObj.Name
            Case "txtScience"
                lblDisplayScience.Text = Calculate(GradeValue)
            Case "txtEnglish"
                lblDisplayEnglish.Text = Calculate(GradeValue)
            Case "txtMath"
                lblDisplayMath.Text = Calculate(GradeValue)
        End Select
    End Sub

    ' This does the calculation for the grade letter
    Private Function Calculate(ByVal Grade As Integer) As String
        If Grade <= 39 Then
            Return "U"
        ElseIf Grade <= 59 Then
            Return "C"
        ElseIf Grade <= 79 Then
            Return "B"
        ElseIf Grade <= 100 Then
            Return "A"
        Else
            Return "Invalid"
        End If
    End Function

End Class

Much shorter. This was only my fourth program as I'm just learning VB.NET so I didn't know about the Select Case function yet. Thanks for letting me learn something new! :)

thank you both very much!!

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.