Preview

Calculator Codes in Visual Basic

Satisfactory Essays
Open Document
Open Document
2742 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Calculator Codes in Visual Basic
Calculator
In this tutoral, Basic Calculator in VB.Net, we will look at creating a basic calculator. The calculator will have the following functionality:

* Addition * Subtraction * Division * Multiplication * Square Root * Exponents (Power Of) * Clear Entry * Clear All

There will be a 2nd tutorial that will cover some more advanced features such as

* Adding a number to memory * Removing a number from memory * Calculating with a number in memory * Entering numbers by typing

The first thing you need to do is create a new project in Visual Studio (or Visual Basic Express Edition if thats what you use). Once you have created your new project you need to create your user interface, your user interface should look like this:

Your user interface will consist of

* Buttons 0 through 9 * Buttons for

* Addition * Subtraction * Division * Multiplication * Exponents (x^) * Inverse (1/x) * Square Root (sqrt)

* Decimal * Equals * Backspace * CE (Clear Entry) * C (Clear All) * ReadOnly TextBox for input (Make sure TabStop is also set to False)

How you setup your user interface is up to you, but remember people are used to a calculator looking a certain way so you may wish to follow my example.

In this tutorial I will show you how to code two of the number buttons (since all 10 are the same except the zero button), how to code the calculations buttons, the clear buttons and the backspace buttons. Before writing any code you need to add the following variables to the top (Globals): 01 | 'variables to hold operands | 02 | Private valHolder1 As Double |

03 | Private valHolder2 As Double | 04 | 'Varible to hold temporary values |

05 | Private tmpValue As Double | 06 | 'True if "." is use else false |

07 | Private hasDecimal As Boolean | 08 | Private inputStatus As Boolean |

09 | Private clearText As Boolean | 10 | 'variable to hold Operater |

11 | Private

You May Also Find These Documents Helpful

Related Topics