How To Make A Calculator Program In Visual Basic 2008
First I want to say thank you for taking the time to read this tutorial. If your a beginner this will help you a lot in the basics of visual basic and also create a fun little application. In this tutorial we will be creating a calculator in visual basic.
Basic Calculator Tutorial in Visual Basic. NETThis tutorial will show you how to make a basic calculator in visual basic. Source Code for the calculator project is. We are going to create a “first program” that will be written in Visual Basic (VB). Our project will be a basic calculator that will teach the logic and.
For this calculator we will use radio buttons, text boxes and buttons to create a fully functional calculator. Hopefully this will intrigue you into making other fun little applications, for me, the better you make your projects the better I feel mentally and physically. Open Microsoft Visual Studio. Click File New Project. In installed templates, click on Other Languages Visual Basic Windows. Click on Windows Forms Application, name the file Calculator in Visual Basic and click OK. You will see a blank form like this: We will add radio buttons, text boxes and buttons to the form to create the design of the calculator.
Keep in mind you can design your calculator the way you want, it does not have to be identical to mine, the functionality will be the same regardless of the calculator’s design. In the Toolbox panel, click and drag a RadioButton onto the form.
Copy the radio button and paste it onto the form three more times, until there is a total of four radio buttons on the form. In the properties window of RadioButton1, change it’s text to Add and change it’s name to addRb. In the properties window of RadioButton2, change it’s text to Subtract and change it’s name to subtractRb. In the properties window of RadioButton3, change it’s text to Multiply and change it’s name to multiplyRb. In the properties window of RadioButton4, change it’s text to Divide and change it’s name to divideRb. In the Toolbox panel, click and drag a TextBox onto the form. Copy the text box and paste it onto the form.
You should have a total of two text boxes on the form. In the properties window of TextBox1, rename it userInput1TextBox. In the properties window to TextBox2, rename it userInput2TextBox. Web development price quote template.
In the Toolbox panel, click and drag a Button control onto the form. Copy the button and paste it onto the form. You should have a total of two buttons on the form. In the properties window of the Button1, change it’s text to Calculate and it’s name to calculateBtn. In the properties window of Button2, change it’s text to Clear and it’s name to clearBtn. 8.In the Toolbox panel, click and drag a Label onto the form.
Copy the label and paste it onto the form. You should have a total of two labels on the form. In the properties window of Label1, change it’s name to symbolLbl and delete it’s text so it is blank.
In the properties window of Label2, change it’s name to answerLbl and delete it’s text so it is blank. We will use symbolLbl for the operation symbol, so place it between the text boxes where it makes most sense. The answerLbl will be used to output the answer, so place it where it makes most sense. This is what my design looks like, there is one label in between the two text boxes and one to the right of the calculate button. Remember that you can design it any way you’d like.
This is where we actually do the coding that does the calculating. We will make great use of the If Else statement to make sure which radio button is checked and to put code in accordingly. Double click on the Calculate button to take you to Form1.vb. You will see a calculateBtnClick method, inside of this method is where we will enter the code. Although this is a basic calculator, I took the liberty to have a message box appear when a number is not entered or no operation is selected. Also we all know that when a zero is involved when multiplying or dividing, the answer will always be zero.
In the case that a denominator is zero I’ve programmed the application to read “Cannot Divide by Zero” because you cannot. The rest of the code is just calculating the user inputs depending on which radio button is selected. End Sub Now that we have the clear button finished, we still have to code the symbolLbl to change symbols according to which operation is selected.
Switch to Form1.vb Design and double click on the Add radio button. We want to tell the application to change symbolLbl to the correct operation symbol each time a radio button is selected. So to do that we will set the test of symbolLbl to “+” and the text of answerLbl to “”(nothing). We will do the same for the other radio buttons, just change the symbolLbl according to which operation is selected.

End Class Run the application. Test the application and try to break it. It should be fully functional. Try entering only one number and don’t select an operation to see if the message boxes appear each time. Use the clear button to clear everything from the calculator and use the calculate button to calculate the and output the correct answer.
How To Make A Calculator Program In Notepad
Everything works. This was a fun experiment, you learned a little bit about If Else statements but also about radio buttons, text boxes and buttons and you have a calculator to use whenever your in need of one!