Mark Dixon, SoCCE SOFT 131Page 1 19 – Procedure Parameters.

Slides:



Advertisements
Similar presentations
Mark Dixon, SoCCE SOFT 131Page 1 15 – Object Oriented Analysis, Design, and Programming.
Advertisements

Mark Dixon, SoCCE SOFT 131Page 1 22 – Object Oriented Analysis, Design, and Programming.
Mark Dixon, SoCCE SOFT 131Page 1 09 – Procedures.
Mark Dixon Page 1 22 – Object Oriented Programming in ASP.
Mark Dixon, SoCCE SOFT 131Page 1 22 – Visual BASIC 2005.
Mark Dixon, SoCCE SOFT 136Page 1 05 – Conditional Execution.
Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.
Mark Dixon, SoCCE SOFT 136Page 1 11 – User Defined Functions.
Mark Dixon, SoCCE SOFT 131Page 1 13 – Object Oriented Analysis, Design, and Programming.
Mark Dixon, SoCCE SOFT 131Page 1 07 – Iterative Execution.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Expressions, Operators & Functions.
Write a program that allows a user to enter information relating to the name and salary details of an employee The user should be able to enter the name.
Mark Dixon, SoCCE SOFT 131Page 1 06 – Iteration. Mark Dixon, SoCCE SOFT 131Page 2 Session Aims & Objectives Aims –Revise Variables and Conditional execution.
Mark Dixon, SoCCE SOFT 131Page 1 10 – Enumerated Data Types & Procedure Parameters.
Mark Dixon, SoCCE SOFT 131Page 1 15 – Object Associations.
Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging & Graphics.
Mark Dixon, SoCCE SOFT 131Page 1 06 – Iteration. Mark Dixon, SoCCE SOFT 131Page 2 Session Aims & Objectives Aims –To introduce the main concepts involved.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Data-types, Variables, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 07 – Constants, Arrays, & Structures.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Object Associations.
Mark Dixon Page 1 21 – Object Oriented Programming in ASP.
Mark Dixon, SoCCE SOFT 131Page 1 08 – Procedures.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Software Development Lifecycle, & User Interface Design.
Mark Dixon, SoCCE SOFT 131Page 1 10 – Variable Scope, and Arrays of Structures.
Mark Dixon, SoCCE SOFT 131Page 1 08 – Iterative Execution.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Passing Data between pages: Sessions, Query Strings, & Self Posting.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Conditional Execution.
Mark Dixon Page 1 02 – Queries: Query by Example.
Mark Dixon, SoCCE SOFT 131Page 1 10 – User Defined Functions.
Mark Dixon, SoCCE SOFT 131Page 1 12 – Enumerated Data-Types & Pass-by-reference.
Mark Dixon, SoCCE SOFT 131Page 1 13 – Control Arrays & Container Controls.
Mark Dixon, SoCCE SOFT 136Page 1 06 – Information Processing: Data-types, Constants, Variables.
Mark Dixon, SoCCE SOFT 131Page 1 09 – User Defined Procedures: Scope, and Parameters.
Mark Dixon, SoCCE SOFT 131Page 1 11 – Arrays of Structures & Modules.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Information Processing: Data-types, Variables, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 20 – Web applications: Writing data to Databases using ASP.
Tutorial 7: Sub and Function Procedures1 Tutorial 7 Sub and Function Procedures.
Mark Dixon Page 1 10 – Iterative Execution. Mark Dixon Page 2 Questions: Variables Write a line of code to declare a variable called h Write a line of.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
Mark Dixon Page 1 24 – Object Oriented Programming in ASP.
Mark Dixon 1 22 – Web applications: Writing data to Databases using ASP.Net.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using ASP.
Mark Dixon Page 1 09 – Arrays. Mark Dixon Page 2 Questions: Loops What is the value of t, after this code executes? t = 0 For x = 4 To 6 t = t + x Next.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Mark Dixon, SoCCE SOFT 136Page 1 9 – Procedures. Mark Dixon, SoCCE SOFT 136Page 2 Session Aims & Objectives Aims –To introduce the main concepts involved.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Dynamic HTML (client-side scripting)
Mark Dixon 1 11 – Array Variables. Mark Dixon 2 Questions: Loops What is the value of t, after this code executes? t = 0 For x = 4 To 6 t = t + x Next.
Mark Dixon, SoCCE SOFT 136Page 1 SOFT – Module Introduction & Overview.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Variables. Mark Dixon, SoCCE SOFT 131Page 2 Admin: Test (next week) In class test –teaching week 6 –university week.
Arrays1 From time to time an object (a variable, a picture, a label or a command) does not serve as well as a set of objects of a similar kind addressed.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Object Associations.
Mark Dixon, SoCCE SOFT 131Page 1 24 – Datatypes and Object Association.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Dynamic HTML (client-side scripting)
Mark Dixon, SoCCE SOFT 131Page 1 16 – Visual BASIC 6.0.
Mark Dixon 1 9 – Case Study. Mark Dixon 2 Session Aims and Objectives Aims –To give an overview of the development of a web-page from initial idea to.
Mark Dixon, SoCCE SOFT 131Page 1 18 – Enumerated Data Types and Arrays of Structures.
Pay Example (PFirst98) Please use speaker notes for additional information!
Mark Dixon SOFT 131Page 1 12 – Object Oriented Analysis, Design, and Programming.
Mark Dixon 1 22 – Object Oriented Programming. Mark Dixon 2 Questions: Databases How many primary keys? How many foreign keys? 3 2.
Mark Dixon Page 1 15 – Structured Programming. Mark Dixon Page 2 Admin: Coursework 3 – Test In class test –9 Feb 2010 –2 Feb 2010: revision (technique)
Mark Dixon, SoCCE SOFT 131Page 1 12 – Databases: Structured Query Language.
Mark Dixon, SoCCE SOFT 131Page 1 17 – Procedures.
Mark Dixon 1 15 – Structured Programming. Mark Dixon 2 Admin: Test 2 In class test –11 Feb 2014 –4 Feb 2014: revision (technique) session 50 mins short.
Mark Dixon 1 13 – Parameters. Mark Dixon 2 Question: Arrays How many array variables are in the following code: Dim x Dim y Dim f(4) x = 12 y = 6 f(2)
Adding Code to the Option Button. Open VB 1.Double click the Calculate button and select General from the Object list box. 2.Add the following code to.
Mark Dixon, SoCCE SOFT 131Page 1 25 – Soft 131 Examination Revision.
Mark Dixon Page 1 09 – Iterative Execution. Mark Dixon Page 2 Questions: Variables Write a line of VBScript code to declare a variable called h Write.
Mark Dixon, SoCCE SOFT 136Page 1 08 – Arrays & Structures.
11 – Enumerated Data Types, & Procedure Parameters
Presentation transcript:

