National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.

Slides:



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

Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types and Expressions
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Constants Variables change, constants don't final = ; final double PI = ; … area = radius * radius * PI; see Liang, p. 32 for full code.
1 ) Data Attributes 2) Declarations, Assignment and Instantiation 3) Global and Local Data 4) Variables 5) Constants 6) Example programs COMP205 IMPERATIVE.
22-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
CSI 101 Elements of Computing Spring 2009 Lecture #6: Data Types and Variables in Visual Basic Wednesday, Februrary 11th, 2009.
Slide 1 Variables, Constants and Data Types. Slide 2 Variables v Three components define a variable: –Name (memory location) –Type –Information (value)
CS150 Introduction to Computer Science 1
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.
String Escape Sequences
Software design and development Marcus Hunt. Application and limits of procedural programming Procedural programming is a powerful language, typically.
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Input & Output: Console
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 2 Introduction to C++
VCE IT Theory Slideshows By Mark Kelly vceit.com Data Types 1 a.
Lecture 8 Visual Basic (2).
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Chapter 2: Using Data.
CPS120: Introduction to Computer Science
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
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.
Variables in Java x = 3;. What is a variable?  A variable is a placeholder in memory used by programmers to store information for a certain amount of.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
INT213-Week-2 Working with Variables. What is variable
Chapter 4 Literals, Variables and Constants. #Page2 4.1 Literals Any numeric literal starting with 0x specifies that the following is a hexadecimal value.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
# 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?
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 7 Where Can I Store This?
Programming with Microsoft Visual Basic th Edition
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
Variables in VB.NET. Variables  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can.
CPS120: Introduction to Computer Science Variables and Constants.
Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.
Copyright © Don Kussee 1120-Ch3 #481 CNS 1120 Chapter 3 Data Types and Variables 1120-Ch3.PPT.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
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.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Copyright © Texas Education Agency, Computer Programming Variables and Data Types.
Egyptian Language School Computer Department
A variable is a name for a value stored in memory.
VBA - Excel VBA is Visual Basic for Applications
Variables and Primative Types
2. Understanding VB Variables
Variables ,Data Types and Constants
Microsoft Visual Basic 2005 BASICS
Numbers.
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
Variables Title slide variables.
CHAPTER FOUR VARIABLES AND CONSTANTS
VB Variables and Data
Unit 3: Variables in Java
Chap 2. Identifiers, Keywords, and Types
Variables and Constants
Presentation transcript:

National Diploma Unit 4 Introduction to Software Development Data types, variables and constants

Basic ideas Computers are very good at doing sums ….but only if we tell them what to do! Programs are best if they are kept general in nature E.g. a=a+b is better than a=2+1 This allows us to decide the values of a and b within certain limits

Data types Depending on the limits we want and the type of data, we can choose to use a particular data type If none of the basic ones fit…you can even create your own (but you need to tell VB everything about it first)

Basic data types Integer A whole number in the range –32,768 to 32,767 Needs 2 bytes of storage space Long A whole number in the range – 2,147,483,648 to 2,147,483,647 Needs 4 bytes of storage

Basic data types Single Floating point numbers in the range E38 to – E-45 for negative values and E-45 to 3.4o2823E38 for positive Takes 4 bytes of storage This should be enough for anyone but…………

Basic data types Double Make yours a double if…… A single doesn’t provide the range or accuracy that you need Takes 8 bytes of storage Bear this last fact in mind, if you don’t need this level of accuracy, declare a single as it is more economical on storage

Basic data types Currency Especially for financial data Uses 8 bytes of storage (Remember that a single only uses 4) Uses 4 decimal points for accuracy and to ensure there are no rounding errors Range is –922,337,203,685, to 922,337,203,685,

Basic data types Decimal Any number scaled to a power of 10 Can be a whole number or just a fractional part Range for whole numbers 79,228,162,514,264,337,593,543,950,335 + or – For fractional numbers: or –

Basic data types Byte Used to store a number or character Number range =0-255 Character = 1 ASCII Stored in 1 byte so very economical

Basic data types Boolean For true or false values Can be used for numbers  0=false  Any other value = true Uses 2 bytes of storage

Basic data types Date Anything from 1 st Jan 100 to 31 st Dec 9999 Covers most of the useful range!! Time information is also stored as hours, minutes and seconds Uses 8 bytes of storage

Basic data types String For text and numbers that you don’t want to do any maths on e.g. a NI number or telephone number You can fix the length or let it be variable length Fixing the length also fixes the amount of storage space

Basic data types Variant When VB doesn’t know what data type it is dealing with Uses 16 bytes for numeric data and 22 bytes overhead + the string itself for a string variable Good programmers leave this one well alone  It is wasteful of storage  It doesn’t help with documentation at all

Basic data types Object For when new objects are declared in an object oriented program Uses 4 bytes of storage All new objects must belong to a class which defines what characteristics they must have The class is like a biscuit cutter and objects are the biscuits

Variables Programs can’t do anything until you have reserved the space in memory that will hold values Dim intNumber as integer This is a typical declaration statement It reserves a 2 byte slot of memory to hold the value of intNumber intNumber=3 Assigns the value of 3

Variables Naming conventions We will use Hungarian notation which is accepted a good programming practice Prefix the variable name with a 3 letter identifier to indicate the data type The variable name should be meaningful - good programmers can read the code of a program and know what it does

Variables Prefixes int = integerlng=long sng=singledbl=double byt=bytecur=currency dtm=datebln=boolean str=stringvnt=variant obj=object

Variables Variables also have scope and lifetime Dim intNumber as integer In this statement, Dim is a local declaration if it is associated with one control or sub procedure If it is in the general declarations area of the form, it has form-wide scope but is still private

Variables Public intNumber as integer This in the general declarations area of a form makes a variable publicly accessible This might be useful but don’t declare all variables public – much better to restrict their scope and keep them local to avoid confusion

Variables Static intNumber as integer Usually variables reach the end of their lifetime at the end of a sub procedure The memory they were using can then be “recycled” Static allows a variable to retain its value for the whole of the program This allows its value to be used by other bits of the program (normally it can’t)

Constants These are special items of data whose value will not be allowed to change at run time Examples include pi, the speed of light, acceleration due to gravity and possibly VAT etc Const dblPi as double Const sngGravity as single ….etc

Name the variable Write down some suitable identifiers for these variables: VATa telephone number Today’s date Whether or not the sun is shining Your name The price of a can of coke

Name the variable Remember to use meaningful names (no spaces or dots allowed) Use Hungarian notation to show the data type

Return to main Menu