driving test 1 marking scheme focus on five areas to pass driving test 1

30

Upload: kari-moak

Post on 01-Apr-2015

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1
Page 2: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

Driving Test 1 Marking Scheme

Focus on five areas to pass driving test 1

Page 3: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

1. Documentation & OrganisationCommentsBlock and In-Line

Meaningful names for variables and other objects

Use of naming conventions for controls e.g. txt lbl etc..

Split our system into layers

Page 4: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

2. Events and HandlersThe user triggers an event e.g. clickThe handler contains some code that does

something when that event happensCode executes in sequence from line 1 to line

n

Page 5: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

3. ObjectsAllow us to control the computer without

worrying about the complexity under the lidObjects are defined by classes (Cake v Recipe)Objects have methods that make them do

something DeleteQuery.Execute("qry_tblAddress_Delete")

Objects have properties that tell us/set something txtAddressNo.Text

Page 6: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

4. Variables & AssignmentSimple object that controls the RAMDeclare a variable using Dim (make a box in

RAM)Dim FirstName as String

Give the box a name so we may put data in it Give the box a data type so we may control what

kind of data it may store

Use the assignment operator = to copy data into the box

FirstName = txtFirstName.Text

Page 7: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

5. Functions and ParametersFunctions perform a predefined task and return

a valueParameters (like the assignment operator) are

another way of copying data from one part of the system to another

We will look at IsNumeric in this lectureFunctions are useful for telling us something

about the state of the system (has the user entered a valid date?)

Use them in an If statement to validate data and provide error messages to the user

Page 8: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1
Page 9: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

Sequence v SelectionSequence describes the code executing line

by lineSelection is about making decisions

Selecting one block of code OrSelecting a different block of code

Handled by If Statements

Page 10: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

The If StatementIf condition Then

‘execute the code hereEnd If

Page 11: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

Else

Page 12: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

ConditionsRelational operators

> If a > b Then< If a < b Then>= If a >= b Then<= If a <= b Then

Equality and Inequality operators= If a = b Then<> If a<>b Then

Page 13: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

When is an Assignment Operator not an Assignment Operator?All about context

“The jelly is nearly set.” And “The badger returns to its set.”

Page 14: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

ElseIf

Page 15: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

If Statements in ActionWe shall look at the code for GPE

Page 16: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

Validation"Programming today is a race between

software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.“

Rich Cook

Page 17: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

ValidationCreate software that is

Robust (doesn’t crash)Responsive (Tells us what went wrong)

Consider the following code

Dim FirstName as IntegerFirstName=”Fred”

Page 18: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

What is wrong with the following?Dim Age as IntegerAge = txtAge.Text

Page 19: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

IsNumeric‘declare a variable to store the ageDim Age as Integer

‘test the data typed in the text box to see if it is a numberIf IsNumeric(txtAge.Text)=True Then

‘if it is ok read in the valueAge = txtAge.Text

Else‘if not ok then show an errorlblError.Text = "The age is not valid"

End If

Page 20: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

NoteThe next set of examples won’t be needed

until driving test 3 (after Christmas)Look at the code and start to get an

understanding of what it doesDon’t worry if it makes no sense at first we

will come back to this later on in the module

Page 21: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

IsDate‘declare a variable to store the date of birthDim DOB as Date

‘test the data typed in the text box to see if it is a dateIf IsDate(txtDOB.Text)=True Then

‘if it is ok read in the valueDOB = txtDOB.Text

Else‘if not ok then show an errorlblError.Text = "The date of birth is not a

valid date"End If

Page 22: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

Testing for a blank field (=“”)‘declare a variable to store first nameDim FirstName as String

‘test the data typed in the text box to see if it isn’t blankIf txtFirstName.Text<>"" Then

‘if it is ok read in the valueFirstName = txtFirstName.Text

Else‘if not ok then show an errorlblError.Text = "You must enter your first

name."End If

Page 23: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

Testing Number of Characters (Len)‘declare a variable to store first nameDim FirstName as String

‘test the data typed in the text box is not over 20 charactersIf Len(txtFirstName.Text)<=20 Then

‘if it is ok read in the valueFirstName = txtFirstName.Text

Else‘if not ok then show an errorlblError.Text = "First name must not exceed

20 letters."End If

Page 24: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

Validating an Email Address (InStr)‘declare a variable to store the email addressDim EMail as String

‘test the data typed in the text box has an @ symbolIf InStr(txtEMail.Text, "@") >0 Then

‘if it is ok read in the valueEMail = txtEMail.Text

Else‘if not ok then show an errorlblError.Text = "Not a valid email

address."End If

Question – What is the problem with the above code?

Page 25: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

The problem is…that the following are all valid email addresses..

fred@@fred@@@@@@@@@@@@

Page 26: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

An Email Address Must Have… “@” symbol e.g. @hotmail.com

“.” symbol e.g. hotmail.com

At least 5 characters (?)

Page 27: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

(What is wrong with the following if we use fred@nothing ?) Dim EMail as String

‘test the data typed in the text box has an @ symbolIf InStr(txtEMail.Text, "@") >0 Then

EMail = txtEMail.TextElse

lblError.Text = "Not a valid email address." End If

‘test the address is long enoughIf Len(txtEMail.Text) >5 Then

EMail = txtEMail.TextElse

lblError.Text = "The address is too short." End If

‘test the data typed in the text box has an . symbolIf InStr(txtEMail.Text, ".") >0 Then

EMail = txtEMail.TextElse

lblError.Text = "Not a valid email address." End If

Page 28: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

Better???

‘declare a variable to store the email address Dim EMail as String

‘test the data typed in the text box has an @ symbolIf InStr(txtEMail.Text, "@") >0 Then

‘test the address is long enoughIf Len(txtEMail.Text) >5 Then

‘test the data typed in the text box has an . symbol

If InStr(txtEMail.Text, ".") >0 Then‘if it is ok read in the valueEMail = txtEMail.Text

ElselblError.Text = "Not a valid email

address." End If

ElselblError.Text = "The address is too short."

End IfElse

lblError.Text = "Not a valid email address no @ symbol."

End If

Page 29: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

Or….

‘declare a variable to store the email address Dim EMail as String

‘clear the error message labellblError.Text = ""‘test the data typed in the text box has an @ symbolIf InStr(txtEMail.Text, "@") = 0 Then

lblError.Text = "No @ symbol." End If

‘test the address is long enoughIf Len(txtEMail.Text) <=5 Then

lblError.Text = lblError.Text & " The address is too short."

End If‘test the data typed in the text box has a . symbolIf InStr(txtEMail.Text, ".") = 0 Then

lblError.Text = lblError.Text & "No dot." End If If lblError.Text = "" Then Email = txtEmail.Text End IF

Page 30: Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1

Validation Function ExamplesAssuming we have two variables…

Dim OK as BooleanDim SomeValue as Integer

What values would be assigned in the following?...OK = IsNumeric(“Hello”)OK = IsDate(“1 Feb 2012”)SomeValue = Len(“Help!”)SomeValue = InStr(“[email protected]”, "@")