Creating A Test Score Average Calculator: Step 1: Step 2
Creating A Test Score Average Calculator: Step 1: Step 2
Step 1: Open Visual Studio and start a new project, and click new windows form application
Step 2: In design mode, create the form based on the following table and figure.
Control Type
Name
Property Values
TextBox
txtScore1
TextBox
txtScore2
TextBox
txtScore3
TextBox
txtScore4
TextBox
txtScore5
Label
lblAverage
Button
btnAverage
Button
btnClear
Text= Clear
Button
btnExit
Text= Exit
Label
(default)
Label
(default)
Label
(default)
Label
(default)
Label
(default)
Label
(default)
Text= Average
Step 3:Double Click on the Calculate Average button, which will bring up the code Window and place the cursor
under the event handler for that button. Insert the following code into the event handler
Private Sub btnAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btnAverage.Click
Try
Dim var1 As Double
Dim var2 As Double
Dim var3 As Double
Dim var4 As Double
Dim var5 As Double
Dim answer As Double
var1 = CDbl(txtScore1.Text)
var2 = CDbl(txtScore2.Text)
var3 = CDbl(txtScore3.Text)
var4 = CDbl(txtScore4.Text)
var5 = CDbl(txtScore5.Text)
answer = (var1 + var2 + var3 + var4 + var5) / 5
lblAnswer.Text = answer.ToString
Catch ex As Exception
MessageBox.Show("please enter valid number")
End Try
End Sub
Step 4: Next, add the event handler for the Clear Button, by double clicking on the button. Insert the following code
into the window.
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btnClear.Click
txtScore1.Text = String.Empty
txtScore2.Text = String.Empty
txtScore3.Text = String.Empty
txtScore4.Text = String.Empty
txtScore5.Text = String.Empty
lblAnswer.Text = String.Empty
txtScore1.Focus()
End Sub
Step 5: Finally we add the event handler for the Exit button.
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btnExit.Click
Me.Close()
End Sub