SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Variables and Datatypes

 Software Design & Development




                                 1
Data Types

A program can’t do anything until you have reserved a
space in memory for the values used in it
This is called declaration of variables
When you declare a variable you must:
   Give it a sensible name
   Give it a data type depending on what kind of
   value it will hold
   Ask yourself will it hold just letters or whole
   numbers or numbers with a decimal point or
   dates…..etc

                                                        2
Data types
Depending on the type of data used by our program,
we need to choose to use a particular data type
Some programs only use whole numbers – we can’t
have ½ a person!
Other programs only deal with numbers up to a few
thousand – if we count the students in the College
Other programs deal with huge numbers such as
distances in space




                                                     3
Basic data types
Date
   Covers most of the useful range!!
   Anything from 1st Jan 100 to 31st Dec 9999
   Time information is also stored as hours, minutes and
   seconds
   Uses 8 bytes of storage
String
   For text e.g. names, addresses, postcodes
   For numbers that you don’t want to do any maths on e.g. A
   telephone number
   You can fix the length or let it be variable
   Fixing the length also fixes the amount of storage space
                                                               4
Basic data types

Boolean
  For true or false values e.g. Yes / No answers
  Can be used for numbers
    0 = false
    Any other value = true
  Uses 2 bytes of storage
Decimal
  Numbers with decimal places, especially currency
  Takes 16 bytes of storage



                                                     5
Basic data types
Short
  whole numbers in the range –32,768 to 32,767
  Examples: -32 or 10,000
  needs 2 bytes of storage space


Integer
  A whole number in the range –2 billion to + 2 billion
  Examples: 20,000,000 or -400,000
  needs 4 bytes of storage



                                                          6
Basic data types
Single
  Numbers with decimal places and fractions
  in the range -3.402823E38 to –1.401298E-45 for negative
  values and 1.401298E-45 to 3.4o2823E38 for positive
  Examples: 3·142, -700·75
  Takes 4 bytes of storage
Double
  For incredibly large or small values use a double, as a single
  wont 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 uses half the storage space

                                                                   7
Variables - Naming conventions

Hungarian notation is used in naming variables
This is accepted as 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
You will need to use these conventions



                                                         8
Variables

Prefixes
sht = short         dte = date
int = integer       dec = decimal
sng = single        bln = boolean
dbl = double        str = string




                                    9
Constants

Use a Constant where a value is needed but does not
change while program is running
  e.g. VAT, Annual Leave, Pi, Gravity
Constants are always global as they are only set up
once
This allows for easy program modification if value
changes
We don’t use a Dim statement, but use
  Const dblPi as double = 3.147
  Const sngGravity as single = 9.8



                                                      10
Name the variable
Write down some suitable identifiers for these
variables:

  VAT
  Your telephone number
  Today’s date
  Whether or not the sun is shining
  Your name
  The price of a can of coke

Remember to use naming conventions and
correct data types!
                                                 11

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.netJaya Kumari
 
Nested queries in database
Nested queries in databaseNested queries in database
Nested queries in databaseSatya P. Joshi
 
HTML Text formatting tags
HTML Text formatting tagsHTML Text formatting tags
HTML Text formatting tagsHimanshu Pathak
 
Command line arguments
Command line argumentsCommand line arguments
Command line argumentsAshok Raj
 
Characteristics of OOPS
Characteristics of OOPS Characteristics of OOPS
Characteristics of OOPS abhishek kumar
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and OperatorsMarwa Ali Eissa
 
Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)AakankshaR
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model IntroductionNishant Munjal
 
Database systems - Chapter 2
Database systems - Chapter 2Database systems - Chapter 2
Database systems - Chapter 2shahab3
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQLEhsan Hamzei
 

Was ist angesagt? (20)

Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.net
 
Data types
Data typesData types
Data types
 
Nested queries in database
Nested queries in databaseNested queries in database
Nested queries in database
 
Introduction to .NET Framework
Introduction to .NET FrameworkIntroduction to .NET Framework
Introduction to .NET Framework
 
VB.net
VB.netVB.net
VB.net
 
Array in c++
Array in c++Array in c++
Array in c++
 
Dtd
DtdDtd
Dtd
 
HTML Text formatting tags
HTML Text formatting tagsHTML Text formatting tags
HTML Text formatting tags
 
VB Script
VB ScriptVB Script
VB Script
 
