Introduction to Computing Dr. Nadeem A Khan. Lecture 10.

Slides:



Advertisements
Similar presentations
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Advertisements

Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Variables and Constants
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Introduction to Computing Dr. Nadeem A Khan. Lecture 22.
Introduction to Computing Dr. Nadeem A Khan. Lecture 8.
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
Introduction to VB prepared by Dr. I A Moneim Reference Book Schneider.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
1 9/20/06CS150 Introduction to Computer Science 1 Review: Exam 1.
Introduction to Computing Dr. Nadeem A Khan. Lecture 24.
CSI 101 Elements of Computing Spring 2009 Lecture #6: Data Types and Variables in Visual Basic Wednesday, Februrary 11th, 2009.
Introduction to Computing Dr. Nadeem A Khan. Lecture 11.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Introduction to Computing Dr. Nadeem A Khan. Lecture 14.
Introduction to Computing Dr. Nadeem A Khan. Lecture 11.
Introduction to Computing Dr. Nadeem A Khan. Lecture 6.
Data types and variables
Introduction to Computing Dr. Nadeem A Khan. Lecture 13.
Visual Basic: An Object Oriented Approach 4: Simple Programming in VB.
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
Chapter 2 Data Types, Declarations, and Displays
VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not.
To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window.
Introduction to Computing Dr. Nadeem A Khan. Lecture 9.
Lecture 2: Topics Bits and Bytes Primitive Types Casting Strings Boolean expressions.
Introduction to Computing Dr. Nadeem A Khan. Lecture 5.
Objectives You should be able to describe: Data Types
 Pearson Education, Inc. All rights reserved Formatted Output.
 2005 Pearson Education, Inc. All rights reserved Formatted Output.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 2 Introduction to C++
Microsoft Access Using Visual Basic Routines. Visual Basic Datatypes Boolean Byte Currency Date Double Integer Long Object Single String Variant Hyperlink.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
Chapter 2: Using Data.
Tutorial 6 Introducing Variables, Memory Concepts & Arithmetic.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Programming with Visual C++: Concepts and Projects Chapter 3A: Integral Data (Concepts)
INT213-Week-2 Working with Variables. What is variable
COMP Primitive and Class Types Yi Hong May 14, 2015.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
# 1# 1 What is a variable that you create? What is a constant that you create? What is an intrinsic (built-in) constant? What variables are built in?
CECS 5020 Computers in Education Visual Basic Variables and Constants.
Variables Continued In the last session we saw how variables are objects that allow us to store values in the RAM of the computer In this session we shall.
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
Numbers1 Working with Numbers There are times that we have to work with numerical values. When we count things, we need Integers or whole numbers. When.
Chapter One Lesson Three DATA TYPES ©
Introduction to Computing Dr. Nadeem A Khan. Lecture 9.
Variables in VB. What is a variable? ► A named memory location that stores a value.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 06 – Java Datatypes Webpage:
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
B065: PROGRAMMING Variables 2. Starter  What is wrong with the following piece of code: Option Explicit Off Dim num1 as string Dim num2 as integer num1.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
28 Formatted Output.
Egyptian Language School Computer Department
Week 2 - Wednesday CS 121.
A variable is a name for a value stored in memory.
Visual Basic Variables
Data Types, Arithmetic Operations
Visual Basic 6 Programming.
Numbers.
C# Revision Cards Data types
Variables and Constants
Presentation transcript:

Introduction to Computing Dr. Nadeem A Khan

Lecture 10

Sub Text1_KeyPress(KeyAscii as Integer) statements statements End Sub ► Text1_KeyPress event will occur when Text1 has the focus and a key is pressed Text1 has the focus and a key is pressed The Keypress Event Procedure

Sub Text1_KeyPress(KeyAscii as Integer) statements statements End Sub ► Keyascii  is a variable (of type Integer)  gets the ANSI value of the pressed key  value is used to display the corresponding character in the Text1 at the end of this procedure The Keypress Event Procedure (Contd.)

What will happen in these cases? Sub Text1_KeyPress(KeyAscii as Integer) Let KeyAscii =65 Let KeyAscii =65 End Sub Sub Text1_KeyPress(KeyAscii as Integer) Let KeyAscii =0 Let KeyAscii =0 End Sub The Keypress Event Procedure (Contd.)

► Already known:  String  Single  Integer Data Types

► Strings Storage: 10 bytes + string length Range: 0 to app. 2 billions chars. Declaration: Dim strVarLen As String (declares a string of a variable length) (declares a string of a variable length) Data Types (Contd.)

► Fixed-Length Strings Storage: Length of string Range: 1 to app. 65, 400 chars. Declaration: Dim strFixLen As String * 2 (declares a string of a fix size of 2 chars.) Data Types (Contd.)

► Fixed-Length Strings Usage:Example Dim strText As String * 5 Let strText = “Hello” Picture1.Print strText Let strText = “H” Picture1.Print strText Let strText = “HelloWorld” Picture1.Print strText Data Types