Mark Dixon, SoCCE SOFT 131Page 1 19 – Procedure Parameters

Mark Dixon, SoCCE SOFT 131Page 2 Session Aims & Objectives Aims, to introduce: –passing parameters/arguments to procedures Objectives, after this week’s sessions, you should be able to: –use parameters in your programs to make procedures more flexible

Mark Dixon, SoCCE SOFT 131Page 3 Parameters in Event Procedures Provide us with information about event –e.g. if mouse was clicked where was it (x, and y co-ordinates) which mouse button was pressed which keyboard buttons were pressed ([Shift] / [Ctrl])

Mark Dixon, SoCCE SOFT 131Page 4 Example: Draw Option Explicit Private Sub picDraw_MouseDown( Button As Integer, Shift As Integer, X As Single, Y As Single ) If Button = 1 Then picDraw.PSet (X, Y) End If End Sub Private Sub picDraw_MouseMove( Button As Integer, Shift As Integer, X As Single, Y As Single ) If Button = 1 Then picDraw.Line -(X, Y) End If End Sub Parameters: –appear in the brackets of a procedure definition horizontal & vertical mouse co-ordinates mouse button keyboard [Shift] [Ctrl] keys

Mark Dixon, SoCCE SOFT 131Page 5 Parameters/Arguments (what) Sometimes our own procedures need information –Making a cup of tea: milk, and number of sugars Makes them more flexible Make cup of tea Milk Sugars

Mark Dixon, SoCCE SOFT 131Page 6 Parameters (how) Procedure Declaration –Formal parameters define name & type Procedure Call –actual parameters list values in order Option Explicit Dim res As Long Private Sub Calc(Num1 As Long, Num2 As long) res = Num1 * Num2 End Sub Private Sub btnCalc_Click() Calc 5, 2 Calc 11, 15 End Sub

Mark Dixon, SoCCE SOFT 131Page 7 Parameters (how)

Mark Dixon, SoCCE SOFT 131Page 8 Example: House v1 Option Explicit Private Sub btnDraw_Click() picHouse.Cls picHouse.Line (1000, 1000)-(2000, 1750),, B picHouse.Line (1000, 1000)-(1500, 750) picHouse.Line -(2000, 1000) End Sub House v1

Mark Dixon, SoCCE SOFT 131Page 9 Example: House v1 to v2 Option Explicit Private Sub btnDraw_Click() picHouse.Cls picHouse.Line (1000, 1000)-(2000, 1750),, B picHouse.Line (1000, 1000)-(1500, 750) picHouse.Line -(2000, 1000) End Sub Option Explicit Private Sub DrawHouse() picHouse.Line (1000, 1000)-(2000, 1750),, B picHouse.Line (1000, 1000)-(1500, 750) picHouse.Line -(2000, 1000) End Sub Private Sub btnDraw_Click() picHouse.Cls DrawHouse End Sub House v1House v2

Mark Dixon, SoCCE SOFT 131Page 10 Example: House v2 Option Explicit Private Sub DrawHouse() picHouse.Line (1000, 1000)-(2000, 1750),, B picHouse.Line (1000, 1000)-(1500, 750) picHouse.Line -(2000, 1000) End Sub Private Sub btnDraw_Click() picHouse.Cls DrawHouse End Sub House v2

