Слайд 1Key Terms – Programming
Service
Oriented
Time
Driven
Events
Click
Trigger
Forms
Handlers
Слайд 2BTEC National for IT Practitioners
Unit 6: Software Design & Development
Data Types
Слайд 3Objectives
What are Variables?
The Data Types supported by VB
Understand why Data Types
are used
Слайд 4Variables
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”)
Слайд 5Declaring 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
Слайд 6Declaring 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
Слайд 7What Data Types are Supported?
See “Data Types” document
Слайд 8Why 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
Слайд 9Why 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
Слайд 10Why 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
Слайд 11So, 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
Слайд 12So, 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)
Слайд 13Assignment 1 – For P4
Create a table in word to list
some of the data types that are available in Visual Basic, with their size, space taken up (in RAM) and the short/brief description of the type of data that should be stored in the data type (include some examples)
Under the table provide a description of the benefits gained by having a variety of different data types available when producing programs