Visual Basic Code Of Simple Calculator

StudioCode

Early in my Software Engineering studies, I was convinced by some colleagues that the future for ASP.Net is very bleak so I started to concentrate on learning other languages such as PHP, Java, CSS for styling simple web pages & Javascript. Although I did not cut off myself from C# because that was my primary programming language to develop desktop apps, specially my semester projects but I never tried to concentrate on learning ASP until now. Now I am in my final year of Software Engineering & soon I’ll graduate so I started to search for applying different companies & Software Houses. One thing I noticed is that most of these jobs require candidates to have knowledge of ASP.Net & particularly MVC framework. Therefore I started learning ASP.Net from the basics again. Here is my first try at creating a Simple Calculator in ASP.Net with background code in C#.

Calculator.aspx Page

ASP.Net is a web based technology so its presentation is on browser & the browser only understand HTML objects. So first we create a simple page with each buttons we need on our Calculator. Here is the source code for Aspx page.

Download our Free eBook : Learning C# by Developing Unity 3D Games.

Why is it simple calculator? It has only the basic functions of a calculator such as addition, subtraction, multiplication,division and 2 others. First Entered number is taken to the first variable a. Then select and operator, enter the second number.

Calculator.css Styling

Since Calculator.aspx is a web page written basically in HTML, we need to style it with Cascading Style Sheets (CSS). Did you noticed that there are ID attributes in each object in Calculator.aspx page. We use these ID’s to style these objects accordingly. Here is the Calculator.css file that will style the object on the webpage. Note that this is not used to calculate anything, It is just for stylish presentation of our HTML page.

Visual Basic Tip Calculator

Read : What really is .Net Framework, its Uses & Benefits to Developers?
Visual basic simple calculator code pdf
  • Code provided in the picture should be simple to understand. Dim is the keyword used to initialize a variable, and new allocates memory. Anything you type in the textbox is of type string by default.
  • A simple scientific calculator perform basic math calculations such as add, subtract, multiply, squareroot, percentage etc and also used for trigonometric calculation such as tangent, square, sine, cosine, absolute value etc. Here is the code snippets to design a simple scientific calculator in Visual Basic. Scientific Calculator.

Code Behind File of Calculator

ASP.Net applications are developed in Visual C# & Visual Basic programming languages. We will be using C# for our development. Remember when we drop any control on windows form & double click on it, It creates its event click. Similarly when you use Standard ASP control on your web page in ASP.Net project & double click on it, It automatically creates its event handler in its Code Behind file. In our case the code behind file is Calculator.aspx.cs. Any code written in this file will actually run on our server. Here is the source code.

Calculate Class

Visual Basic Simple Calculator Code Pdf

I created a simple class just like we create in Console App or Windows Forms Apps. I named it Calculate.cs. This class contains my methods for Addition, Subtraction, Multiplication, Division & Percentage. I am calling these methods in my code behind file Calculator.aspx.cs. Here is the source code for this file.

Output ASP.Net Simple Calculator

Here is the video output of this Simple Calculator in ASP.Net that I develop.

Learn : Using Webcam Control in C# Windows Form Application.

Download Calculator in ASP.Net

I am also attaching actual project file here, So if someone want to have look on working app, Download the file from below. It is in Visual Studio 2012 file format & the size of project file is ~50 KB.

You can ask me any questions related to this or any other programming issue on Facebook.