Mark Dixon, SoCCE SOFT 131Page 11 Example: House v3 Option Explicit Private Sub DrawHouse(x As Single, y As Single) picHouse.Line (x, y)-(x , y + 750),, B picHouse.Line (x, y)-(x + 500, y - 250) picHouse.Line -(x , y) End Sub Private Sub btnDraw_Click() picHouse.Cls DrawHouse 1000, 1000 DrawHouse 2500, 1000 DrawHouse 4000, 1000 End Sub House v3

Mark Dixon, SoCCE SOFT 131Page 12 Questions: Parameters Given the following declaration: What will the following put in lblOutput? Sub thing(Num1 As Long, Num2 As Long, Num3 As Long) Dim tmpOutput As Long tmpOutput = (Num1 + Num2) * Num3 lblOutput.Caption = tmpOutput End Sub thing 2, 3, 6 thing 6, 3, 2 thing 20, 5,

Mark Dixon, SoCCE SOFT 131Page 13 Example: Till v1 Option Explicit Dim SubTotal As Double Dim Total As Double Private Sub btnEquals_Click() Dim price As Double Dim quantity As Double price = Val(Me.txtPrice.Text) quantity = Val(Me.txtQuantity.Text) SubTotal = price * quantity lblSubTotal.Caption = "£" & SubTotal End Sub Private Sub btnAdd_Click() Total = Total + SubTotal lblTotal.Caption = "£" & Total End Sub Private Sub btnUndo_Click() Total = Total - SubTotal lblTotal.Caption = "£" & Total End Sub Till v1

Mark Dixon, SoCCE SOFT 131Page 14 amount: Double Example: Till v2 Option Explicit Dim SubTotal As Double Dim Total As Double Private Sub TotalAdd(amount As Double) Total = Total + amount Me.lblTotal.Caption = "£" & Total End Sub Private Sub btnEquals_Click() Dim price As Double Dim quantity As Double price = Val(Me.txtPrice.Text) quantity = Val(Me.txtQuantity.Text) SubTotal = price * quantity lblSubTotal.Caption = "£" & SubTotal End Sub Private Sub btnAdd_Click() TotalAdd SubTotal End Sub Private Sub btnUndo_Click() TotalAdd -SubTotal End Sub TotalAdd Till v2

Mark Dixon, SoCCE SOFT 131Page 15 Example: Heart Rate v3 Option Explicit Dim HR(0 To 6) As Long Private Sub Form_Load() HR(0) = 134 HR(1) = 127 HR(2) = 139 HR(3) = 155 HR(4) = 143 HR(5) = 151 HR(6) = 141 End Sub Private Sub DrawHR() Dim i As Long picMain.Cls For i = 0 To 6 picMain.Line -(i * 500, HR(i) * 10) Next End Sub Private Sub btnDraw_Click() DrawHR End Sub

Mark Dixon, SoCCE SOFT 131Page 16 Example: Heart Rate v4 Option Explicit Dim HR(0 To 6) As Long Private Sub Form_Load() HR(0) = 134 HR(1) = 127 HR(2) = 139 HR(3) = 155 HR(4) = 143 HR(5) = 151 HR(6) = 141 End Sub Private Sub DrawHR(picTemp As PictureBox) Dim i As Long picTemp.Cls For i = 0 To 6 picTemp.Line -(i * 500, HR(i) * 10) Next End Sub Private Sub btnDraw_Click() DrawHR Me.picMain1 DrawHR Me.picMain2 End Sub

Mark Dixon, SoCCE SOFT 131Page 17 Tutorial Exercise: Draw LEARNING OBJECTIVE: –use parameters provided by event procedures Task 1: Get the Draw example (from the lecture) working. Task 2: Modify your code – allow the user to rub out (paint in the background colour) using the right mouse button. Task 3: Modify your code – allow the user to use a thicker line by holding down the [ctrl] button on the keyboard

Mark Dixon, SoCCE SOFT 131Page 18 Tutorial Exercise: House LEARNING OBJECTIVE: –use parameters in your own procedures, to make them more flexible (general purpose) Task 1: Get the House examples (versions 1, 2, and 3) from the lecture working. Task 2: Modify your code – add code that draws a door and a window for each house. Task 3: Modify your code – add code that draws 10 small houses. Hint: use a for loop (rather than simply copying the procedure calls)

Mark Dixon, SoCCE SOFT 131Page 19 Tutorial Exercise: Till LEARNING OBJECTIVE: –use parameters in your own procedures, to make them more flexible (general purpose) Task 1: Get the Till examples (versions 1 and 2) from the lecture working. Task 2: Modify your code – add code that clears all data when the clear button is clicked. Task 3: Modify your code – create a procedure to calculate and display the sub total.

Mark Dixon, SoCCE SOFT 131Page 20 Tutorial Exercise: Heart Rate LEARNING OBJECTIVE: –use parameters in your own procedures, to make them more flexible (general purpose) Task 1: Get the Heart Rate examples (versions 3 and 4) from the lecture working. Task 2: Modify your code – use additional parameters to control the horizontal and vertical sizes of the graphs (so that the two graphs can be different sizes).