In this tutorial we will create a simple calculator to Add/Subtract/Multiply and Divide two numbers and show a simple message box result.

Similar documents
To enter the number in decimals Label 1 To show total. Text:...

Learning VB.Net. Tutorial 10 Collections

First start a new Windows Form Application from C# and name it Interest Calculator. We need 3 text boxes. 4 labels. 1 button

Objectives. After completing this topic, the students will: Understand of the concept of polymorphism Know on How to implement 2 types of polymorphism

Learning VB.Net. Tutorial 17 Classes

VISUAL BASIC II CC111 INTRODUCTION TO COMPUTERS

FOR 240 Homework Assignment 4 Using DBGridView and Other VB Controls to Manipulate Database Introduction to Computing in Natural Resources

Mr.Khaled Anwar ( )

Developing Student Programming and Problem-Solving Skills With Visual Basic

Programming with Visual Studio Higher (v. 2013)

Year 12 : Visual Basic Tutorial.

Revision for Final Examination (Second Semester) Grade 9

IMS1906: Business Software Fundamentals Tutorial exercises Week 5: Variables and Constants

Unit 4. Lesson 4.1. Managing Data. Data types. Introduction. Data type. Visual Basic 2008 Data types

Computing Science Unit 1

S.2 Computer Literacy Question-Answer Book

Else. End If End Sub End Class. PDF created with pdffactory trial version

A Complete Tutorial for Beginners LIEW VOON KIONG

These are the four symbols which we will use in the picture box to represent the sum instructions.

DO NOT COPY AMIT PHOTOSTUDIO

Tutorial 03 understanding controls : buttons, text boxes

Check out the demo video of this application so you know what you will be making in this tutorial.

Visual Basic: Opdracht Structuur

Learning VB.Net. Tutorial 15 Structures

VARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals

VISUAL BASIC 2005 EXPRESS: NOW PLAYING

Unit 7. Lesson 7.1. Loop. For Next Statements. Introduction. Loop

QUALITATIVE INDICES IN FAULT TOLERANCE FOR SOFTWARE RELIABILITY

Savoy ActiveX Control User Guide

Learning VB.Net. Tutorial 19 Classes and Inheritance

Running the Altair SIMH from.net programs

Repetition Structures

Decision Structures. Start. Do I have a test in morning? Study for test. Watch TV tonight. Stop

To get started with Visual Basic 2005, I recommend that you jump right in

DEVELOPING OBJECT ORIENTED APPLICATIONS

Lab 3 The High-Low Game

VB FUNCTIONS AND OPERATORS

Learning Log Title: CHAPTER 2: FRACTIONS AND INTEGER ADDITION. Date: Lesson: Chapter 2: Fractions and Integer Addition

Getting Started with Visual Basic.NET

Lab 4: Adding a Windows User-Interface

Unit 3. Lesson Designing User Interface-2. TreeView Control. TreeView Contol

Disclaimer. Trademarks. Liability

The Filter Property Selecting a File The Save Menu The SaveFileDialog Control The Edit Menu The Copy Menu...

COPYRIGHTED MATERIAL. Visual Basic: The Language. Part 1

Unit: Rational Number Lesson 3.1: What is a Rational Number? Objectives: Students will compare and order rational numbers.

GUI Design and Event- Driven Programming

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Label1.Text = Label1.

Student Success Center Arithmetic Study Guide for the ACCUPLACER (CPT)

Rational number operations can often be simplified by converting mixed numbers to improper fractions Add EXAMPLE:

フラクタル 1 ( ジュリア集合 ) 解説 : ジュリア集合 ( 自己平方フラクタル ) 入力パラメータの例 ( 小さな数値の変化で模様が大きく変化します. Ar や Ai の数値を少しずつ変化させて描画する. ) プログラムコード. 2010, AGU, M.

UNIT 2 USING VB TO EXPAND OUR KNOWLEDGE OF PROGRAMMING

Introduction. Getting Started with Visual Basic Steps:-

Fractions. Dividing the numerator and denominator by the highest common element (or number) in them, we get the fraction in its lowest form.

PROGRAMMING ASSIGNMENT: MOVIE QUIZ

C4.3, 4 Lab: Conditionals - Select Statement and Additional Input Controls Solutions

Disclaimer. Trademarks. Liability

ก Microsoft Visual Studio 2008

DRAWING AND MOVING IMAGES

Only to be used for arranged hours. Order of Operations

Topic 3: Fractions. Topic 1 Integers. Topic 2 Decimals. Topic 3 Fractions. Topic 4 Ratios. Topic 5 Percentages. Topic 6 Algebra

!"!!!"!!"!! = 10!!!!!(!!) = 10! = 1,000,000

超音波モータ制御プログラムの作成 (v1.2.1)

Chapter 1 Operations With Numbers

Form Connection. Imports System Imports System.Threading Imports System.IO.Ports Imports System.ComponentModel

"!#... )*! "!# )+, -./ 01 $

: CREATING WEB BASED APPLICATIONS FOR INSTRUMENT DATA TRANSFER USING VISUAL STUDIO.NET

Classes in C# namespace classtest { public class myclass { public myclass() { } } }

Name: Date: Review Packet: Unit 1 The Number System

Formatting & Style Examples

