Unit 6: Software Design & Development. Data Types in Programming

Слайд 2

BTEC National for IT Practitioners Unit 6: Software Design & Development Data Types

BTEC National for IT Practitioners Unit 6: Software Design & Development

Data Types

Слайд 3

Objectives What are Variables? The Data Types supported by VB Understand why Data Types are used

Objectives

What are Variables?
The Data Types supported by VB
Understand why Data Types

are used
Слайд 4

Variables When a program runs, any data it uses must be

Variables

When a program runs, any data it uses must be stored

in RAM
A variable is a name made up by a programmer to identify the address in RAM where a piece of data is stored
Every variable must be of a given data type (see word document “Data Types”)
Слайд 5

Declaring Variable To declare a variable means to tell Visual Basic

Declaring Variable

To declare a variable means to tell Visual Basic two

things about it
Its name
Its data type
Use the keywords Dim and As when you declare a variable, for example
Dim Number As Integer
Dim Payment As Decimal
Dim DateOfPayment As Date
Слайд 6

Declaring Variables You can declare more than one variable of the

Declaring Variables

You can declare more than one variable of the same

type in the same line of code, for example
Dim FirstNumber, SecondNumber, ThirdNumber As Integer
Слайд 7

What Data Types are Supported? See “Data Types” document

What Data Types are Supported?

See “Data Types” document

Слайд 8

Why are Data Types used? Data Types are used to determine

Why are Data Types used?

Data Types are used to determine what

type of information is going to be stored in a variable (will it be a date, a number or some text)
Data Types also determine how much space in memory (RAM) the variable needs to store the information
Each Data Type has a maximum size (this is what has the impact on memory)
Important to choose the correct Data Type for variables to ensure that the most efficient amount of storage space needed is used
Слайд 9

Why are Data Types used? Data Types are also used to

Why are Data Types used?

Data Types are also used to help

validate what is being stored in each variable (since VB will present you with an error message if you put a different type of value in a variable with the wrong data type)
For example, VB will not let you put text or numbers into a variable with a Date data type
And VB will not let you put text into a field with a Number data type
The result will be that the program will “fall-over” displaying an error message
Слайд 10

Why are Data Types used? Having different Data Types allows you

Why are Data Types used?

Having different Data Types allows you to

perform calculation on the different values of variable (such as Adding values of variables)
Having different Data Types also allows different formatting to be applied to the field when you create reports or data entry screen
For example, a Date field in VB (just like in Access) can be printed or displayed with the following different formats
11/09/2011
11 Sept 2011
11 September 2011
Слайд 11

So, what are the benefits? Accurate storage This is vitally important

So, what are the benefits?

Accurate storage
This is vitally important for numeric

values. If the data type is too small to store a value, it becomes truncated (chopped) and accuracy is lost.
Using a data type of the right size prevents this happening
Efficiency of storage
This is important particularly in computer systems where free RAM or processing power may be limited
Additional validation
Entering non-numeric data into a numeric data type can cause a program to crash at runtime
Слайд 12

So, what are the benefits? Calculations Data that you need to

So, what are the benefits?

Calculations
Data that you need to do calculations

with must be placed in a numeric data type such as integer or single
Placing non-numeric data into these variables, will result in the program crashing
Formatting
By having data types you can take advantage of the formatting that can be applied to each type and make the presentation of information stored in variable appear more user friendly
Consistency
Data types give the programmer the ability to have variables that have a consistent style throughout the program (with a consistent format and options)