Microsoft+Visual+Studio+Activity+1

Create a calculator (which can operate with integers)
Creating a calculator using Microsoft Visual Studio may at first seem very difficult, actually, it is very simple; today we will earn, step by step how to create one. In this case, we will use INTEGERS, (int) therefore, no decimal numbers can be operated with this calculator. In case of doing so, the program will have an error and colapse. First of all, we must open Microsoft Visual Studio and create a new project. In Form1, we must create two text boxes, which will allow the user to write two numbers. Next, we must create four different buttons, one for adding, subsrtacting, dividing and multiplying. Finally, we must create four different labels in order to send the results there.

Now, we are ready to program!

First of all, we need to set an order to our programming order. We must decide which will be the order in which actions must be done to program it in that way. In this case our ordr is as follows:

1.- User introduces a value in text box number one. 2.- User introduces a value in text box number two. -Up to this moment, no changes have ocurred- 3.- Once the two values are set, the user must click ONE of the buttons (addition, substraction, division or multiplication) 4.- Each button will chage the text of the 4 different lables and will express the result of the operation. -The user may click one after the other, and the labels will change- -The user may change a value and the labels will not change AUTOMATICALLY, another clikc is needed to get the new result.

Addition

int x; x = int.Parse(textBox1.Text); (change the text in text box 1 to numbers using INTEGERS) int y; y = int.Parse(textBox2.Text); (change the text in text box 2 to numbers using INTEGERS) (WE NOW HAVE CONVERTED TO NUMBERS THE VALUES WRITTEN BY THE USER AS TEXT) int z; z = x + y; (WE ASSIGN A NEW VARIABLE, Z AND USE THE FORMER VARIABLES ALREADY SET TWO ADD THEM) label1.Text = "The addition of " + x +" + "+ y + " is " + z; (WE CHANGE THE LABEL 1 TEXT SO IT SAYS THE RESULT) label1.ForeColor = Color.Blue;(WE CHANGE THE FORECOLOR [LETTER COLOR] OF THE LABEL1)

(BY THIS POINT, THE FIRST OF 4 LABELS HAS CHANGED AND INDICATES THE VALUE OF THE ADDITION OF X AND Y)

SUBSTRACTION

int x; x = int.Parse(textBox1.Text); (change the text in text box 1 to numbers using INTEGERS) int y; y = int.Parse(textBox2.Text); (change the text in text box 2 to numbers using INTEGERS) (WE NOW HAVE CONVERTED TO NUMBERS THE VALUES WRITTEN BY THE USER AS TEXT) int z; z = x - y; (WE ASSIGN A NEW VARIABLE, Z AND USE THE FORMER VARIABLES ALREADY SET TWO ADD THEM) label2.Text = "The addition of " + x -" + "+ y + " is " + z; (WE CHANGE THE LABEL 1 TEXT SO IT SAYS THE RESULT) label2.ForeColor = Color.Red;(WE CHANGE THE FORECOLOR [LETTER COLOR] OF THE LABEL1)

DIVISION

int x; x = int.Parse(textBox1.Text); (change the text in text box 1 to numbers using INTEGERS) int y; y = int.Parse(textBox2.Text); (change the text in text box 2 to numbers using INTEGERS) (WE NOW HAVE CONVERTED TO NUMBERS THE VALUES WRITTEN BY THE USER AS TEXT) int z; z = x / y; (WE ASSIGN A NEW VARIABLE, Z AND USE THE FORMER VARIABLES ALREADY SET TWO ADD THEM) label3.Text = "The addition of " + x /" + "+ y + " is " + z; (WE CHANGE THE LABEL 1 TEXT SO IT SAYS THE RESULT) label3.ForeColor = Color.Green;(WE CHANGE THE FORECOLOR [LETTER COLOR] OF THE LABEL1)

MULTIPLICATION

int x; x = int.Parse(textBox1.Text); (change the text in text box 1 to numbers using INTEGERS) int y; y = int.Parse(textBox2.Text); (change the text in text box 2 to numbers using INTEGERS) (WE NOW HAVE CONVERTED TO NUMBERS THE VALUES WRITTEN BY THE USER AS TEXT) int z; z = x * y; (WE ASSIGN A NEW VARIABLE, Z AND USE THE FORMER VARIABLES ALREADY SET TWO ADD THEM) label4.Text = "The addition of " + x *" + "+ y + " is " + z; (WE CHANGE THE LABEL 1 TEXT SO IT SAYS THE RESULT) label4.ForeColor = Color.Veige;(WE CHANGE THE FORECOLOR [LETTER COLOR] OF THE LABEL1)

After each click, ONE value will change, depending on the button pressed. THe variables in x and y can be changed in ANY MOMENT ! And therefore, to get the new results using the NEW VALUES, it is neccesary to press again the button in order to have the new results.

__Download an example here.

__