Design a Basic Calculator with Basic math operators in Visual Basic 2010

First we will explain all the steps required to design and code the calculator and then we will be giving the over-all code for the calculator. You can find the over-all code at the end of this tutorial. Good Luck!

Steps to design the calculator

  1. Open a new Windows Forms Application form
  2. Drag and drop 2 labels, resize them on your form. The first label has to be big in size and the second one should be small. Position the labels nearby each other. These 2 labels will be the display screen of your calculator. The text on both the labels should be 0 or null. (As for calculators, the initial text on the display screen is 0.
  3. Drag and drop as many buttons you desire your calculator to have. You need buttons for the digits from 0 to 9, the clear button, the equal sign and the basic math operators.
  4. Change the text on the buttons correspondingly. Digits for the number buttons and signs or characters for others.
  5. Click on one of the buttons you have created. Go to the properties window and click on the events menu. Under the events menu find click option. Assign (Button_Click) to it, copy the event and paste it for every single digit button you have in your calculator. You can also paste this event for (.) button in case you have created one for calculating decimal numbers too.
    * (Button_Click) event is assigned to all the buttons so that all the buttons may work with one piece of code written for (Button_Click) event.
  6. Just like step number 5, click on one of the arithmetic operation buttons on your calculator and from the event menu, find click option and assign (Arithmetic_Function) to it and copy this even for all the arithmetic operation buttons you have created.
  7. Double click on your form. Moreover; you can also modify your form, change its name to whatever you want and give it a proper design. After you double click on your form, assign some variables which may store the first number, the second number, the answer and the operator.
  8. Get back to the design window. Double click on one of the digits you have created and type the code below.

    9. Head back to the design window and double click on the clear button you have created and type the code below.

    10. From the design window, double click on one of the arithmetic operation button you have created and type the code below.

    11. Get back to the design window and double click on the equal (=) sign button. Type the code below for the button.

    12. Now that you have designed and coded all the buttons on your calculator, you can go on and run your project.

Your calculator may look something like this:

Calculator View

See Also: [button link=”” size=”default” icon=”fa-ellipsis-v” side=”left” target=”” color=”0f1ab7″ textcolor=”ffffff”]Function Procedure & Call by Value in Visual Basic 2010[/button]

The Over-all Code for the Basic Calculator:


When you enter the first number and press any operator button, they both move from the first label to the second label you have created in your calculator. Then you can enter the second number in the first label. Check below:


Once you press (=) sign button, the second label turns 0 and the answer to the operation is displayed in the first label. Check below:


You can simply modify your calculator as you want. All the best of Luck!

Leave a Reply