SlideShare a Scribd company logo
aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf
Variables, Constants and Calculations Chapter 3 McGraw-Hill © 2006 The McGraw-Hill Companies, Inc. All rights reserved.
Objectives  (1 of 2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Objectives  (2 of 2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Data - Variables and Constants  (1 of 2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Data - Variables and Constants  (2 of 2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Data Types   4 Any type of data Object Varies Alphanumeric data: letters, digits, and other characters String 8 Larger whole numbers Long 4 Whole numbers in the range -2,147,483,648 to +2,147,483,647 Integer 2 Small integer in the range -32,768 to 32,767 Short 8 Double precision floating-point numbers with 14 digits of accuracy Double 4 Single precision floating-point numbers with six digits of accuracy Single 16 Decimal fractions, such as dollars/cents Decimal 8 1/1/0001 through 12/31/9999 Date 2 Single Unicode character Clear 1 0 to 255, binary data Byte 2 True or False value Boolean Storage Size in bytes Use For Data Type
Naming Variables and Constants ,[object Object],[object Object],[object Object],[object Object],[object Object]
Constants ,[object Object],[object Object],[object Object],[object Object],[object Object],Const COMPANY_ADDRESS_String As String = "101 S. Main Street" Const SALES_TAX_RATE_Decimal As Decimal = .08D
Assigning Values to Constants ,[object Object],Single – 101.25F F Single S Short Long – 134257987L L Long Integer – 12345678I I Integer Double – 52875.8R R Double Decimal – 850.50D D Decimal
Declaring Variables ,[object Object],[object Object],[object Object],[object Object],[object Object]
Declaration Statement Examples As Decimal Private priceDecimal As Decimal Dim priceDecimal As Single Dim temperatureSingle As Integer Private totalSoldInteger As Integer As String Dim customerName Strging As String
Scope and Lifetime of Variables  (1 of 2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Module Level Variable Declaration Example Code module-level declarations in the Declaration section at the top of the code
Calculations ,[object Object],[object Object],[object Object],[object Object],[object Object]
Converting Strings to a Numeric Data Type ,[object Object],[object Object],[object Object],[object Object]
Converting to String ,[object Object],[object Object]
Conversion Methods ,[object Object],[object Object],[object Object],[object Object]
Conversion Examples quantityInteger  =Integer.Parse(quantityTextBox.Text) priceDecimal   =Decimal.Parse(priceTextBox.Text) wholeNumberInteger  =Integer.Parse(digitString) resultLabel.Text   =resultDecimal.ToString( ) countTextBox.Text  =countInteger.ToString( ) idString   =idInteger.ToString( )
Arithmetic Operations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Order of Operations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Evaluation of Expression ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Mathematical Examples ,[object Object],3+4*2 = 11 Multiply then add (3+4)*2 = 14 Parentheses control: add then multiply 8/4*2 = 4 Same level, left to right: divide then multiply
Using Calculations in Code ,[object Object],[object Object],[object Object],‘ Accumulate a total. TotalSalesDecimal += salesDecimal
Option Explicit and Option Strict ,[object Object],[object Object],[object Object],[object Object],[object Object]
Converting Between Numeric Data Types ,[object Object],[object Object],[object Object],[object Object],[object Object]
Performing Calculations with  Unlike Data Types ,[object Object],[object Object],[object Object]
Rounding Numbers ,[object Object],[object Object],[object Object],2 0 2.5 2 0 1.5 1.44 2 1,455 1.46 2 1,455 Results Number of Decimal Positions Decimal Value to Round
Formatting Data for Display ,[object Object],[object Object],[object Object],[object Object],[object Object],Me.displayTextBox.Text = numberInteger.ToString()
Using Format Specifier Codes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Format Specifier Codes Percent P or p Digits D or d Number N or n Fixed-point F or f Currency C or c Name Format Specifier Codes
Format Specifier Code Examples ($10.00) "C" -10 valueInteger 8% "P0" 0.075 rateDecimal 7.500% "P3" 0.075 rateDecimal 7.50% "P" 0.075 rateDecimal 000123 "D6" 123 pinInteger 1,126 "N0" 1125.6744 totalDecimal $1,125.67 "C" 1125.6744 totalDecimal Output Code Value Variable
Date Specifier Code ,[object Object],[object Object]
Handling Exceptions ,[object Object],[object Object],[object Object],[object Object]
Try/Catch Blocks ,[object Object],[object Object],[object Object]
Try Block - General Form Try statements that may cause error Catch  [VariableName As ExceptionType] statements for action when an exception occurs [ Finally statements that always execute before exit of Try block] End Try
Try Block - Example Catches Any Exception Try quantityInteger = Integer.Parse(quantityTextBox.Text) Me.quantityLabel.Text = quantityInteger.ToString( ) Catch Me.messageLabel.Text = "Error in input data." End Try
Try Block - Example Catches Specific Exception ,[object Object],Catch   theException As FormatException messageLabel.Text="Error in input data." End Try
Common Exception Classes Each exception is an instance of the Exception class. The properties of this class allow you to determine the code location of the error, the type of error and cause.
Try Block - Example Handling Multiple Exceptions Try '   Statements that may cause errors. Catch   theException As FormatException '  Statements for nonnumeric data. Catch   theException As ArithmeticException '  Statements for calculation problem. Catch   theException As Exception '  Statements for any other exception. End Try
MessageBox Object  (1 of 2) ,[object Object],[object Object],[object Object],[object Object],[object Object],MessageBox.Show (TextMessage, TitlebarText, _   MessageBoxButtons, MesssageBoxIcon)
MessageBox Object   (2 of 2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Overloaded Methods ,[object Object],[object Object],[object Object],[object Object]
Testing Multiple Fields ,[object Object],[object Object],[object Object],[object Object]
Counting and Accumulating Sums ,[object Object],[object Object],[object Object],[object Object],discountedPriceSumDecimal += discountedPriceDecimal ,[object Object],[object Object],[object Object]

More Related Content

What's hot

Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
Vince Vo
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)
rnkhan
 
Introduction
IntroductionIntroduction
Introduction
Komal Pardeshi
 
Data types in java | What is Datatypes in Java | Learning with RD | Created b...
Data types in java | What is Datatypes in Java | Learning with RD | Created b...Data types in java | What is Datatypes in Java | Learning with RD | Created b...
Data types in java | What is Datatypes in Java | Learning with RD | Created b...
rahuldaredia21
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
Kamal Acharya
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
Programming
ProgrammingProgramming
Programming
Sean Chia
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
Mohammed Khan
 
introductory concepts
introductory conceptsintroductory concepts
introductory concepts
Walepak Ubi
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
Qazi Shahzad Ali
 
Datatypes
DatatypesDatatypes
Datatypes
ZTE Nepal
 
Computer
ComputerComputer
Computer
Hanaa Ahmed
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
Suchit Patel
 
Chapter 3.4
Chapter 3.4Chapter 3.4
Chapter 3.4
sotlsoc
 
Lecture02(constants, variable & data types)
Lecture02(constants, variable & data types)Lecture02(constants, variable & data types)
Lecture02(constants, variable & data types)
Dhaka University of Engineering & Technology(DUET)
 
Chapter 03
Chapter 03Chapter 03
Chapter 03
Rooney Joh
 
Constants and variables in c programming
Constants and variables in c programmingConstants and variables in c programming
Constants and variables in c programming
Chitrank Dixit
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
K Durga Prasad
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
nikshaikh786
 
Decisions
DecisionsDecisions
Decisions
nicky_walters
 

What's hot (20)

Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)
 
Introduction
IntroductionIntroduction
Introduction
 
Data types in java | What is Datatypes in Java | Learning with RD | Created b...
Data types in java | What is Datatypes in Java | Learning with RD | Created b...Data types in java | What is Datatypes in Java | Learning with RD | Created b...
Data types in java | What is Datatypes in Java | Learning with RD | Created b...
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Programming
ProgrammingProgramming
Programming
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
introductory concepts
introductory conceptsintroductory concepts
introductory concepts
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Datatypes
DatatypesDatatypes
Datatypes
 
Computer
ComputerComputer
Computer
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
 
Chapter 3.4
Chapter 3.4Chapter 3.4
Chapter 3.4
 
Lecture02(constants, variable & data types)
Lecture02(constants, variable & data types)Lecture02(constants, variable & data types)
Lecture02(constants, variable & data types)
 
Chapter 03
Chapter 03Chapter 03
Chapter 03
 
Constants and variables in c programming
Constants and variables in c programmingConstants and variables in c programming
Constants and variables in c programming
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 
Decisions
DecisionsDecisions
Decisions
 

Similar to Chapter 03

Unit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingUnit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programming
Abha Damani
 
Visual Basics for Application
Visual Basics for Application Visual Basics for Application
Visual Basics for Application
Raghu nath
 
Visual Basic Fundamentals
Visual Basic FundamentalsVisual Basic Fundamentals
Visual Basic Fundamentals
DivyaR219113
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2pp
J. C.
 
Variables&DataTypes.pptx
Variables&DataTypes.pptxVariables&DataTypes.pptx
Variables&DataTypes.pptx
sanjanaMudduluru1
 
Lesson 4 Basic Programming Constructs.pptx
Lesson 4 Basic Programming Constructs.pptxLesson 4 Basic Programming Constructs.pptx
Lesson 4 Basic Programming Constructs.pptx
John Burca
 
CIS160 final review
CIS160 final reviewCIS160 final review
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
Ali Raza Jilani
 
C# basics
C# basicsC# basics
C# basics
sagaroceanic11
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
PriyadarshiniS28
 
C++ programming
C++ programmingC++ programming
C++ programming
Anshul Mahale
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
Tareq Hasan
 
C language
C languageC language
Pengaturcaraan asas
Pengaturcaraan asasPengaturcaraan asas
Pengaturcaraan asas
Unit Kediaman Luar Kampus
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
Connex
 
JAVA LESSON-01.pptx
JAVA LESSON-01.pptxJAVA LESSON-01.pptx
JAVA LESSON-01.pptx
StephenOczon1
 
C++ data types
C++ data typesC++ data types
C++ data types
pratikborsadiya
 
Chapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingChapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programming
z9819898203
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
YashwanthMalviya
 
Python
PythonPython

Similar to Chapter 03 (20)

Unit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingUnit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programming
 
Visual Basics for Application
Visual Basics for Application Visual Basics for Application
Visual Basics for Application
 
Visual Basic Fundamentals
Visual Basic FundamentalsVisual Basic Fundamentals
Visual Basic Fundamentals
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2pp
 
Variables&DataTypes.pptx
Variables&DataTypes.pptxVariables&DataTypes.pptx
Variables&DataTypes.pptx
 
Lesson 4 Basic Programming Constructs.pptx
Lesson 4 Basic Programming Constructs.pptxLesson 4 Basic Programming Constructs.pptx
Lesson 4 Basic Programming Constructs.pptx
 
CIS160 final review
CIS160 final reviewCIS160 final review
CIS160 final review
 
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
 
C# basics
C# basicsC# basics
C# basics
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 
C language
C languageC language
C language
 
Pengaturcaraan asas
Pengaturcaraan asasPengaturcaraan asas
Pengaturcaraan asas
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
JAVA LESSON-01.pptx
JAVA LESSON-01.pptxJAVA LESSON-01.pptx
JAVA LESSON-01.pptx
 
C++ data types
C++ data typesC++ data types
C++ data types
 
Chapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingChapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programming
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
 
Python
PythonPython
Python
 

More from Terry Yoast

9781305078444 ppt ch12
9781305078444 ppt ch129781305078444 ppt ch12
9781305078444 ppt ch12
Terry Yoast
 
9781305078444 ppt ch11
9781305078444 ppt ch119781305078444 ppt ch11
9781305078444 ppt ch11
Terry Yoast
 
9781305078444 ppt ch10
9781305078444 ppt ch109781305078444 ppt ch10
9781305078444 ppt ch10
Terry Yoast
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
Terry Yoast
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
Terry Yoast
 
9781305078444 ppt ch07
9781305078444 ppt ch079781305078444 ppt ch07
9781305078444 ppt ch07
Terry Yoast
 
9781305078444 ppt ch06
9781305078444 ppt ch069781305078444 ppt ch06
9781305078444 ppt ch06
Terry Yoast
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
Terry Yoast
 
9781305078444 ppt ch04
9781305078444 ppt ch049781305078444 ppt ch04
9781305078444 ppt ch04
Terry Yoast
 
9781305078444 ppt ch03
9781305078444 ppt ch039781305078444 ppt ch03
9781305078444 ppt ch03
Terry Yoast
 
9781305078444 ppt ch02
9781305078444 ppt ch029781305078444 ppt ch02
9781305078444 ppt ch02
Terry Yoast
 
9781305078444 ppt ch01
9781305078444 ppt ch019781305078444 ppt ch01
9781305078444 ppt ch01
Terry Yoast
 
9781337102087 ppt ch13
9781337102087 ppt ch139781337102087 ppt ch13
9781337102087 ppt ch13
Terry Yoast
 
9781337102087 ppt ch18
9781337102087 ppt ch189781337102087 ppt ch18
9781337102087 ppt ch18
Terry Yoast
 
9781337102087 ppt ch17
9781337102087 ppt ch179781337102087 ppt ch17
9781337102087 ppt ch17
Terry Yoast
 
9781337102087 ppt ch16
9781337102087 ppt ch169781337102087 ppt ch16
9781337102087 ppt ch16
Terry Yoast
 
9781337102087 ppt ch15
9781337102087 ppt ch159781337102087 ppt ch15
9781337102087 ppt ch15
Terry Yoast
 
9781337102087 ppt ch14
9781337102087 ppt ch149781337102087 ppt ch14
9781337102087 ppt ch14
Terry Yoast
 
9781337102087 ppt ch12
9781337102087 ppt ch129781337102087 ppt ch12
9781337102087 ppt ch12
Terry Yoast
 
9781337102087 ppt ch11
9781337102087 ppt ch119781337102087 ppt ch11
9781337102087 ppt ch11
Terry Yoast
 

More from Terry Yoast (20)

9781305078444 ppt ch12
9781305078444 ppt ch129781305078444 ppt ch12
9781305078444 ppt ch12
 
9781305078444 ppt ch11
9781305078444 ppt ch119781305078444 ppt ch11
9781305078444 ppt ch11
 
9781305078444 ppt ch10
9781305078444 ppt ch109781305078444 ppt ch10
9781305078444 ppt ch10
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
 
9781305078444 ppt ch07
9781305078444 ppt ch079781305078444 ppt ch07
9781305078444 ppt ch07
 
9781305078444 ppt ch06
9781305078444 ppt ch069781305078444 ppt ch06
9781305078444 ppt ch06
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
 
9781305078444 ppt ch04
9781305078444 ppt ch049781305078444 ppt ch04
9781305078444 ppt ch04
 
9781305078444 ppt ch03
9781305078444 ppt ch039781305078444 ppt ch03
9781305078444 ppt ch03
 
9781305078444 ppt ch02
9781305078444 ppt ch029781305078444 ppt ch02
9781305078444 ppt ch02
 
9781305078444 ppt ch01
9781305078444 ppt ch019781305078444 ppt ch01
9781305078444 ppt ch01
 
9781337102087 ppt ch13
9781337102087 ppt ch139781337102087 ppt ch13
9781337102087 ppt ch13
 
9781337102087 ppt ch18
9781337102087 ppt ch189781337102087 ppt ch18
9781337102087 ppt ch18
 
9781337102087 ppt ch17
9781337102087 ppt ch179781337102087 ppt ch17
9781337102087 ppt ch17
 
9781337102087 ppt ch16
9781337102087 ppt ch169781337102087 ppt ch16
9781337102087 ppt ch16
 
9781337102087 ppt ch15
9781337102087 ppt ch159781337102087 ppt ch15
9781337102087 ppt ch15
 
9781337102087 ppt ch14
9781337102087 ppt ch149781337102087 ppt ch14
9781337102087 ppt ch14
 
9781337102087 ppt ch12
9781337102087 ppt ch129781337102087 ppt ch12
9781337102087 ppt ch12
 
9781337102087 ppt ch11
9781337102087 ppt ch119781337102087 ppt ch11
9781337102087 ppt ch11
 

Recently uploaded

ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 

Recently uploaded (20)

ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 

Chapter 03

  • 1. aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf
  • 2. Variables, Constants and Calculations Chapter 3 McGraw-Hill © 2006 The McGraw-Hill Companies, Inc. All rights reserved.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. Data Types 4 Any type of data Object Varies Alphanumeric data: letters, digits, and other characters String 8 Larger whole numbers Long 4 Whole numbers in the range -2,147,483,648 to +2,147,483,647 Integer 2 Small integer in the range -32,768 to 32,767 Short 8 Double precision floating-point numbers with 14 digits of accuracy Double 4 Single precision floating-point numbers with six digits of accuracy Single 16 Decimal fractions, such as dollars/cents Decimal 8 1/1/0001 through 12/31/9999 Date 2 Single Unicode character Clear 1 0 to 255, binary data Byte 2 True or False value Boolean Storage Size in bytes Use For Data Type
  • 8.
  • 9.
  • 10.
  • 11.
  • 12. Declaration Statement Examples As Decimal Private priceDecimal As Decimal Dim priceDecimal As Single Dim temperatureSingle As Integer Private totalSoldInteger As Integer As String Dim customerName Strging As String
  • 13.
  • 14. Module Level Variable Declaration Example Code module-level declarations in the Declaration section at the top of the code
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. Conversion Examples quantityInteger =Integer.Parse(quantityTextBox.Text) priceDecimal =Decimal.Parse(priceTextBox.Text) wholeNumberInteger =Integer.Parse(digitString) resultLabel.Text =resultDecimal.ToString( ) countTextBox.Text =countInteger.ToString( ) idString =idInteger.ToString( )
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31. Format Specifier Codes Percent P or p Digits D or d Number N or n Fixed-point F or f Currency C or c Name Format Specifier Codes
  • 32. Format Specifier Code Examples ($10.00) "C" -10 valueInteger 8% "P0" 0.075 rateDecimal 7.500% "P3" 0.075 rateDecimal 7.50% "P" 0.075 rateDecimal 000123 "D6" 123 pinInteger 1,126 "N0" 1125.6744 totalDecimal $1,125.67 "C" 1125.6744 totalDecimal Output Code Value Variable
  • 33.
  • 34.
  • 35.
  • 36. Try Block - General Form Try statements that may cause error Catch [VariableName As ExceptionType] statements for action when an exception occurs [ Finally statements that always execute before exit of Try block] End Try
  • 37. Try Block - Example Catches Any Exception Try quantityInteger = Integer.Parse(quantityTextBox.Text) Me.quantityLabel.Text = quantityInteger.ToString( ) Catch Me.messageLabel.Text = "Error in input data." End Try
  • 38.
  • 39. Common Exception Classes Each exception is an instance of the Exception class. The properties of this class allow you to determine the code location of the error, the type of error and cause.
  • 40. Try Block - Example Handling Multiple Exceptions Try ' Statements that may cause errors. Catch theException As FormatException ' Statements for nonnumeric data. Catch theException As ArithmeticException ' Statements for calculation problem. Catch theException As Exception ' Statements for any other exception. End Try
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.

Editor's Notes

  1. Brief description on how to navigate within this presentation (ppt) The first time a Key Term from the chapter is used in the ppt it will display in blue Gold colored text boxes display coding examples Slides will be numbered (# of #) when multiple slides on same topic (Slide title) Speaker notes are included where appropriate for slides (*)Denotes either a comment for page reference to textbook or slide reference in ppt
  2. When you declare a variable or a named constant, VB reserves an area of memory and assigns it a name, called an identifier Identifier names are specified according to the rules of Basic as well as some recommended naming conventions
  3. The data type of a variable or constant indicates what type of information will be stored in the allocated memory space The data type charts displays the kind of data each type of data types hold, and the amount of memory allocated for each
  4. A programmer has to name (identify) the variables and named constants that will be used in a project
  5. Constants provide a way to use words to describe a value that doesn’t change Constants are declared using the keyword and are given a name, a data type, and a value Once a value is declared as a constant, its value can’t be changed during the execution of the project Data type declared and data type of the value must match Many sets of intrinsic constants (key term) are declared in system class libraries and are available for use in VB programs
  6. If a type-declaration character is not appended any whole number is assumed to be Integer and any fractional value is assumed to be Double Use two quotes with a string literal to avoid confusion
  7. VB IntelliSense feature helps you enter Private, Public, and Dim statements—after you type the space that follows VariableName As, a list pops up and displays the possible entries for data type to complete the statement If you begin to complete the statement the list automatically scrolls to the correct section; when the correct entry is highlighted press Enter, Tab, or the spacebar to select the entry or double-click if using the mouse The reserve word Dim is really short dimension, which means size. When declaring a variable, the amount of memory reserved depends on its data type.
  8. A variable may exist and be visible for an entire project, for only one form, or for only one procedure Visibility really means “this variable can be used or ‘seen’ in this location.” Namespace - Available to all procedures of project Module - Available to all procedures within that module (often a form) Use Public or Private keywords Local - Available only to the procedure in which it is declared Block - Available only in block of code inside a procedure where declared An example of a module level variable declaration is displayed on the next slide (Slide 15)
  9. The class that you use depends on the data type of the variable to which you are assigning a value; for example, to convert text to an integer, use the Integer.Parse method
  10. When you assign a value to a variable, you must take care to assign like types; you assign an integer value to an Integer variable and a decimal value to a Decimal variable ( chart shown on next slide, Slide 19) There are some exception to the rule about assigning only like types See “Implicit Conversions”
  11. The arithmetic operations you can perform you can perform in VB include addition, subtraction, multiplication, division, integer division, modulus, and exponentiation The first four operations are self explanatory, but you may not be familiar with Integer Division, Modulus, and/or exponentiation Integer division-use to divide one integer by another giving an integer result truncating (dropping) any remainder Modulus – returns the remainder of a division problem Exponentiation – raises a number to the pwer specified and retruns (produces) a result of the Double data type
  12. VB provides two options that can significantly change the behavior of the editor and compiler Not using either Option Explicit and/or Option Strict can make coding somewhat easier but provide opportunities for hard-to-find errors and very sloppy programming When Option Explicit is turned off, programmers can use any variable name without first declaring it which is a throwback to the older version of Basic and programmers spent many hours debugging programs that had small typos in a variable name Programmers should always program with Option Explicit turned on-in VB.NET the option is turned on by default for all new projects. Programmers will need to place a an additional code line before the first line of code in a file to turn it off When Option Strict it turned on, the editor and compiler try to help keep programmers from making hard-to-find mistakes. By having Option Strict turned on programmers can be saved from developing poor programming habits
  13. In VB you can convert data from one numeric data type to another—some conversions can be performed implicitly (automatically) and some you must specify explicitly. *Refer to p. 114 for tables displaying Conversion examples
  14. The expression countInteger / 2* amount Decimal is evaluated as integer division for countInteger /2, producing an integer intermediate result; then the multiplication is performed on the integer and decimal value (amountDecimal), producing a decimal result
  15. See the Appendices for additional mathematical, financial and string functions
  16. When wanting to display numeric data in the Text property of a label or text box the value must first be converted to string—the data can be formatted which controls the way the output will look
  17. The format specifier codes formats the display of output and are predefined The default format of each of the formatting codes is based on the computer’s regional setting Format specifier codes are displayed on the next slide (Slide 32) and examples are shown on the following slide (Slide 33)
  18. The strings returned are based on the computer’s regional settings and can be changed. Currently the default values are set for US-English in Windows XP *Refer to chart on p. 118
  19. When users input numbers and use those numbers in calculations, lots of things can go wrong—for example, the Parse methods, Integer.Parse and Decimal.Parse fail if the user enters nonnumeric data or leaves the text box blank
  20. The Try-Block General Form is shown on the next slide (Slide 37)
  21. *Refer to the chart on p. 125 for Common Exception Classes examples
  22. If wanting to trap for more than one type of exception multiple Catch blocks (handlers) can be included. When an exception occurs, the Catch statements are checked in sequence.
  23. Two sample message boxes
  24. Programs often need to calculate the sum of numbers. The technique for summing is to declare a module-level variable for the total