Functions Chapter 6-Part 2.

Slides:



Advertisements
Similar presentations
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 6- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Advertisements

Chapter 6, Slide 1Starting Out with Visual Basic 3 rd Edition Chapter 6 Sub Procedures And Functions.
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
1 5.3 Sub Procedures, Part II Passing by Value Passing by Reference Sub Procedures that Return a Single Value Debugging.
Chapter 7: Sub and Function Procedures
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
1.
Writing General Procedures Often you will encounter programming situations in which multiple procedures perform the same operation This condition can occur.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
Example 2.
Chapter 4 - Visual Basic Schneider
Chapter 41 Sub Procedures, Part II Passing by Value Passing by Reference Local Variables Class-Level Variables Debugging.
Functions Section 4.3. Last week, we were introduced to procedures Procedures are used in support of top- down program design. –They are used to create.
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.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Tutorial 7: Sub and Function Procedures1 Tutorial 7 Sub and Function Procedures.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Chapter 6 Procedures and Functions Instructor: Bindra Shrestha University of Houston – Clear Lake CSCI
Why to Create a Procedure
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look UTPA – Fall 2011.
C Functions Programmer-defined functions – Functions written by the programmer to define specific tasks. Functions are invoked by a function call. The.
PROGRAMMING Functions. Objectives Understand the importance of modular programming. Know the role of functions within programming. Use functions within.
Programming with Microsoft Visual Basic 2008 Fourth Edition
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 7 Sub and Function Procedures.
CH 8 : Enhancing Classes - Review QUICK REVIEW : A Class defines an entity’s (Object’s) data and the actions or behaviors (Methods) associated with that.
110-G1 Motivation: Within a program, may have to perform the same computation over and over Many programs share the same computation (e.g. sorting) To.
Chapter 6 Sub Procedures
Chapter 9: Writing Procedures Visual Basic.NET Programming: From Problem Analysis to Program Design.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
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.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
1 CS161 Introduction to Computer Science Topic #9.
Week Procedures And Functions 7 A procedure is a collection of statements that performs a task.
Sub Procedures; Passing Values Back From Sub Procedures Passing by reference Passing by value.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
Programming Fundamentals Enumerations and Functions.
Copyright © 2014 Pearson Education, Inc. Chapter 6 Procedures and Functions.
1 CS 106 Computing Fundamentals II Chapter 42 “Sub Procedures And Functions” Herbert G. Mayer, PSU CS Status 8/5/2013 Initial content copied verbatim from.
CS0004: Introduction to Programming
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.
Sub Procedures And Functions
Subprograms Functions Procedures.
Chapter 9: Value-Returning Functions
Royal University of Phnom Penh
Chapter 10: Void Functions
Organization of Programming Languages
Method.
Using Procedures and Exception Handling
Chapter#8 General Procedures
Starting Out with Java: From Control Structures through Objects
Chapter 4 - Visual Basic Schneider
Chapter 6 Sub Procedures
5.2 Sub Procedures, Part I Defining and Calling Sub Procedures
Procedures and Functions
CIS16 Application Development and Programming using Visual Basic.net
Introduction to Visual Programming
Chapter#8 General Procedures
Chapter 7: Using Functions, Subs, and Modules
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look
Workshop for Programming And Systems Management Teachers
Chapter 9: Value-Returning Functions
Chapter 8 - Functions and Functionality
STARTING OUT WITH Visual Basic 2008
Chapter 10: Void Functions
Presentation transcript:

Functions Chapter 6-Part 2

Functions Built-in Function Examples Functions don’t stand alone. Val(txtTextBox.Text) InputBox(“Prompt”) Functions don’t stand alone. intAge = Val(txtAge.Text) Chapter 6 Part 2

Function Information Similar to General Procedure Set of statements that perform a task when called Not associated with controls Parameter lists like general sub procedures Local variables allowed Different from General Procedure The function must return a value result used in an expression. Function name is a variable in itself. Chapter 6 Part 2

Differences between Procedure & Function Does not return a value; can pass values by reference or value though. Returns a value to its call statement. Called procedure can be on its own line. Invokes function but must contain code on same line to do something with returned value. Use when end result is not just a single value. Use when end result is a single value. Chapter 6 Part 2

Process Encounters function call. Invokes function (and passes any arguments). Completes function code. Returns a value through the name of the function. Stores function value in something—a variable. Chapter 6 Part 2

Function Syntax Access: Private, Public, etc. [Access] Function FunctionName(ParameterList) As DataType [Statements] End Function Access: Private, Public, etc. Function: specifies function FunctionName: name of function you create ParameterList: variables declared to receive arguments passed; specifiy ByVal or ByRef As DataType: declaration of function return type Chapter 6 Part 2

Function Header Function Name Parameter passed by value Return Type Chapter 6 Part 2

Function Example: Return Value Through Return Keyword Parameter variable to receive a copy of the incoming argument Local variable Contents of local variable returned Return keyword returns value to the function call. Chapter 6 Part 2

Alternative Function: Assign Value to Function Name Chapter 6 Part 2

Function Call Syntax Variable = FunctionName(arguments) Variable stores results of function FunctionName calls (invokes) the function Arguments variables passed to the function Chapter 6 Part 2

decShipping ShippingCharge decPurchase Variable to store results of function ShippingCharge Function call decPurchase Variable to pass as argument to function Chapter 6 Part 2

Process (10 contained in decPurchase variable) Step 4 Step 3 Step 1 Step 1: Passes 10 by value to the function. Step 2: Select Case determines shipping is 2.95. Step 3: 2.95 returned through function name to calling statement. Step 4: 2.95 return value is assigned to decShipping variable. Chapter 6 Part 2

Function Return Value Stored in Variable Chapter 6 Part 2

Function Notes The function name is a “store-only” variable. The function name value contains the value at the end of the function. A function never is displayed on the right side of an assignment statement inside that function. Doing so would invoke itself (the function) again. Chapter 6 Part 2

Additional Return Information Also return nonnumeric results String Boolean (pp. 372-373) Chapter 6 Part 2

Section 6.6 Read scenario, study sketches, examine methods and flowcharts, and interpret pseudocode. Build application (Tutorial 6-7). Chapter 6 Part 2