Creating a simple calculator in Visual Basic 2015

Asked By 30 points N/A Posted on -
qa-featured

I am just learning new ways to Visual Basic 2015. Can you show me the tools that I need to use how to achieve this simple program? What are the arithmetic operators that I need to use? Can you show me how to make use of command button in this program? Can I change also color for command buttons? How can I animate my window? A simple animation will do. Please provide me instructions by detail. Thank you very much and have a nice day!

SHARE
Answered By 0 points N/A #174912

Creating a simple calculator in Visual Basic 2015

qa-featured

Hello Jessica!

In this program I will use most of the arithmetic operators that we can use in VB. You just need few controls to make this work. You just need the following controls in your form.

1. 3 Label controls – “1st Value:”, “2nd Value:”, “Answer” for the name properties that is similar above.

2. 3 text boxes – str1 for the name property of the first text box, str2 for the second, and strans for the last box.

3. 6 command buttons – name it according to the operator that you will use for the command buttons like, “cmdadd”, cmdsubtract, etc.

The codes should look like this.

For cmdadd_click() type this:

strans.Text = Val(str1.Text) + Val(str2.Text)

For cmdsubtract_click():

strans.Text = Val(str1.Text) – Val(str2.Text)

For cmddivide_click()

strans.Text = Val(str1.Text) / Val(str2.Text)

For cmdmultiply_click()

strans.Text = Val(str1.Text) * Val(str2.Text)

For cmdmod_click()

strans.Text = Val(str1.Text) MOD Val(str2.Text)

for cmdexponent_click()

strans.Text = Val(str1.Text) ^ Val(str2.Text)

Notice that we used the “Val” to get the numerical value of the string that will be placed in the text boxes.

Login/Register to Answer

Related Questions