Promoting Code Reuse Often in programming, multiple procedures will perform the same operation IN OTHER WORDS – the same piece of code will do the same.

Slides:



Advertisements
Similar presentations
Chapter 6, Slide 1Starting Out with Visual Basic 3 rd Edition Chapter 6 Sub Procedures And Functions.
Advertisements

Sub and Function Procedures
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Writing General Procedures Often you will encounter programming situations in which multiple procedures perform the same operation This condition can occur.
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA By Robert T. Grauer Maryann Barber.
VBA Modules, Functions, Variables, and Constants
Example 2.
Chapter 4 - Visual Basic Schneider
Exploring Office Grauer and Barber 1 Creating More Powerful Applications: Introduction to VBA(Wk9)
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Scope of Variables and Constants A Variable or Constant may exist and be Visible for an entire project, for only one form, or for only one procedure Therefore,
Scope of Variables and Constants A Variable or Constant may exist and be Visible for an entire project, for only one form, or for only one procedure Therefore,
VB – Core III Functions Sub-routines Parameter passing Modules Scope Lifetime.
Chapter 4 Sec. 4.1, 4.2, 4.4 Procedures (User-defined)
Apply Sub Procedures/Methods and User Defined Functions
IE 212: Computational Methods for Industrial Engineering
XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter.
Automating Tasks with Visual Basic. Introduction  When can’t find a readymade macro action that does the job you want, you can use Visual Basic code.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Enhancing User Interaction Through Programming
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 6 Multiple Forms.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
Why to Create a Procedure
Using Arrays and File Handling
5-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
CPS120: Introduction to Computer Science Functions.
IMS 3253: Subroutines 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Procedures Subroutines Parameters –By Value.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Sub Procedures. A Sub procedure is a block of code that is executed in response to an event. There are two types of Sub procedures, general procedures.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Debugging, Static Variables, ByRef, ByValue Chapt. 6 in Deitel, Deitel and Nieto.
Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School Unit 2 Software Development Process Topic.
Visual Basic CDA College Limassol Campus COM123 Visual Programming 1 Semester B Lecture:Pelekanou Olga Week 5: Useful Functions and Procedures.
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
Understanding Visual Basic Fundamentals CHAPTER 13 Understanding Visual Basic Fundamentals.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
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,
Visual Basic.NET BASICS Lesson 9 Nested If Statements and Radio Buttons.
What Are Subprograms? Subprograms are named PL/SQL blocks that can take parameters and be invoked. Subprograms allow decomposition of a program into logical.
Multiple Forms and Menus
Development Environment
13 Enhancing the Wage Calculator App
UNIT - V STORED PROCEDURE.
Microsoft Access 2003 Illustrated Complete
Microsoft Access Illustrated
Object-Oriented Programming: Classes and Objects
Variables and Arithmetic Operations
Chapter 4 - Visual Basic Schneider
Tonga Institute of Higher Education
CS285 Introduction - Visual Basic
Functions Christopher Harrison | Content Developer
Tonga Institute of Higher Education
Chapter 8 - Functions and Functionality
Brief description on how to navigate within this presentation (ppt)
Presentation transcript:

Promoting Code Reuse Often in programming, multiple procedures will perform the same operation IN OTHER WORDS – the same piece of code will do the same thing somewhere else in the application Rather than retyping the code twice (or even more than twice….), code can be written in a general (sub/function) procedure and can be called into use from other procedures (therefore promoting reuse)

Promoting Code Reuse Click each command button triggering the click event procedure associated with each one

Promoting Code Reuse Now when we click on the hello command button we trigger the click event procedure associated with that command button but also call the other procedures which execute in turn producing the same output

Creating a ‘Sub Procedure’ The coding of a new procedure is similar to the other event procedures that we have been coding, but is not in itself attached to any event Therefore, this code cannot be executed unless a CALL is specified from another procedure, for the General Sub Procedure To call a Sub Procedure, just give the procedure name

Creating a ‘Sub Procedure’ 2 ways to create a General Sub Procedure [1] simply type in the procedure definition in the code window [2] use the tools / add procedure menu command

Type sub myprocedure and press return on the keyboard and the procedure is created

Very Important - visibility Sub procedures are by default Public in all modules, which means they can be called from anywhere in the application So what is the scope of this newly created procedure?

Very Important - visibility So you should put the PRIVATE keyword in front of the sub keyword to reduce the procedures visibility

tools / add procedure menu command

Creating a ‘Sub Procedure’ The Sub statement declares the name, arguments, and code that will form the body of a subroutine / sub procedure as follows: [Private | Public] Sub ProcedureName [(arguments)] statements End Sub

Advantages of a ‘Sub Procedure’ Code is easier to write and debug - test individual modules Code is maintainable Improves code structure Decreases the size of individual procedures and often the size of the program itself Disadvantages of a ‘Sub Procedure’ Requires extra preparatory work Need to understand logical design of code structure May require more CPU time and memory

Calling a ‘Sub Procedure’ The use of the keyword Call is optional but required in certain cases: ProcedureName Call ProcedureName Call ProcedureName ( ) An Event Procedure can also be called Command1_Click Call Command1_Click Call Command1_Click ( )

Scope of Variables: General Sub Procedures Example 1

Scope of Variables: General Sub Procedures