calculator program

16
Calculator Program Explained by Arafa Hamed

Upload: briar

Post on 06-Jan-2016

35 views

Category:

Documents


0 download

DESCRIPTION

Calculator Program. Explained by Arafa Hamed. First Designing The Interface. Ask yourself how many places are there that will be used to input numbers? The answer is two places for first number and second number. Which object enables user to input data? The answer is Textbox control. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Calculator Program

Calculator Program

Explained byArafa Hamed

Page 2: Calculator Program

First Designing The Interface

•Ask yourself how many places are there that will be used to input

numbers?

•The answer is two places for first number and second number.

•Which object enables user to input data?

•The answer is Textbox control.

Page 3: Calculator Program

•What is the data that will be displayed on your calculator project?

•There are many data will be displayed such as:

•Number 1•Number 2 •Result•So you must use the object which

displays fixed data that can not be changed by user this control is:

• Label control .

Page 4: Calculator Program

•Ask yourself How many mathematical operations will be done

by your calculator and how will execute them?

•The answer is many mathematical operations and to execute them you must build Button which is used to

execute your codes.

• After all the previous answers. You can design your project as

follow:

Page 5: Calculator Program
Page 6: Calculator Program

After finishing the designing such as shown on the previous step:

•Think with me after the user inputs the numbers how can the computer

receive them to process them•The answer is we have to build

Variables * The variable is a reserved place in

the memory , its contents can be changed during program running .

Page 7: Calculator Program

•To build a variable in the code window double click on the button

object then use this rule for building variables:

•Dim VariableName As Data type•Another question : How many

variables do we need and why?

•The answer is 3 variables 2 for numbers and one for result . Think

which kind of data will be used ?

•The answer is Decimal.

Page 8: Calculator Program

•After that you can build the variables as shown:

Notes : if you use ( integer, long, short) data types computer will ignore the fraction but if you use ( decimal, double, single) data types computer will process the fraction.

Page 9: Calculator Program

•Let’s think how can the variables get the data from the TextBox object and

store them on the memory till the processing happen on it.

•The answer is so easy by using:•Assignment Statement •Number1 = Textbox1.text•Number2 = Textbox2.text•Result = Number1 + Number2•As displayed in the following screen:

Page 10: Calculator Program
Page 11: Calculator Program

Dear students may I ask a question?

•Is that possible the user input letters instead of numbers onto the TextBox?

•The answer is ……………… yes. •How can you prevent that happen????? •The answer is by using ( try –

catch )which is used to discover the errors during the running of program as

displayed in the following screen:

Page 12: Calculator Program

*** If the user input letters instead of numbers an error message will appear as shown on the following screen:

*** By the way we use MsgBox to display error messages. We type it as shown on the previous code window

Page 13: Calculator Program
Page 14: Calculator Program

•The last question is How the contents of Result variable which is found on

the memory will be displayed on the screen after the computer makes

processing on the numbers?

•The answer by using this code:

•Label4.text = Result•as shown on the following :

•Notes we use Label to display the result so, no one can change this result.

Page 15: Calculator Program
Page 16: Calculator Program

At the last type the codes into each button

•Encapsulation means to hide your codes and no one can reach them

without permission• This is what you have done when

type the codes into the object.