Chapter 4 (cont) Sec. 4.1, 4.2, 4.4 Procedures (User-defined)

Slides:



Advertisements
Similar presentations
Subprograms Functions Procedures. Subprograms A subprogram separates the performance of some task from the rest of the program. Benefits: “Divide and.
Advertisements

Sub and Function Procedures
1 5.3 Sub Procedures, Part II Passing by Value Passing by Reference Sub Procedures that Return a Single Value Debugging.
REPETITION (loops or iteration) Schneider: Sec. 6.1 & 6.3.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
VBA Modules, Functions, Variables, and Constants
Chapter 6: User-Defined Functions I
Chapter 4 - Visual Basic Schneider
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
Chapter 4 - VB.Net by Schneider1 Chapter 4 General Procedures 4.1 Sub Procedures, Part I 4.2 Sub Procedures, Part II 4.3 Function Procedures 4.4 Modular.
Chapter 41 Sub Procedures, Part II Passing by Value Passing by Reference Local Variables Class-Level Variables Debugging.
Chapter 6: User-Defined Functions I
Chapter 7: Sub and Function Procedures
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Chapter 41 General Procedures Sub Procedures, Part I Sub Procedures, Part II Function Procedures.
Chapter 4 Sec. 4.1, 4.2, 4.4 Procedures (User-defined)
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
Apply Sub Procedures/Methods and User Defined Functions
1 INF110 Visual Basic Programming AUBG Spring semester 2011 Reference books: Schneider D., An Introduction to Programming Using Visual Basic, Prentice.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
Subroutines and Functions Chapter 6. Introduction So far, most of the code has been inside a single method for an event –Fine for small programs, but.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Chapter 5 - VB 2008 by Schneider1 Chapter 5 - General Procedures 5.1 Sub Procedures, Part I 5.2 Sub Procedures, Part II 5.3 Function Procedures 5.4 Modular.
Visual Basic I Programming
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
CS0004: Introduction to Programming Subprocedures and Modular Design.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
1 Chapter 5 - General Procedures 5.1 Function Procedures 5.2 Sub Procedures, Part I 5.3 Sub Procedures, Part II 5.4 Modular Design.
Subroutines and Functions. Introduction So far, most of the code has been inside a single method for an event –Fine for small programs, but inconvenient.
Sub procedures School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 6, Friday 2/21/03)
Subprograms CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Chapter 6 Sub Procedures
Chapter 9: Writing Procedures Visual Basic.NET Programming: From Problem Analysis to Program Design.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
‘Tirgul’ # 2 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #2.
Structure Programming Lecture 8 Chapter 5&6 - Function – part I 12 December 2015.
Lecture 10: Modular Programming (functions) B Burlingame 13 April 2015.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School Unit 2 Software Development Process Topic.
Functions Chapter 6. Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules Function: a collection.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
1Edited By Maysoon Al-Duwais. 2 General Procedures Function Procedure Sub Procedures, Part I Sub Procedures, Part II Modular Design Edited By Maysoon.
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Sub Procedures; Passing Values Back From Sub Procedures Passing by reference Passing by value.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
General Procedures Chapter 4. Different Procedures 4.1 Sub Procedures, Part I 4.2 Sub Procedures, Part II 4.3 Function Procedures 4.4 Modular Design (not.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
Subroutines and Functions Chapter 6. Introduction So far, all of the code you have written has been inside a single procedure. –Fine for small programs,
1Edited By Maysoon Al-Duwais. 2 Devices for Modularity Visual Basic has two ways for breaking problems into smaller pieces: Sub procedures Function procedures.
Sub Procedures and Functions Visual Basic. Sub Procedures Slide 2 of 26 Topic & Structure of the lesson Introduction to Modular Design Concepts Write.
 2007 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1Lect7 GC20111/2/ General Procedures Function Procedure Sub Procedures, Part I Sub Procedures, Part II Modular Design Lect7 GC20111/2/2015.
Visual Basic I Programming
Subprograms Functions Procedures.
Chapter 6: User-Defined Functions I
Object-Oriented Programming: Classes and Objects
Chapter 8: Writing Graphical User Interfaces
Functions Chapter 6-Part 2.
Chapter 4 - Visual Basic Schneider
Chapter 6 Sub Procedures
Programming Logic and Design Fourth Edition, Comprehensive
Chapter#8 General Procedures
CHAPTER 17 The Report Writer Module
Chapter (3) - Procedures
Presentation transcript:

Chapter 4 (cont) Sec. 4.1, 4.2, 4.4 Procedures (User-defined)

Well-designed programs... §consist of highly modular code §have procedures that pass data between them l data is passed to & from the calling procedure in the form of arguments l a procedure declares parameters to represent each argument that is sent to it §have other important features but our focus here is on procedures...

Relationship between arguments & parameters... §Where are they declared? l Arguments are declared in the calling procedure. l Parameters are declared in the procedure in the procedure header. §How must they correspond? l They must be in with respect to their placement in the procedure call (arguments) & procedure header (parameters)... perfect agreement

Perfect agreement means... §#arguments in the call = #parameters in the procedure header §the type of an argument = the type of its corresponding parameter

Passing values back from procedures OUTPUT parameters §If you want a procedure to change the value of an argument, you must use a variable for that argument. §When this happens, we say that the corresponding parameter is serving as an output parameter. §Often a parameter is used for both input & output

Passing by value §Sometimes we want to send a variable argument to a procedure, but we want to ensure that the variable will retain its original value after the procedure has terminated. §In the parameter list of the procedure: Private Sub Triple (ByVal num As Single)

What arguments & parameters look like... §Arguments may be: l constants - used to send values to a procedure l variables - used to send values to a procedure and/or to receive values back from a procedure l expressions - used to send values to a procedure §Parameters must be: l variables - declared by mini-declarations in the procedure header parameter list

What can be accomplished within a procedure?

To be more dignified... §From now on, your event procedures should be designed in a modular fashion, consisting of calls to procedures that you create & define. §You may use any Visual Basic instructions you know within a procedure that you write.

Local variables §Declare variables for use in your procedures for the same reason you would declare them in an event procedure: l to receive input, or l to receive an intermediate result §Ex. 4, p. 146 l local variable is rawDensity

Once you decide on the procedures you need... §Name your procedures appropriately l use descriptive names §You must determine l what input your procedure requires l what output your procedure requires §These input & output items become the parameters

Examples... §Let’s write our own... l p. 162 #54 - use two procedures: getinput (job, amount, tiprate) show output (job, amt, rate)

Assignment... §Lab work l VB projects - pp , 2, 6 l Written work: p. 151: 4, 10, 12, 22, 26, 34 p. 171: 2-10 (even), 15, 18 §Homework Due Tuesday l VB projects: p , 32 l Read all of Chapter 4, esp. Sec. 4.3 (functions)