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.

Slides:



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

Subprograms Functions Procedures. Subprograms A subprogram separates the performance of some task from the rest of the program. Benefits: “Divide and.
Sub and Function Procedures
Spring Semester 2013 Lecture 5
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
1.
1 CS 106, Winter 2009 Class 11, Section 4 Slides by: Dr. Cynthia A. Brown, Instructor section 4: Dr. Herbert G. Mayer,
Passing Arguments Question Example: IS1102 Exam Autumn 2001.
Chapter 4 General Procedures
VBA Modules, Functions, Variables, and Constants
Chapter 4 - Visual Basic Schneider
Introduction to Computing Dr. Nadeem A Khan. Lecture 17.
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 (Continue). Chapter 42 Local Variable A variable declared inside a Sub procedure with a Dim statement Space reserved.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
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.
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)
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
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.
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.
Why to Create a Procedure
InvEasy (Project1) Please use speaker notes for additional information!
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 7 Sub and Function Procedures.
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.
Visual Basic CODE. Basics of Code Declaration Declaration Set aside a named place to put things Set aside a named place to put things Assignment Assignment.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 10: Chapter 6: Slide 1 Unit 10 Sub Procedures and Functions Chapter 6 Sub.
Procedural Programming Criteria: P2 Task: 1.2 Thomas Jazwinski.
Arrays and others. Annoucement Today’s office hour move to Friday 1:00PM to 3:00PM Today’s office hour move to Friday 1:00PM to 3:00PM Today Today  Call.
Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School Unit 2 Software Development Process Topic.
Modularity using Functions Chapter 4. Modularity In programming blocks of code often can be "called up" and reused whenever necessary, for example code.
FUNCTION Functions is a sub-program that contains one or more statements and it performs some task when called.
Visual Basic CDA College Limassol Campus COM123 Visual Programming 1 Semester B Lecture:Pelekanou Olga Week 5: Useful Functions and Procedures.
Sub Procedures; Passing Values Back From Sub Procedures Passing by reference Passing by value.
Loop and repetition. Today Passing values to and back from Sub procedures Option Buttons Do While Loops For Loops Population Growth.
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.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub 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,
 The real power of PHP comes from its functions; it has more than 1000 built-in functions.  PHP User Defined Functions  Besides the built-in PHP functions,
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Sub Procedures and Functions Visual Basic. Sub Procedures Slide 2 of 26 Topic & Structure of the lesson Introduction to Modular Design Concepts Write.
Sub Procedures Chapter 6-Part 1. Chapter 6 Part 12 Event Procedures Code that occurs based upon event. Mouse click Got focus Repetitive code that might.
Introduction to Computing Dr. Nadeem A Khan. Lecture 21.
Sub Procedures And Functions
Programming Right from the Start with Visual Basic .NET 1/e
UNIT - V STORED PROCEDURE.
3rd prep. – 2nd Term MOE Book Questions.
Method.
Functions.
Chapter 4 - Visual Basic Schneider
5.2 Sub Procedures, Part I Defining and Calling Sub Procedures
Sub Procedures and Functions
A function is a group of statements that exist within a program for the purpose of performing a specific task. We can use functions to divide and conquer.
The structure of programming
Chapter 4 General Procedures
Functions Imran Rashid CTO at ManiWeber Technologies.
Chapter (3) - Procedures
Introducing Modularity
Presentation transcript:

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 and event procedures.

General Sub Procedures A general procedure tells the application how to perform a specific task. Once a general procedure is defined, it must be specifically invoked by the application. By contrast, an event procedure remains idle until called upon to respond to events caused by the user.

Why create general procedures? several different event procedures might need the same actions performed eliminates the need to duplicate code makes the application easier to maintain may be able to reuse general procedures in other applications

Sub Procedure Syntax Syntax for Sub procedure declaration: Private Sub ProcedureName() statements End Sub Syntax for calling Subroutines: Call ProcedureName

Private Sub cmdAdd_Click() Dim num1 As Single, num2 As Single 'Display the sum of two numbers picResult.Cls picResult.Print "This program displays a sentence" picResult.Print "identifying two numbers and their sum." picResult.Print num1 = 2 num2 = 3 picResult.Print "The sum of"; num1; "and"; num2; "is"; num1 + num2 End Sub

Private Sub cmdAdd_Click() Dim num1 As Single, num2 As Single 'Display the sum of two numbers picResult.Cls Call ExplainPurpose picResult.Print num1 = 2 num2 = 3 picResult.Print "The sum of"; num1; "and"; num2; "is"; num1 + num2 End Sub Private Sub ExplainPurpose() 'Explain the task performed by the program picResult.Print "This program displays a sentence" picResult.Print "identifying two numbers and their sum." End Sub

Using Parameters with Sub Procedures Syntax for defining a Sub procedure with parameters: Private Sub ProcedureName(Parameters) statements End Sub The parameters for a procedure are like a variable declaration, declaring values that are passed in from the calling procedure. Private Sub Add(num1 As Single, num2 As Single) 'Display numbers and their sum picResult.Print "The sum of"; num1; "and"; _ num2; "is"; num1 + num2 End Sub

Calling Sub Procedures with Arguments Syntax for calling a Sub procedure with Arguments: Call ProcedureName (value1, value2, … ) Arguments send values to the parameters in the Sub Procedure from the calling procedure. Private Sub cmdAdd_Click() 'Display the sum of two numbers picResult.Cls Call ExplainPurpose picResult.Print Call Add(2, 3) End Sub

Private Sub cmdAdd_Click() 'Display the sum of two numbers picResult.Cls Call ExplainPurpose picResult.Print Call Add(2, 3) End Sub Private Sub Add(num1 As Single, num2 As Single) 'Display numbers and their sum picResult.Print "The sum of"; num1; "and"; num2; "is"; num1 + num2 End Sub Private Sub ExplainPurpose() 'Explain the task performed by the program picResult.Print "This program displays a sentence" picResult.Print "identifying two numbers and their sum." End Sub

Private Sub cmdAdd_Click() 'Display the sums of several pairs of numbers picResult.Cls Call ExplainPurpose picResult.Print Call Add(2, 3) Call Add(4, 6) Call Add(7, 8) End Sub Private Sub Add(num1 As Single, num2 As Single) 'Display numbers and their sum picResult.Print "The sum of"; num1; "and"; num2; "is"; num1 + num2 End Sub

Private Sub cmdAdd_Click() Dim Value1 As Single, Value2 As Single Value1 = Val(Text1.Text) Value2 = Val(Text2.Text) picResult.Cls Call ExplainPurpose picResult.Print Call Add(Value1, Value2) End Sub Private Sub Add(num1 As Single, num2 As Single) 'Display numbers and their sum picResult.Print "The sum of"; num1; "and"; num2; "is"; num1 + num2 End Sub