CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look UTPA – Fall 2011.

Slides:



Advertisements
Similar presentations
Sub and Function Procedures
Advertisements

Pemrograman VisualMinggu …6… Page 1 MINGGU Ke Enam Pemrograman Visual Pokok Bahasan: Module, Class & Methods Tujuan Instruksional Khusus: Mahasiswa dapat.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
Chapter 7: User-Defined Functions II
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
Chapter 6: User-Defined Functions I
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
COMP 14 Introduction to Programming Mr. Joshua Stough February 28, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
 2007 Pearson Education, Inc. All rights reserved C Functions.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
 2007 Pearson Education, Inc. All rights reserved C Functions.
 2003 Prentice Hall, Inc. All rights reserved. 1 Functions Modules: functions and classes Programs use new and “prepackaged” modules –New: programmer-defined.
Chapter 6: User-Defined Functions I
1 Functions Modules: functions and classes Programs use new and “prepackaged” modules –New: programmer-defined functions, classes –Prepackaged: from the.
Apply Sub Procedures/Methods and User Defined Functions
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "methods" in Java Purpose Reuse code Modularize the program This.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
Why to Create a Procedure
Dale Roberts Procedural Programming using Java Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
6.1 Introduction Divide and Conquer –The best way to develop and maintain a large program is to construct it from small, manageable pieces. BZUPAGES.COM.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
* * 0 Chapter 6 Java Methods. * * 0 Method Syntax [access specifier][qualifier] return type method name(argument list) Access specifier public – method.
Chapter 6: User-Defined Functions
 2008 Pearson Education, Inc. All rights reserved JavaScript: Functions.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 7 Sub and Function Procedures.
Chapter 9: Writing Procedures Visual Basic.NET Programming: From Problem Analysis to Program Design.
4-Methods Dr. John P. Abraham Professor UTPA. Common ways of packaging code Properties Methods Classes Namespaces (related classes are grouped into a.
CPSC 230 Computers and Programming I Spring 2003 Dr. Lynn Lambert.
CSCI 3327 Visual Basic Chapter 9: Object-Oriented Programming: Classes and Objects UTPA – Fall 2011.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions Outline 5.1Introduction 5.2Program Modules.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
Methods: A Deeper Look. Template for Class Definition public class { } A.Import Statement B.Class Comments C.Class Name D.Data members E.Methods (inc.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "___________________" in Java Purpose –Reuse code –Modularize.
More on Variables and Subroutines. Introduction Discussion so far has dealt with self- contained subs. Subs can call other subs or functions. A module.
CHAPTER 4 FUNCTIONS Dr. Shady Yehia Elmashad. Outline 1.Introduction 2.Program Components in C++ 3.Math Library Functions 4.Functions 5.Function Definitions.
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,
 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Chapter 7 User-Defined Methods.
Chapter 6: User-Defined Functions I
IS 350 Application Structure
Methods Chapter 6.
Functions Chapter 6-Part 2.
JavaScript: Functions
Programming Fundamentals Lecture #7 Functions
Method.
User-Defined Functions
Chapter 5 - Functions Outline 5.1 Introduction
Chapter 6 Methods: A Deeper Look
CIS16 Application Development and Programming using Visual Basic.net
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods
Chapter 6: User-Defined Functions I
Chapter 9: Value-Returning Functions
Methods.
Presentation transcript:

CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look UTPA – Fall 2011

Objectives In this chapter, you will: –Explore the components of a module or a class –Get familiar with the syntax of methods –Learn the declaration of methods Subroutines Functions –Become aware of.Net Namespace –Discover how to use recursions 2

Modules, Classes and Methods Modules and classes make up a program Modules and classes are composed of smaller pieces called methods, instance variables and properties Related classes are grouped into namespaces Two types of methods exist: –Subroutines –Functions 3

Pre-Packaged and User Defined.NET framework provides a class library that contains many pre-packaged classes: –Mathematical calculations, error checking, GUI & graphics, String and character manipulations, I/O operations, XML, database, web, etc. Users can define their own classes You can combine new modules and classes with pre-packaged ones 4

Method Basics A method is invoked by a method call Method call specifies the method name and provides information as arguments When method is finished the control goes back to the caller The method may or may not return results Method provides for divide-and-conquer approach to software engineering Methods can be used over and over again 5

Methods That Do Not Return a Value Methods that only performs a task such as printing, but do not return a value –These methods are generally called Subroutines The parameters passed into these methods are ByVal parameters. 6

Declaring a Subroutine Sub methodName (parameterList) –Declarations and statements End Sub If you pass a parameter ByRef and if the value of that parameter is changed by the subroutine, that variable’s value also will be changed in the calling module 7

Methods That Return A Value (Functions) Functions must have a return statement followed by what is being returned Declared as follows: Function Square(ByVal v As Integer) As Integer Return v^2 End function Please pay attention to the type in the last portion of function heading 8

Shared Methods Methods declared in a module are shared by default If you want to share a method in a class, use the modifier Shared in the header of the method (instead of private or public) – write and writeline are shared methods Class Math contains many shared methods 9

Subroutines A Method that does not return a value Pass values in and out through interfaces, ByVal/ByRef parameters ByVal –A copy is passed –May pass actual values rather than variables –Original value is not changed ByRef –Memory location is passed –Value stored in that location may change –Cannot pass a value, must pass a variable –Side effects may occur 10

Functions Returns exactly one value through its name Name must have an associated type 11

.Net Namespaces System.windows.forms –Contains the classes required to create and manipulate GUIs System.io –Contains classes that enable programs to input and output data System.Data –Contains classes that enable program to access and manipulate databases There are many others 12

Recursion A method calling itself The method only knows how to solve the simplest case (base case) A more complex case is divided into two pieces, one base case and remaining as a complex case Factorial of 5 is 5 times factorial of 4. Factorial of 1 is 1 (base case) 13

See Recursion Examples 14

Method Overloading Multiple methods with the same name but different signatures –Meaning different numbers and types of parameters OR different ordering of parameters by type Function square(ByVal value As Integer) As Integer Return convert.toInt32(value ^ 2) End Function Function square(ByVal value As Double) As Integer Return value ^ 2 End Function 15

More Examples (Optional Parameters) May have one or more optional parameters (list after the required parameters) Specify default value in case not passed in Function Power(ByVal base As Integer, Optional ByVal exponent As Integer =2) As Integer Dim total As Integer =1 For i As Integer = 1 To exponent total *=base Next Return total End Function 16

17