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.

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.
Sub and Function Procedures
1 5.3 Sub Procedures, Part II Passing by Value Passing by Reference Sub Procedures that Return a Single Value Debugging.
1.
1 Chapter 5 - General Procedures 5.1 Function Procedures 5.2 Sub Procedures, Part I 5.3 Sub Procedures, Part II 5.4 Modular Design.
Passing Arguments Question Example: IS1102 Exam Autumn 2001.
Chapter 4 General Procedures
Chapter 4 - Visual Basic Schneider
Introduction to Computing Dr. Nadeem A Khan. Lecture 17.
Chapter 4 (cont) Sec. 4.1, 4.2, 4.4 Procedures (User-defined)
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.
Introduction to Computing Dr. Nadeem A Khan. Lecture 18.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
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)
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.
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
1 Chapter 5 - General Procedures 5.1 Function Procedures 5.2 Sub Procedures, Part I 5.3 Sub Procedures, Part II 5.4 Modular Design.
5-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
PROGRAMMING Functions. Objectives Understand the importance of modular programming. Know the role of functions within programming. Use functions within.
1 Chapter 5 - General Procedures 5.1 Function Procedures 5.2 Sub Procedures, Part I 5.3 Sub Procedures, Part II 5.4 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.
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.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
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.
Procedural Programming Criteria: P2 Task: 1.2 Thomas Jazwinski.
Repetition Chapter 6 - Visual Basic Schneider 1  Loop Structure  Elements of a Loop Structure  Processing Lists of Data with Do Loops Chapter 6 -
‘Tirgul’ # 2 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #2.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
Chapter 3 - Visual Basic Schneider Numeric Variables Used to store numbers Value is assigned by a statement of the form: numVar = expression The variable.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
1Edited By Maysoon Al-Duwais. 2 General Procedures Function Procedure Sub Procedures, Part I Sub Procedures, Part II Modular Design Edited By Maysoon.
Week Procedures And Functions 7 A procedure is a collection of statements that performs a task.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
Chapter 5 Menus, Sub Procedures and Sub Functions Programming In Visual Basic.NET.
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.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
CSC 162 Visual Basic I Programming. Storage Classes Determines the “lifetime” of an identifier Types: –Automatic Default Memory is allocated for the variable.
Copyright © 2014 Pearson Education, Inc. Chapter 6 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,
1Edited By Maysoon Al-Duwais. 2 Devices for Modularity Visual Basic has two ways for breaking problems into smaller pieces: Sub procedures Function procedures.
Sub Procedures and Functions Visual Basic. Sub Procedures Slide 2 of 26 Topic & Structure of the lesson Introduction to Modular Design Concepts Write.
1Lect7 GC20111/2/ General Procedures Function Procedure Sub Procedures, Part I Sub Procedures, Part II Modular Design Lect7 GC20111/2/2015.
Introduction to Computing Dr. Nadeem A Khan. Lecture 21.
Sub Procedures And Functions
Functions Chapter 6-Part 2.
Method.
Chapter#8 General Procedures
Chapter 4 - Visual Basic Schneider
5.2 Sub Procedures, Part I Defining and Calling Sub Procedures
Procedures and Functions
Chapter#8 General Procedures
Sub Procedures and Functions
Chapter 5 - General Procedures
Function Procedures.
STARTING OUT WITH Visual Basic 2008
Presentation transcript:

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 on test)

Sub Procedures Part 1 Sub Procedure - part of a program that performs one or more related tasks, has its own name, is written as a separate part of the program. Private Sub ProcedureName() statements End Sub

Example 1 pg.143 Private Sub cmdAdd_Click() Dim num1 as single, num2 as single 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() picResult.Print “This program displays a sentence” picResult.Print “Identifying two numbers and their sum.” End Sub

Example 2, pg.144 Private Sub cmdAdd_Click() Dim num1 as single, num2 as single picResult.cls Call ExplainPurpose picResult.Print Call Add(2,3) End Sub Private Sub Add(num1 as Single, num2 as Single) picResult.Print “the sum of”; num1; “and”; num2; “is”; num1 + num2 End Sub Private Sub ExplainPurpose() picResult.Print “This program displays a sentence” picResult.Print “Identifying two numbers and their sum.” End Sub

Sub Procedures Part II Passing Values Back from Sub Procedures passed by reference passed by value - use this method when you want to ensure the variable will retain its original value when the Sub terminates  In the Call statement, enclose the variable with an extra parentheses…..Call Triple((amt))  Use ByVal statement…. Private Sub Triple(By Val num as single) NOTE: Look at Practice Problem 3 on page 170

Function Procedures Built-in Visual Basic Function Format, Val, Int, Chr, Len, Mid, InStr (pg 178) User-defined functions Functions that you create and declare Private Function FunctionName (var1 as Type1,…..) as dataType statements FunctionName = expression End Function

Function Example 1, pg 179 Private Sub cmdConvert_Click() picTempC.cls picTemC.Print FtoC(val(txtTempF.Text)) End Sub Private Function FtoC(t as Single) as Single FtoC = (5 / 9) * (t - 32) End Function NOTE: Look at Practice Problem 2 on page 185