Presentation is loading. Please wait.

Presentation is loading. Please wait.

Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1.

Similar presentations


Presentation on theme: "Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1."— Presentation transcript:

1

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

3 1. Documentation & Organisation Comments Block 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

4 2. Events and Handlers The user triggers an event e.g. click The handler contains some code that does something when that event happens Code executes in sequence from line 1 to line n

5 3. Objects Allow us to control the computer without worrying about the complexity under the lid Objects 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

6 4. Variables & Assignment Simple object that controls the RAM Declare 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

7 5. Functions and Parameters Functions perform a predefined task and return a value Parameters (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 lecture Functions 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

8

9 Sequence v Selection Sequence describes the code executing line by line Selection is about making decisions Selecting one block of code Or Selecting a different block of code Handled by If Statements

10 The If Statement If condition Then ‘execute the code here End If

11 Else

12 Conditions Relational operators >If a > b Then =If a >= b Then <=If a <= b Then Equality and Inequality operators =If a = b Then <>If a<>b Then

13 When is an Assignment Operator not an Assignment Operator? All about context “The jelly is nearly set.” And “The badger returns to its set.”

14 ElseIf

15 If Statements in Action We shall look at the code for GPE

16 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

17 Validation Create software that is Robust (doesn’t crash) Responsive (Tells us what went wrong) Consider the following code Dim FirstName as Integer FirstName=”Fred”

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

19 IsNumeric ‘declare a variable to store the age Dim Age as Integer ‘test the data typed in the text box to see if it is a number If IsNumeric(txtAge.Text)=True Then ‘if it is ok read in the value Age = txtAge.Text Else ‘if not ok then show an error lblError.Text = "The age is not valid" End If

20 Note The 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 does Don’t worry if it makes no sense at first we will come back to this later on in the module

21 IsDate ‘declare a variable to store the date of birth Dim DOB as Date ‘test the data typed in the text box to see if it is a date If IsDate(txtDOB.Text)=True Then ‘if it is ok read in the value DOB = txtDOB.Text Else ‘if not ok then show an error lblError.Text = "The date of birth is not a valid date" End If

22 Testing for a blank field (=“”) ‘declare a variable to store first name Dim FirstName as String ‘test the data typed in the text box to see if it isn’t blank If txtFirstName.Text<>"" Then ‘if it is ok read in the value FirstName = txtFirstName.Text Else ‘if not ok then show an error lblError.Text = "You must enter your first name." End If

23 Testing Number of Characters (Len) ‘declare a variable to store first name Dim FirstName as String ‘test the data typed in the text box is not over 20 characters If Len(txtFirstName.Text)<=20 Then ‘if it is ok read in the value FirstName = txtFirstName.Text Else ‘if not ok then show an error lblError.Text = "First name must not exceed 20 letters." End If

24 Validating an Address (InStr) ‘declare a variable to store the address Dim as String ‘test the data typed in the text box has symbol If InStr(txt .Text, >0 Then ‘if it is ok read in the value = txt .Text Else ‘if not ok then show an error lblError.Text = "Not a valid address." End If Question – What is the problem with the above code?

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

26 An Address Must Have… symbol “. ” symbol e.g. hotmail.com At least 5 characters (?)

27 (What is wrong with the following if we use ?) Dim as String ‘test the data typed in the text box has symbol If InStr(txt .Text, >0 Then = txt .Text Else lblError.Text = "Not a valid address." End If ‘test the address is long enough If Len(txt .Text) >5 Then = txt .Text Else lblError.Text = "The address is too short." End If ‘test the data typed in the text box has an. symbol If InStr(txt .Text, ".") >0 Then = txt .Text Else lblError.Text = "Not a valid address." End If

28 Better??? ‘declare a variable to store the address Dim as String ‘test the data typed in the text box has symbol If InStr(txt .Text, >0 Then ‘test the address is long enough If Len(txt .Text) >5 Then ‘test the data typed in the text box has an. symbol If InStr(txt .Text, ".") >0 Then ‘if it is ok read in the value = txt .Text Else lblError.Text = "Not a valid address." End If Else lblError.Text = "The address is too short." End If Else lblError.Text = "Not a valid address symbol." End If

29 Or…. ‘declare a variable to store the address Dim as String ‘clear the error message label lblError.Text = "" ‘test the data typed in the text box has symbol If InStr(txt .Text, = 0 Then lblError.Text = symbol." End If ‘test the address is long enough If Len(txt .Text) <=5 Then lblError.Text = lblError.Text & " The address is too short." End If ‘test the data typed in the text box has a. symbol If InStr(txt .Text, ".") = 0 Then lblError.Text = lblError.Text & "No dot." End If If lblError.Text = "" Then = txt .Text End IF

30 Validation Function Examples Assuming we have two variables… Dim OK as Boolean Dim SomeValue as Integer What values would be assigned in the following?... OK = IsNumeric(“Hello”) OK = IsDate(“1 Feb 2012”) SomeValue = Len(“Help!”) SomeValue =


Download ppt "Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1."

Similar presentations


Ads by Google