Learning Log Title: CHAPTER 3: PORTIONS AND INTEGERS. Date: Lesson: Chapter 3: Portions and Integers

โปรแกรมช วยทดสอบหม อแปลงกระแส

MATH REVIEW SUPPLEMENT. For The ARITHMETIC SECTION. of the. ACCUPLACER Entry Assessment

Pre-Algebra Notes Unit One: Rational Numbers and Decimal Expansions

Visual Basic 2008 Anne Boehm

Learning VB.Net. Tutorial 11 Functions

Section 7 The BASIC Language II

ALGEBRA I Summer Packet

Apéndice E Código de software de ayuda en Visual Basic 2005 Public Class Form1

Create a Login System in Visual Basic. Creating a login system. Start a new visual basic Windows Forms application project. Call it Login System

Exponential Notation

Excerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.

MATFOR In Visual Basic

Unit 4 Advanced Features of VB.Net

Microsoft Office Excel Use Excel s functions. Tutorial 2 Working With Formulas and Functions

Rational Number is a number that can be written as a quotient of two integers. DECIMALS are special fractions whose denominators are powers of 10.

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy.

Lesson 1: THE DECIMAL SYSTEM

1. Create your First VB.Net Program Hello World

CALIFORNIA STATE UNIVERSITY, SACRAMENTO College of Business Administration. MIS 15 Introduction to Business Programming. Programming Assignment 3 (P3)

Solving Equations with Inverse Operations

Rational numbers as decimals and as integer fractions

2.Simplification & Approximation

Units 0 to 4 Groovy: Introduction upto Arrays Revision Guide

Section 2.3 Rational Numbers. A rational number is a number that may be written in the form a b. for any integer a and any nonzero integer b.

On the Structure and Sizes of Infinitely Large Sets of Numbers

EE 301 Signals & Systems I MATLAB Tutorial with Questions

Fifth Grade Report Card Rubric 1 Exceeding 2 Meeting 3 Developing 4 Area of Concern

Code: Week 13. Write a Program to perform Money Conversion. Public Class Form1

MATH LEVEL 2 LESSON PLAN 5 DECIMAL FRACTIONS Copyright Vinay Agarwala, Checked: 1/22/18

Any Integer Can Be Written as a Fraction

Transcription:

Simple Calculator In this tutorial we will create a simple calculator to Add/Subtract/Multiply and Divide two numbers and show a simple message box result. Let s get started First create a new Visual Basic Windows Form Project Lets call it simplecalcvb. From the tool box we need the following 1. 2 text boxes 2. 4 buttons 3. 1 label This is the view of the Form now Arrange your components so it looks like this

Now let s change the text property in each of these components Label1 -> Change text to Simple VB Calculator Button1 -> change text to + Button2 -> change text to Button3 -> change text to * Button4 -> change text to / Each button to a calculation for us and then return a result on screen. Lets get started with the code now. First of all right click on the form and Click on Show Code

This is what the code view looks like at the moment. We don t have any code to run except the Form 1 class there. All the code for this program will go inside that class. We need to create two different variables first. These variables will be used to store the numbers from each text box. I know you are already thinking about integers; well you are not wrong we do a number variable however we want one that can hold decimal numbers and not just whole numbers. EndClass Integers hold numbers such as 1, 2, 30, 45, 67542 its all whole numbers but since we have a division button on the mix we will need to a simple division calculation and with an integer we cannot do that. So double variables can hold numbers such as 1.2, 12.221211 and so on. Now go back to the design view and double click on the plus button. PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

EndClass Once you double clicked on the button, visual studio will automatically add the line of code in your project. These lines are now linked to the button 1 which is out plus sign. Now lets add the following code inside this function This line is calling the numa variable we created earlier and storing some value inside it. Now since the user will be using those text boxes to enter the numbers they want to calculate they will be stored as Text or Strings. Now we cannot do maths with strings because well you know why. Anyhow since our numa variable is a double we will have to convert them to a double type of data and store them inside it. Hence the line Convert.ToDouble() Inside the brackets we can put in our target which we want to convert in this instance it s the Textbox1 and we are looking for the value which the user has put inside it that s the text portion of Textbox1 hence its Textbox1.Text. Doing the same thing as above except with numb and TextBox2.Text Now then how can we view our result to the user? We will use a text box. Lets try this MessageBox.Show(numA+numB) since its adding the values together That worked. Now lets go back and double click on the Minus, Multiply and Divide button and add the following code PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'this is the plus button function MessageBox.Show(numA + numb) ' notice the plus symbol

PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'this is the minus button function MessageBox.Show(numA - numb) 'notice the minus symbol PrivateSub Button3_Click(ByVal sender As System.Object, By Val e As System.EventArgs) Handles Button3.Click 'this is the multiply button function MessageBox.Show(numA * numb) 'notice the multiply symbol PrivateSub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click 'this is the divide button function MessageBox.Show(numA / numb) 'notice the divide symbol EndClass Notice where the symbols changed for the calculations, it s inside the message boxes. MessageBox.Show(numA + numb) MessageBox.Show(numA - numb) MessageBox.Show(numA * numb) MessageBox.Show(numA / numb) Here are the results See the decimal is working in the end. Now go make something else. MOOOO