0% found this document useful (0 votes)
25 views

Creating A Test Score Average Calculator: Step 1: Step 2

The document provides steps to create a test score average calculator in Visual Studio. It involves: 1. Creating a new Windows form application project and adding textboxes for inputting 5 test scores and a label to display the average. 2. Adding code to the "Calculate Average" button's click event handler to get the values from each textbox, calculate the average, and display it in the label. 3. Adding code to the "Clear" button's click event handler to clear all textboxes and labels. 4. Adding code to the "Exit" button's click event handler to close the application.

Uploaded by

Rachel Manning
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Creating A Test Score Average Calculator: Step 1: Step 2

The document provides steps to create a test score average calculator in Visual Studio. It involves: 1. Creating a new Windows form application project and adding textboxes for inputting 5 test scores and a label to display the average. 2. Adding code to the "Calculate Average" button's click event handler to get the values from each textbox, calculate the average, and display it in the label. 3. Adding code to the "Clear" button's click event handler to clear all textboxes and labels. 4. Adding code to the "Exit" button's click event handler to close the application.

Uploaded by

Rachel Manning
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Creating a test score average calculator

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

Text= Calculate Average

Button

btnClear

Text= Clear

Button

btnExit

Text= Exit

Label

(default)

Text= Test Score 1

Label

(default)

Text= Test Score 2

Label

(default)

Text= Test Score 3

Label

(default)

Text= Test Score 4

Label

(default)

Text= Test Score 5

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

You might also like