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

Developing Application - Exercise Handout

The document provides instructions for creating a basic calculator application using Visual Studio. It involves adding text boxes and buttons to the form, writing code to handle button clicks and perform calculations, and displaying results. Key steps include declaring variables to store operands and results, writing code for each calculation button to get values from text boxes, perform the operation and display the output. Additional code is provided to clear the text boxes and reset the display for the clear button. Students are asked to test the application, document the code, and save screenshots with their activity file.

Uploaded by

Arish altmish
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Developing Application - Exercise Handout

The document provides instructions for creating a basic calculator application using Visual Studio. It involves adding text boxes and buttons to the form, writing code to handle button clicks and perform calculations, and displaying results. Key steps include declaring variables to store operands and results, writing code for each calculation button to get values from text boxes, perform the operation and display the output. Additional code is provided to clear the text boxes and reset the display for the clear button. Students are asked to test the application, document the code, and save screenshots with their activity file.

Uploaded by

Arish altmish
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Exercise: Developing Applications – Visual Studio Class 8

Developing Applications – Exercise Handout


Creating a calculator using windows form on Visual Studio:
1. Open Visual Studio.
2. Select New Project.
3. Select Windows Form Application.
4. Add two text boxes and six buttons.
5. Edit the text of buttons and their names by the following sequence:
a. First button text Add+ and name should be btnAdd
b. Second button text Subtract- and name should be btnSubtract
c. Third button text Multiply X and name should be btnMultiply
d. Fourth button text Divide / and name should be btnDivision
e. Fifth button text Exponent ^ and name should be btnExponent
f. Sixth button text Clear and name should be btnClear
6. Edit the text of first label to Result and name should be lblResult
and make appropriate visual changes to make it more prominent
for i.e. background color, font type, font color etc.
7. Remove the text of second label and name should be lblErrMsg
8. Click on the blank area of form and in properties layout window, under the StartPosition
property, select CenterScreen.
9. Make sure to align every component aesthetically to give a clear and simple design to the
application for best user interface experience.
10. Double click on the Add+ button to open the script window:
11. Declare three public variables so they can be reused in every Subroutine:
Public operand1 As Integer
Public operand2 As Integer
Public result As Integer

12. Enter the following code to use and calculate these variables along with event handler so if the
user enters the string in text box so than the program should give feedback to user about the
mistake:
Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles
btnAdd.Click
On Error GoTo error_handler
operand1 = TextBox1.Text
operand2 = TextBox2.Text
result = operand1 + operand2
lblResult.Text = result
Exit Sub
error_handler:

The City School/Academics/Computing Curriculum/Class 8/2022-2023 Page 1 of 2


Exercise: Developing Applications – Visual Studio Class 8

lblErrMsg.Text = "Enter numbers only !"


lblResult.Text = "Error >"
End Sub

13. Copy past the whole code mentioned in step 11 for every subroutine(Add+, Subtract-, Multiply
X, Divide /, Exponent ^) by double clicking on the buttons and do a minor change in result
variable depending on the operator
result = operand1 - operand2
result = operand1 * operand2
result = operand1 / operand2
result = operand1 ^ operand2

14. Add the following code to Clear button to make a clear function as a traditional calculator has:
lblErrMsg.Text = " "
lblResult.Text = "Result"
TextBox1.Text = 0
TextBox2.Text = 0

15. Run the program and test every aspect to make sure the functionality of the calculator.
16. Copy paste the script of the program in a word document and also take the screenshot of the
executed form and paste it in the word document.
17. Take a printout of word document and file it in your student activity file also save the word
document with your name in the class folder.

The City School/Academics/Computing Curriculum/Class 8/2022-2023 Page 2 of 2

You might also like