Features of java
Features of javaFeatures of java
Features of java
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
Characteristics of OOPS
Characteristics of OOPS Characteristics of OOPS
Characteristics of OOPS
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
 
Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
Database systems - Chapter 2
Database systems - Chapter 2Database systems - Chapter 2
Database systems - Chapter 2
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 

Andere mochten auch

Andere mochten auch (20)

Decisions
DecisionsDecisions
Decisions
 
Simple debugging
Simple debuggingSimple debugging
Simple debugging
 
Event driven theory
Event driven theoryEvent driven theory
Event driven theory
 
Controls
ControlsControls
Controls
 
Using loops
Using loopsUsing loops
Using loops
 
Design for edp
Design for edpDesign for edp
Design for edp
 
Learning VB.NET Programming Concepts
Learning VB.NET Programming ConceptsLearning VB.NET Programming Concepts
Learning VB.NET Programming Concepts
 
Input output
Input outputInput output
Input output
 
Vb net xp_11
Vb net xp_11Vb net xp_11
Vb net xp_11
 
Vb.net session 12
Vb.net session 12Vb.net session 12
Vb.net session 12
 
Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
Decisions
DecisionsDecisions
Decisions
 
Simple debugging
Simple debuggingSimple debugging
Simple debugging
 
Software development lifecycle
Software development lifecycleSoftware development lifecycle
Software development lifecycle
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programming
 
Data structures vb
Data structures vbData structures vb
Data structures vb
 
Ndu06 typesof language
Ndu06 typesof languageNdu06 typesof language
Ndu06 typesof language
 
Design documentation
Design documentationDesign documentation
Design documentation
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Event driven programming amazeballs
Event driven programming amazeballsEvent driven programming amazeballs
Event driven programming amazeballs
 

Ähnlich wie Data types vbnet

CIS 1403 Lab 2- Data Types and Variables
CIS 1403 Lab 2- Data Types and VariablesCIS 1403 Lab 2- Data Types and Variables
CIS 1403 Lab 2- Data Types and VariablesHamad Odhabi
 
Programming concepts By ZAK
Programming concepts By ZAKProgramming concepts By ZAK
Programming concepts By ZAKTabsheer Hasan
 
Ch-3(b) - Variables and Data types in C++.pptx
Ch-3(b) - Variables and Data types in C++.pptxCh-3(b) - Variables and Data types in C++.pptx
Ch-3(b) - Variables and Data types in C++.pptxChereLemma2
 
C programming Ms. Pranoti Doke
C programming Ms. Pranoti DokeC programming Ms. Pranoti Doke
C programming Ms. Pranoti DokePranoti Doke
 
Variables & Data Types.pptx
Variables & Data Types.pptxVariables & Data Types.pptx
Variables & Data Types.pptxAbdisamedAdam
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
Variables and calculations_chpt_4
Variables and calculations_chpt_4Variables and calculations_chpt_4
Variables and calculations_chpt_4cmontanez
 
different Data type Modifiers in c language
different Data type Modifiers in c languagedifferent Data type Modifiers in c language
different Data type Modifiers in c languagedbmscse61
 
Visual Basic Fundamentals
Visual Basic FundamentalsVisual Basic Fundamentals
Visual Basic FundamentalsDivyaR219113
 

Ähnlich wie Data types vbnet (20)

CIS 1403 Lab 2- Data Types and Variables
CIS 1403 Lab 2- Data Types and VariablesCIS 1403 Lab 2- Data Types and Variables
CIS 1403 Lab 2- Data Types and Variables
 
Handling Data in Algorithm
Handling Data in AlgorithmHandling Data in Algorithm
Handling Data in Algorithm
 
Fundamentals of Programming Chapter 4
Fundamentals of Programming Chapter 4Fundamentals of Programming Chapter 4
Fundamentals of Programming Chapter 4
 
Variables
VariablesVariables
Variables
 
Programming concepts By ZAK
Programming concepts By ZAKProgramming concepts By ZAK
Programming concepts By ZAK
 
12.6-12.9.pptx
12.6-12.9.pptx12.6-12.9.pptx
12.6-12.9.pptx
 
Ch-3(b) - Variables and Data types in C++.pptx
Ch-3(b) - Variables and Data types in C++.pptxCh-3(b) - Variables and Data types in C++.pptx
Ch-3(b) - Variables and Data types in C++.pptx
 
C programming Ms. Pranoti Doke
C programming Ms. Pranoti DokeC programming Ms. Pranoti Doke
C programming Ms. Pranoti Doke
 
