Sub Procedures and Functions Visual Basic. Sub Procedures Slide 2 of 26 Topic & Structure of the lesson Introduction to Modular Design Concepts Write.

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
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Chapter 7: Sub and Function Procedures
Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
Introduction to Computers and Programming Lecture 11: Introduction to Methods Professor: Evan Korth New York University.
Passing Arguments Question Example: IS1102 Exam Autumn 2001.
Introduction to Computers and Programming Introduction to Methods in Java.
CSI 101 Elements of Computing Spring 2009 Lecture #10 – Functions and Subroutines Monday, March 16th.
Chapter 5 - Menus, Sub Procedures, and Sub Functions  Menus - controls - properties and events –menu editor - create and change –defining menus - menu.
Lec6 P 1 CP2030 Visual Basic For C++ programmers Copyright © University of Wolverhampton CP2030 VBFC Lecture 6 Back To Index v Procedures and Parameters.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Chapter 41 General Procedures Sub Procedures, Part I Sub Procedures, Part II Function Procedures.
Apply Sub Procedures/Methods and User Defined Functions
3/9/2004 PPCC - Introduction to VB6 Copyright ©2004, Tore Bostrup 1 Introduction to VB6 Week 2.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
1 INF110 Visual Basic Programming AUBG Spring semester 2011 Reference books: Schneider D., An Introduction to Programming Using Visual Basic, Prentice.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
1 Subroutines and Functions Chapter 6 in Deitel, Deitel and Nieto.
Chapter 2: Creating ActiveX Code Components By นภดล กมลวิลาศเสถียร Dept. of Computer Engineering, Prince of Songkla University Source: Mastering Visual.
Visual Basic I Programming
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
CS0004: Introduction to Programming Subprocedures and Modular Design.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhancing the Wage Calculator Application Introducing Function Procedures and.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Sub procedures School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 6, Friday 2/21/03)
VB Core II Conditional statements Exception handling Loops Arrays Debugging.
Subprograms CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Programming Test #1 Solutions. Multiple Choice 1. B) the grammar of the coding language 2. C) String 3. A) Single 4. C) 2Burgers4Me 5. B) Design Time.
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.
University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Programming in Microsoft Access using VBA Using VBA to add functionality.
University of Sunderland CIF 104 Fundamentals of DatabasesUnit 16 SESSION 16 VBA example.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
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.
© 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.
ME 142 Engineering Computation I Using Subroutines Effectively.
Top-down approach / Stepwise Refinement & Procedures & Functions.
31/01/ Selection If selection construct.
04/02/ Procedures Top-down approach / Stepwise Refinement & Sub Procedures.
Functions Structured Programming. Topics to be covered Introduction to Functions Defining a function Calling a function Arguments, local variables and.
Slide 1 Controls v Control naming convention –Label: lblName –Command Button: cmdName –Text Box: txtName.
Sub Procedures; Passing Values Back From Sub Procedures Passing by reference Passing by value.
BACS 287 Programming Fundamentals 5. BACS 287 Programming Fundamentals This lecture introduces the following topics: – Procedures Built-in Functions User-defined.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
1 VB-04-Control Structures 16 March 2016 Visual Basic Control Structures - Selection.
Week 1 Lecture 1 Slide 1 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton CP2028 Visual Basic Programming 2 v Week.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Lecture 7 Methods (functions and subroutines) Parameter Passing
CS0004: Introduction to Programming
Sub Procedures And Functions
Visual Basic I Programming
IS 350 Application Structure
Functions CIS 40 – Introduction to Programming in Python
Sub Procedures and Functions
Week 4 Lecture-2 Chapter 6 (Methods).
Chapter 8 - Functions and Functionality
Fundamental Programming
PROGRAM DESIGN CONCEPTS AND TECHNIQUES
Introduction to Computing Lecture 08: Functions (Part I)
Introduction to Computer Programming IT-104
Introducing Modularity
Presentation transcript:

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 Compare between Call by Value and Call by Reference

Visual Basic Sub Procedures Slide 3 of 26 Learning Outcomes At the end of this lecture you should be able to : 1.Declare a sub program 2.Write a sub program and pass arguments to it 3.Write a Call-By-Value and Call By Reference sub procedure

Visual Basic Sub Procedures Slide 4 of 26 Key Terms you must be able to use If you have mastered this topic, you should be able to use the following terms correctly in your assignments and tests: nCall nBy Ref nBy Val

