score sequence choices to be made once may not be enough reuse and recycle evaluate and improve

16

Upload: alexander-logan

Post on 20-Jan-2018

214 views

Category:

Documents


0 download

DESCRIPTION

We use procedures all of the time The fire drill on the wall A recipe in a cook book They are set up in advance We use (call) them only as and when we need them

TRANSCRIPT

Page 1: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve
Page 2: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

SCORESequenceChoices to be madeOnce may not be enoughReuse and recycleEvaluate and improve

Page 3: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

We use procedures all of the timeThe fire drill on the wallA recipe in a cook book

They are set up in advanceWe use (call) them only as and when we need

them

Page 4: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

Procedures in ASP.NETProcedure

Name

Code for the

procedure

Page 5: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

It doesn’t matter how it works…So long as we know …

What the procedure does.

And

How to call the procedure.

In this case Call DisplayArray

Will draw the contents of the connect four game on the page.

Page 6: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

Event ProceduresFor example, whenever you write the code

for a button, you are writing the code inside an event procedure.

E.g.

Private Sub btnOK_Click(ByVal sender As etc…

'code for the click event goes hereEnd Sub

Page 7: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

Creating a Sub ProcedureMake sure

you are not creating a procedure inside a procedure!

Page 8: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

One place you could use…

Page 9: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

1. Start by typing …

2. Then press Enter…

3. Type your procedure code…

4. Call your procedure…

Page 10: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

The Benefits of ProceduresGives greater functionalityHides complexityPromotes code re-useSimplifies maintenance

Page 11: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

Gives greater functionality

We don’t need to write this code over and over again…

Page 12: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

We call it with a single line of code..

Call DisplayArray

Page 13: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

Hides complexityCall DisplayArray

Is very easy to typeVery simple to understand

Call DisplayArray =

Page 14: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

Promotes code re-use(Library code)The code for connect four could be used

again in a game of noughts and crosses

Smart programmers build up code libraries so that useful procedures may be “recycled”

Page 15: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

Simplifies maintenanceIf the code for a certain task exists only once

in a program

E.g. DisplayArray

Any changes to that one procedure are passed on to all the places in the program that call it.

Modifications and error corrections only need to be done once – within the procedure itself.

Page 16: SCORE Sequence Choices to be made Once may not be enough Reuse and recycle Evaluate and improve

Flow of the code…Using the debugger we shall examine how the following code works when it calls the different procedures