Data types ,variables,array
Data types ,variables,arrayData types ,variables,array
Data types ,variables,array
 
C++ data types
C++ data typesC++ data types
C++ data types
 
Variables & Data Types.pptx
Variables & Data Types.pptxVariables & Data Types.pptx
Variables & Data Types.pptx
 
Data types in C
Data types in CData types in C
Data types in C
 
Data types in C
Data types in CData types in C
Data types in C
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Variables and calculations_chpt_4
Variables and calculations_chpt_4Variables and calculations_chpt_4
Variables and calculations_chpt_4
 
different Data type Modifiers in c language
different Data type Modifiers in c languagedifferent Data type Modifiers in c language
different Data type Modifiers in c language
 
Visual Basic Fundamentals
Visual Basic FundamentalsVisual Basic Fundamentals
Visual Basic Fundamentals
 
Ppt lesson 05
Ppt lesson 05Ppt lesson 05
Ppt lesson 05
 
Lesson 5 PP
Lesson 5 PPLesson 5 PP
Lesson 5 PP
 
Chapter 03
Chapter 03Chapter 03
Chapter 03
 

Mehr von nicky_walters

Mehr von nicky_walters (8)

Pseudocode flowcharts
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowcharts
 
Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
Ndu06 typesof language
Ndu06 typesof languageNdu06 typesof language
Ndu06 typesof language
 
Event driventheory
Event driventheoryEvent driventheory
Event driventheory
 
Debugging
DebuggingDebugging
Debugging
 
Decisions
DecisionsDecisions
Decisions
 
Intro to visual studio 2008
Intro to visual studio 2008Intro to visual studio 2008
Intro to visual studio 2008
 
Input output
Input outputInput output
Input output
 

Data types vbnet

  • 1. Variables and Datatypes Software Design & Development 1
  • 2. Data Types A program can’t do anything until you have reserved a space in memory for the values used in it This is called declaration of variables When you declare a variable you must: Give it a sensible name Give it a data type depending on what kind of value it will hold Ask yourself will it hold just letters or whole numbers or numbers with a decimal point or dates…..etc 2
  • 3. Data types Depending on the type of data used by our program, we need to choose to use a particular data type Some programs only use whole numbers – we can’t have ½ a person! Other programs only deal with numbers up to a few thousand – if we count the students in the College Other programs deal with huge numbers such as distances in space 3
  • 4. Basic data types Date Covers most of the useful range!! Anything from 1st Jan 100 to 31st Dec 9999 Time information is also stored as hours, minutes and seconds Uses 8 bytes of storage String For text e.g. names, addresses, postcodes For numbers that you don’t want to do any maths on e.g. A telephone number You can fix the length or let it be variable Fixing the length also fixes the amount of storage space 4
  • 5. Basic data types Boolean For true or false values e.g. Yes / No answers Can be used for numbers  0 = false  Any other value = true Uses 2 bytes of storage Decimal Numbers with decimal places, especially currency Takes 16 bytes of storage 5
  • 6. Basic data types Short whole numbers in the range –32,768 to 32,767 Examples: -32 or 10,000 needs 2 bytes of storage space Integer A whole number in the range –2 billion to + 2 billion Examples: 20,000,000 or -400,000 needs 4 bytes of storage 6
  • 7. Basic data types Single Numbers with decimal places and fractions in the range -3.402823E38 to –1.401298E-45 for negative values and 1.401298E-45 to 3.4o2823E38 for positive Examples: 3·142, -700·75 Takes 4 bytes of storage Double For incredibly large or small values use a double, as a single wont 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 uses half the storage space 7
  • 8. Variables - Naming conventions Hungarian notation is used in naming variables This is accepted as 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 You will need to use these conventions 8
  • 9. Variables Prefixes sht = short dte = date int = integer dec = decimal sng = single bln = boolean dbl = double str = string 9
  • 10. Constants Use a Constant where a value is needed but does not change while program is running e.g. VAT, Annual Leave, Pi, Gravity Constants are always global as they are only set up once This allows for easy program modification if value changes We don’t use a Dim statement, but use Const dblPi as double = 3.147 Const sngGravity as single = 9.8 10
  • 11. Name the variable Write down some suitable identifiers for these variables: VAT Your telephone number Today’s date Whether or not the sun is shining Your name The price of a can of coke Remember to use naming conventions and correct data types! 11