Visual Basic Sub Procedures Slide 5 of 26 Modular Design Concepts Modularity refers to breaking a large problem down into smaller self-contained modules. This allows the programmer to isolate problems within the program by looking at specific areas. Without Breaking problems down into smaller modules will increase program maintenance cost.

Visual Basic Sub Procedures Slide 6 of 26 Dividing code into procedures Divide & Conquer Approach Makes program development more manageable. Software Reusability Using existing procedures as building blocks for new programs Avoid Duplicating programs

Visual Basic Sub Procedures Slide 7 of 26 Different Modular Techniques Sub Procedures Function Procedures Event Procedures Visual Basic provides us with the ability to represent modules through the use of the following:-

Visual Basic Sub Procedures Slide 8 of 26 Sub Procedures Sub Procedures are subprograms or routines which are self contained and are used to perform a particular task. What are Sub Procedures?

Visual Basic Sub Procedures Slide 9 of 26 Writing a Sub Procedure Private Sub cmdAdd_click() Call add(2,1) End sub Private sub add(num1,num2 as integer) Dim total as integer total = num1 + num2 End Sub Arguments parameters

Visual Basic Sub Procedures Slide 10 of 26 Write a program to accept two numbers using textboxes and pass the numbers into a subprogram called product to multiply them. Display the answer in the product procedure. Use a Msgbox to display the answer Quick Review Question

Visual Basic Sub Procedures Slide 11 of 26 Answer Private Sub cmdmultiply_Click() Dim a,b as integer Call product (a, b) End Sub Private Sub product (num1 As integer, num2 As integer) Msgbox ("The product of “ & num1 & "and“ & num2 & "is“ & num1 * num2) End Sub

Visual Basic Sub Procedures Slide 12 of 26 No Arguments – No return value MAIN PROGRAM Private Sub Command1_Click( ) ‘ Check the parenthesis. There is no argument Call No_arg_No_return End Sub No arguments

Visual Basic Sub Procedures Slide 13 of 26 No Arguments – No return value SUB PROCEDURE Public Sub No_arg_No_return() Dim x, y, z As Integer x = 20 y = 30 z = x * y Label1.Caption = "TOTAL = " & z End Sub

Visual Basic Sub Procedures Slide 14 of 26 OUTPUT

Visual Basic Sub Procedures Slide 15 of 26 Write a program that will accept three numbers and pass the numbers to a procedure minimum to determine the smallest number. Accept the three numbers using input box and display the smallest number on a text box. Quick Review Question

Visual Basic Sub Procedures Slide 16 of 26 Solution Private Sub cmdSmallest_Click() Dim value1 As Long, value2 As Long, value3 As Long value1 = txtOne.Text value2 = txtTwo.Text value3 = txtThree.Text Call Minimum(value1, value2, value3) End Sub Private Sub Minimum(min As Long, y As Long, z As Long) If y < min Then min = y End If If z < min Then min = z End If lblSmallest.Caption = "Smallest value is " & min End Sub

Visual Basic Sub Procedures Slide 17 of 26 Call By Reference When you pass a variable to a sub procedure and return its updated value By default Call By Reference is used in VB

Visual Basic Sub Procedures Slide 18 of 26 Call By Reference - Procedure Private sub a() dim a as integer a = 5 call square(a) print a end sub private sub square(num as integer) num = num * num end sub Ans a = 25

Visual Basic Sub Procedures Slide 19 of 26 Call By Value When you pass a variable to a sub program and it does not affect the value from the main program

Visual Basic Sub Procedures Slide 20 of 26 Call By Value Private sub a() dim a as integer a = 5 call square(a) print a end sub private sub square (byval num as integer) num = num * num end sub Ans a = 5

Visual Basic Sub Procedures Slide 21 of 26 Group Exercise Write a program that accepts a student mark and passes the mark to a subprogram called grade which will determine the students grade. Mark Grade A B C D 0 – 39 F

Visual Basic Sub Procedures Slide 22 of 26 n Write a program that uses a Sub procedure Maximum to determine the largest of three Integers. The smallest value is displayed in a Label. Follow Up Assignment

Visual Basic Sub Procedures Slide 23 of 26 Module Design – Sub Procedures – Function Procedures – Event Procedures Sub Procedures – Call By Value – Call By Reference Summary of Main Teaching Points