In: Computer Science
Visual Basics
In this exercise, you modify the History Grade application from this chapter’s Focus lesson. Use Windows to make a copy of the History Solution folder. Rename the copy History Solution-Functions. Open the History Solution.sln file contained in the History Solution-Functions folder. Modify the btnDisplay_Click procedure so that it uses two functions named GetGrade101 and GetGrade201 to get the appropriate grade; the procedure should then display the grade in the lblGrade control. Change the two independent Sub procedures to functions that return the appropriate grade to the statements that invoke them in the btnDisplay_Click procedure. Each function should contain a parameter that accepts the total points passed to it. Save the solution and then start and test the application.
Option Explicit On
Option Strict On
Option Infer Off
Public Class frmMain
' Independent Sub procedures.
Private Sub btnDisplay_Click(sender As Object, e
As EventArgs) Handles btnDisplay.Click
' Calls independent Sub
procedures to display a grade.
End Sub
Private Sub btnExit_Click(sender As Object, e
As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub txtPoints_Enter(sender As Object,
e As EventArgs) Handles txtPoints.Enter
txtPoints.SelectAll()
End Sub
Private Sub ClearGrade(sender As Object, e As
EventArgs) Handles txtPoints.TextChanged, radHis101.CheckedChanged,
radHis201.CheckedChanged
lblGrade.Text =
String.Empty
End Sub
Private Sub txtPoints_KeyPress(sender As
Object, e As KeyPressEventArgs) Handles txtPoints.KeyPress
' Accept 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
Hi,
Please follow the below code snippest which you need to add in your project and need to call the respected new functions based on the condition:
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
' Calls independent Sub procedures to display a grade.
''Here I assumed that you will call the newly created function based on the radio button below
'' you need to use appropriate condition here which will decide when to call the below functions
If radHis101.Checked Then
lblGrade.Text = GetGrade101(intPoints)
Else
lblGrade.Text = GetGrade201(intPoints)
End If
End Sub
' Independent Sub procedures.
Private Function GetGrade101(ByVal intPoints As Integer) As String
Select Case intPoints
Case Is >= "90"
Grade = "A"
Case Is >= "80"
Grade = "B"
Case Else
Grade = "F"
End Select
Return Grade
End Function
Private Function GetGrade201(ByVal intPoints As Integer) As String
Select Case intPoints
Case Is >= "75"
Grade = "P"
Case Else
Grade = "F"
End Select
Return intPoints
End Function
Thanks.