Top Banner
24

Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Dec 29, 2015

Download

Documents

Dustin Watts
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"
Page 2: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Rote Learning of the Week"A variable is a named section of RAM that stores data of a specific data type"

Page 3: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

ObjectsIn the first lecture we introduced the idea of classes

and objects

One way of looking at an object is that it is a word in our code that links to the functions in a class

Once we have an instance of an object (the word) we may access the methods and properties defined in the class Properties allow us to change or find out about some

aspect of the dataMethods allow us to perform some action on the data

 There are lots of different objects within the computer

system all allowing us to control data in different ways

Page 4: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Screen Objects

Event driven

Page 5: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

System ArchitecturePresentation(Interface)

Data LayerDatabase

Middle TierBusiness Logic(Objects/Classes)

Page 6: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Layers Split in to Other Layers

Interface and code linked by events

Page 7: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Click Event Handler

Event Handler = Function that responds to an event

Page 8: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Interface v RAM Exercise

Split into two teamsBoth teams to count from 1 – 50One team to write the numbers on paperThe other team to count in their headsEverybody standRaise your hand when you have finished

Page 9: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

The Assignment Operator

The symbol for copying data around the systemPossibly the most important concept in programmingFail to grasp how this works and you won’t progress

Page 10: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

How it workstxtMessage.Text = “Hello world”;

The assignment operator copies data from right to left

Destination = Source

All together now!

Page 11: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Computer Technology

We need objects & classes to control all this!

Page 12: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Where the RAM fits in

The RAM

Page 13: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Variables and RAMComputer RAM is VERY COMPLICATEDStores data as binary values

“hello” stored as … “0100100001000101010011000100110001001111”

Variables spare us a great deal of pain!

Variables are a very simple kind of objectAllow us to control a section of RAMThree things we want to do…

Allocate a section of RAMGive that section a name (a word)Set the rules for the type of data it will storeStore some data in the variable

Page 14: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Creating Variables

Variables are “declared” using the key word “Dim”

Page 15: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Data TypesNotice in declaring variables we give them a

data type, e.g.

string

Sets the rule as to the type of data we may put in the box

Page 16: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Data TypesInteger whole number

Types of Int Int16 -32768 to +32787 Int32 (or just Int) -2,147,483684 to +2,147,483683 Int64 -9223372036854775808 to

+9223372036854775807

String any combination of numbers and letters

DateTime any valid date or timeBoolean true or falseDecimal any whole or decimal number

Page 17: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Declare Variables at the top of your code…

Makes them easier to findMust declare a variable before we may use it

Page 18: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Think as Variables a Boxes in RAMThe seven variables declared above have the

following names…ErrMsgOfferTitleDescriptionSwapNoUsernoEmailUserName

A series of boxes are created…

Page 19: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Rules for Variable NamesWe do not have any spaces in the variable names

Err Msg BadErrMsg GoodUse underscore if you want a space e.g. Err_Msg

The variable names use pascal or camel caseswapno BadSwapNo Good (public variable)swapNo Good (private variable)

The names must be meaningfulA, B & C are normally bad names as they give no clue as

to their usage

Page 20: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Things we do with Variables

Assign literal constants

Page 21: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Perform Calculations

Page 22: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Get data off the Interface

string FirstName;FirstName = txtFirstName.Text;

Page 23: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

A Simple ApplicationTo finish off we will create the following

application…

Page 24: Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"

Common Variable ErrorsWe shall look at some common errors in

Visual StudioLearn to recognise the errors

Missing variable declarationMismatched Variable NamesSelection of incorrect data typeRounding errorsOverflow errors