Procedures: Functions and Subroutines

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
1 Procedural Programming Paradigm Stacks and Procedures.
1 5.3 Sub Procedures, Part II Passing by Value Passing by Reference Sub Procedures that Return a Single Value Debugging.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
Writing General Procedures Often you will encounter programming situations in which multiple procedures perform the same operation This condition can occur.
Chapter 4 General Procedures
CSI 101 Elements of Computing Spring 2009 Lecture #10 – Functions and Subroutines Monday, March 16th.
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 41 Sub Procedures, Part II (Continue). Chapter 42 Local Variable A variable declared inside a Sub procedure with a Dim statement Space reserved.
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.
Financial Information Management Stefano Grazioli.
Apply Sub Procedures/Methods and User Defined Functions
Programming with Microsoft Visual Basic th Edition CHAPTER SEVEN SUB AND FUNCTION PROCEDURES.
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
1 INF110 Visual Basic Programming AUBG Spring semester 2011 Reference books: Schneider D., An Introduction to Programming Using Visual Basic, Prentice.
1 INF110 Visual Basic Programming AUBG Fall semester 2009 Reference books: Schneider D., An Introduction to Programming Using Visual Basic, Prentice Hall,
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.
Visual Basic I Programming
Why to Create a Procedure
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look UTPA – Fall 2011.
Programming with Microsoft Visual Basic 2008 Fourth Edition
CS0004: Introduction to Programming Subprocedures and Modular Design.
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.
Subprograms CE 311 K - Introduction to Computer Methods Daene C. McKinney.
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 9: Writing Procedures Visual Basic.NET Programming: From Problem Analysis to Program Design.
Introduction to VB.NET 2005 Dr. McDaniel IDS4704 Spring 2005.
IMS 3253: Subroutines 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Procedures Subroutines Parameters –By Value.
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.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 10: Chapter 6: Slide 1 Unit 10 Sub Procedures and Functions Chapter 6 Sub.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
ME 142 Engineering Computation I Using Subroutines Effectively.
Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.
ME 142 Engineering Computation I Using Subroutines Effectively.
Debugging, Static Variables, ByRef, ByValue Chapt. 6 in Deitel, Deitel and Nieto.
Sub Procedures; Passing Values Back From Sub Procedures Passing by reference Passing by value.
More on Variables and Subroutines. Introduction Discussion so far has dealt with self- contained subs. Subs can call other subs or functions. A module.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
1 Computer Programming Andres, Wen-Yuan Liao Department of Computer Science and Engineering De Lin Institute of Technology
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,
Sub Procedures and Functions Visual Basic. Sub Procedures Slide 2 of 26 Topic & Structure of the lesson Introduction to Modular Design Concepts Write.
Lecture 7 Methods (functions and subroutines) Parameter Passing
Sub Procedures And Functions
Visual Basic I Programming
Programming Right from the Start with Visual Basic .NET 1/e
Subprograms Functions Procedures.
Lesson 16 Sub Procedures Lesson 17 Functions
VB.Net Programming Console Application
Chapter 10: Void Functions
Functions and Procedures
Method.
Chapter 6 Sub Procedures
Top-down approach / Stepwise Refinement & Sub Procedures
CIS16 Application Development and Programming using Visual Basic.net
Introduction to Visual Programming
VB.Net Programming Console Application
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look
Controls, Properties, and Procedures
Lesson Objectives Aims Key Words
The structure of programming
Chapter 8 - Functions and Functionality
Accessing Variables in your project
Functions By Anand George.
10.2 Procedures Passing Parameters 30/08/2019.
Programming Techniques
Presentation transcript:

Procedures: Functions and Subroutines

Procedures Functions and Subroutines are Procedures. Procedures are discreet blocks of code that perform discreet tasks.

Arguments Arguments are the values passed into a function or subroutine A function or subroutine may have: No arguments A number of arguments An variable number of arguments

Functions Functions differ from subroutines in one key aspect: Functions return a value. Although functions and subroutines may change any number of variable values, a function returns the value processed by the formula or computation.

A Function: A Magic Box myFunction = A = 10 myFunction = A = 12 Console.WriteLine(myFunction(R, S, T)) Console.WriteLine(myFunction(A, B,C)) R= 3 S= 2 T = 1 A= 2 B= 3 C = 4 myFunction = A = 10 Function myFunction( X As Integer, Y As Integer, Z as Integer ) A = X ^ Y + Z Return A End Function myFunction = A = 12

ByRef vs. ByVal Function myFunction(ByVal X as integer) ByVal sends the value into the function ByRef sends the reference to the actual memory space into the function. THUS ByRef CAN CHANGE THE ACTUAL MEMORY LOCATION OF THE VARIABLE PASSED INTO THE FUNCTION …even though the variable name is different. ByRef is the default

Console.WriteLine("X = " & x) Console.WriteLine("Enter New X Value:") This refers to the actual memory location. Y=Y+1 changes the value of X Sub Main() Dim x As Integer Do While x < 100 Console.WriteLine("X = " & x) Console.WriteLine("Enter New X Value:") x = Console.ReadLine() doSomething(x) Loop End Sub Sub doSomething(ByRef y As Integer) y = y + 1