► Fixed-Length Strings Usage:Result: Hello(Complete string) H…. (H followed 4 spaces) Hello(First 5 characters only) => The length is fix Data Types

► Integers Storage: 2 bytes Range: -32,768 to 32,767 Declaration: Dim intExample As Integer (declares intExample as an Integer variable) (declares intExample as an Integer variable) Data Types (Contd.)

► Integers Usage:Example Dim count As Integer Let count= 6 Picture1.Print count Let count= count+1 Picture1.Print count Let count= 6/5 Picture1.Print count Let count= * 2 Picture1.Print count Data Types

► Integer Usage:Result67 1 (rounding to lower value) 5(rounding to higher value) => takes only whole number values => takes only whole number values Data Types

► Long (Integer) Storage: 4 bytes Range: -2,147,483,648 to 2,147,483,647 Declaration: Dim lngExample As Long (declares lntExample as a long variable) (declares lntExample as a long variable) Data Types (Contd.)

► Long (Integer) Usage: Same as Integer Type except the range is much larger much larger Data Types (Contd.)

► Byte Storage: 1 byte Range: 0 to 255 Declaration: Dim bytExample As Byte (declares bytExample as a Byte type variable) (declares bytExample as a Byte type variable) Data Types (Contd.)

► Byte Usage: Same as Integer Type except the range is positive and much smaller positive and much smaller Data Types (Contd.)

► Boolean Storage: 2 bytes Range: TRUE(1) or FALSE(0) Declaration: Dim blnState As Boolean (declares a Boolean type variable blnState) Data Types (Contd.)

► Boolean Usage:Example Dim blnExample As Boolean Let blnExample= FALSE Picture1.Print blnExample Let blnExample= 1 Picture1.Print blnExample Let blnExample= 6 Picture1.Print blnExample Let blnExample= -8*7+5.2 Let blnExample= -8*7+5.2 Picture1.Print blnExample Data Types (Contd.)

► Boolean Usage:Example FALSE FALSE TRUE TRUE =>Values other than 0 are TRUE =>Values other than 0 are TRUE Data Types (Contd.)

► Single (Precision Floating-Point) Storage: 4 bytes Range: -3.4…E38 to -1.4…E-45 (negative) 1.4…E-45 to 3.4…E38 (positive) Declaration: Dim sngAverage As Single (declares a Single type variable sngAverage) Data Types (Contd.)

► Double (Precision Floating-Point) Storage: 8 bytes Range: -1.7…E308 to -4.9…E-324 (negative) 4.9…E-324 to 1.7…E308 (positive) 4.9…E-324 to 1.7…E308 (positive)Declaration: Dim dblAverage As Double (declares a Double type variable dblAverage) Data Types (Contd.)

► Double Usage:Example Dim sngValue As Single, dblValue As Double Let sngValue= 1/3 Picture1.Print sngValue Let dblValue= 1/3 Picture1.Print dblValue Data Types (Contd.)

► Double Usage:Result (Single precision) (Double precision) => Value of 1/3 represented more accurately by double than by single by double than by single Data Types (Contd.)

► Double Usage:Example Dim sngValue As Single, dblValue As Double Let sngValue= 1/3 Let sngValue= sngValue * Picture1.Print sngValue Let dblValue= 1/3 Let dblValue= dblValue * Picture1.Print dblValue Data Types (Contd.)

► Double Usage:Result (Single precision; rounding error) (Double precision) => - The decimal point is floating; - Eventually both will be subjected to rounding errors value increases to large values value increases to large values - Still Double will remain more precise than Single Data Types (Contd.)

► Currency Storage: 8 bytes Range: -922,337,203,685, to 922,337,203,685, ,337,203,685, Declaration: Dim curRevenue As Currency (declares a Currency type variable curRevenue) Data Types (Contd.)

► Currency Usage:Example Dim curValue As Currency Let curValue= 1/3 Picture1.Print curValue Let curValue= 100*1/3 Picture1.Print curValue Data Types (Contd.)

► Currency Usage:Result =>- The decimal point is NOT floating; - Could be used for currency and scientific research - No rounding problems for high values Data Types (Contd.)

► Even more data types  Date Variable: for date and time  Object Variable  Variant Variable  ………. Read the book for more info. Data Types (Contd.)

Not only +,-,*,^ But also: But also: \ opeartor e.g: 5.1\2.04= 2 \ opeartor e.g: 5.1\2.04= 2 MOD operator e.g: 15.2 MOD 6=3 MOD operator e.g: 15.2 MOD 6=3 More on Operators

More on Operators (Contd.) ► Operator Precedence 1. ^ 2.- operator (indicating a negative value) 3. * and / operator 4. \ operator 5. MOD operator 6. + and - operator

Assignment 3 ► Assignment 3 has been posted to the CS101 Website. ► The Deadline is on 6:59 p.m. Wednesday Sept. 25.

Reading for today ► Scott Warner:  Chapter 2: Section 2.3(p60-p66)  Chpater5: Section 5.1