Visual Basic Calculator
Visual Basic Calculator
Table of Contents
Step 8: Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
http://www.instructables.com/id/Visual-Basic-Calculator/
Intro: Visual Basic Calculator
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 provide the code for
our calculator. Our instructions will be set up so that the user creates one button for addition and writes code for it. From this the user will be able to add more
(subtraction, division, etc.) on to their program if desired. Watch video for demonstration.
Programming is becoming more important and it is beneficial to have some understanding of how to code. This instruction will serve to both teach a basic understanding
of code as well as teach the logic needed to code. Our instructions are different from others on Instructables.com because there is no calculator made in Visual Basic.
Our target readers will be anyone who wants to learn how to program. The instructions will be set up to where someone who has never programmed before will be able
to complete the project.
Important Note:
These instructions assume you already have Visual Studio installed and open.
Your User Interface (where toolbars are placed) my look different from the instructions. These instructions will not address how to make changes to
the User Interface. Making your User Interface look like the provided pictures is not necessary, but will be helpful.
If you make a mistake, i.e. double click on an object by accident, move to the last step (Troubleshooting) for common mistakes and fixes.
Step 5: Set the save location. Desktop is recommended as it is the easiest to find.
Step 6: Click OK
Step 7: If needed, click on the view tab then select the Toolbox, Property, and Solutions Explorer window
http://www.instructables.com/id/Visual-Basic-Calculator/
Step 2: Design the Graphical User Interface (GUI)
Helpful Tip:
On the properties toolbox set in alphabetical order. Refer to the picture of the Toolbox, green circle.
Step 2: In the properties window, under the Text property, type Simple Calculator
Step 3: In the properties window, under the StartPosition property, select CenterScreen
Step 5: Click and drag a label from the Toolbox to the form
Step 6: While the label is selected, in the properties window, under the Text property, type Simple Calculator. Note: Since this label is the main text describing the text,
you can change the size and boldness of the text under the Font property in the properties window but is not required for this project
Step 7: Proceed to do this for the following labels (5) and place them accordingly. Name them: Operators, Operation, Operand 1, Operand 2, and Result (See picture)
Note: Objects can either be dragged or double clicked to be placed onto the GUI
Step 10: While the button is selected, in the properties window, under the Name property, enter btnAdd
Step 12: Click and drag a TextBox from the ToolBox beside the “Operand 1” label (See picture)
Step 13: While the TextBox is selected, in the properties window, under the Name property, enter txtOperand1
Step 14: Repeat Step 12 but place the second TextBox beside the “Operand 2” label (See picture)
Step 16: Click and drag a label between the two text boxes (See picture)
Step 17: While the label is selected, in the properties window, under the Name property, enter lblOperator
Step 19: Under 9the AutoSize property, select False. Note: This lets you resize the label at your desire
Step 21: Click and drag another label beside the “Result” label
Step 24: Click and drag a button from the Toolbox below the “Result” label (See picture)
Step 25: While button is selected, in the properties window, under the Name property, enter btnClear
Step 26: Change the text property for the Clear button to Clear
Step 27: Click and drag a button from the Toolbox beside the Clear button (See picture)
http://www.instructables.com/id/Visual-Basic-Calculator/
Step 28: While button is selected, in the properties window, under the Name property, enter btnExit
Step 29: Change the text property for the Clear button to Exit
Step 30: Enter the following code by double clicking on each button to open the code window:
http://www.instructables.com/id/Visual-Basic-Calculator/
http://www.instructables.com/id/Visual-Basic-Calculator/
Step 3: Coding the Add Button
Goal: Add to numbers that the user inputs into the text boxes
Code Explanation
Code Explanation:
Clear()Function clears a text box. This function can only be used on a text box
Label boxes must be cleared by setting the .Text property to nothing
Focus() Function sets the cursor to the text box
Note: While the program is running, you can test to see if your program is working properly.
Click either the exit button or the red “X” on the program when done.
Step 8: Troubleshooting
When you enter improper code, a blue squiggly line will appear below the word(s). This is an error and the program will not run. If you see a blue line under a
piece of your code, hover over it with your mouse and it should give you an explanation of the error. From there you can research the error online to find more
information.
If you double click on an object, i.e. a label that you are not going to code, you can either delete the code you just created or leave it there.
If you are having trouble like errors or if you forgot a keyword, please see Microsoft’s Visual Basic help site ( https://msdn.microsoft.com/en-
us/library/2x7h1hfk.aspx)
Another good reference to look at is the textbook, Step into Programming with Visual Basic.Net, 4th Edition, by Guity Ravai and Ibrahim M. Baggili.
If you accidentally double click a tool while moving it from the toolbox Visual Studio will automatically take you to the coding tab, and create a section for coding
the element you double clicked. It is recommended to delete this section of code that was accidentally created, as it is junk code that does nothing. To return back
to the form design tab, simply click the Form Design tab
http://www.instructables.com/id/Visual-Basic-Calculator/
Related Instructables
Creating a
Program in 'Riding' or
Visual Basic: VBS Date 'Running' on
Communicating Create a simple Web Browser by Calculator App Creating Your
google map
with arduino delay in your VB munchman First Program In
by ezman (Photos) by
micro controller Visual Basics Visual Basic by
zhangpeisheng
and computer Program by munchman
by usb with a vb eglass1
program by
eglass1
Advertisements
Comments
1 comments Add Comment
http://www.instructables.com/id/Visual-Basic-Calculator/