6b – Sub Procedure With Parameters Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.

Slides:



Advertisements
Similar presentations
Sub and Function Procedures
Advertisements

1 Procedural Programming Paradigm Stacks and Procedures.
Control structures Part 2 iteration control To enable repetition of a statement block.
More on lists, exceptions, loops and validation. You can use the exception to indicate the error that occurred Private Sub btnCheck_Click(ByVal sender.
5.05 Apply Looping Structures
1b – Inside Visual Studio Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Apply Sub Procedures/Methods and User Defined Functions
Tutorial 7: Sub and Function Procedures1 Tutorial 7 Sub and Function Procedures.
Tutorial 7: Sub and Function Procedures1 Tutorial 7 Sub and Function Procedures.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
CS0004: Introduction to Programming Variables – Numbers.
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 6 Procedures and Functions Instructor: Bindra Shrestha University of Houston – Clear Lake CSCI
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
Why to Create a Procedure
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
3 - Variables Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 7 Sub and Function Procedures.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
CIS 338: Classes and Modules Dr. Ralph D. Westfall May, 2011.
IMS 3253: Subroutines 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Procedures Subroutines Parameters –By Value.
CS0004: Introduction to Programming Project 1 – Lessons Learned.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 10: Chapter 6: Slide 1 Unit 10 Sub Procedures and Functions Chapter 6 Sub.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
1 Advanced Computer Programming Lab Calculator Project.
VB Classes ISYS 512/812. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
4-1 Chapter 4 The Selection Process in VB.NET. 4-2 Learning Objectives Understand the importance of the selection process in programming. Describe the.
PSU CS 106 Computing Fundamentals II VB Declarations HM 5/4/2008.
2a – Object Oriented Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
2d – CheckBox Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
2e – RadioButtons Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
7. Data Import Export Lingma Acheson Department of Computer and Information Science IUPUI CSCI N207 Data Analysis Using Spreadsheets 1.
Week Procedures And Functions 7 A procedure is a collection of statements that performs a task.
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.
Lab 10 Slides.
2c – Textboxes and Buttons Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
5b – For Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
COM148X1 Interactive Programming Lecture 8. Topics Today Review.
1 Computer Programming Andres, Wen-Yuan Liao Department of Computer Science and Engineering De Lin Institute of Technology
5a – While Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 3 Variables and Calculations.
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.
Computer Science Up Down Controls, Decisions and Random Numbers.
CS0004: Introduction to Programming
Sub Procedures And Functions
Visual Basic I Programming
Visual Basic Fundamental Concepts
Royal University of Phnom Penh
للمزيد زورونا على موقعنا الإلكتروني:
Visual Basic..
5.2 Sub Procedures, Part I Defining and Calling Sub Procedures
1.الدوال Function 2.الاجراءاتSub Procedure 3.وحده نمطيه Add Module
Visual Basic 6 Programming.
CIS16 Application Development and Programming using Visual Basic.net
funCTIONs and Data Import/Export
CSCI N207 Data Analysis Using Spreadsheet
Programming Concepts and Database
CSCI N207 Data Analysis Using Spreadsheet
2g – ComboBox Lingma Acheson CSCI N331 VB .NET Programming
7 – Variables, Input and Output
Programming Concepts and Database
4a- If And Else Lingma Acheson CSCI N331 VB .NET Programming
4d – Program Design Lingma Acheson CSCI N331 VB .NET Programming
Presentation transcript:

6b – Sub Procedure With Parameters Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming

Procedure Revisit Add an item into the list box: ‘Contents inside the () defines what to add to the listbox lstOutput.Items.Add(“*************”) ‘Contents inside the () defines what to show in the messagebox MessageBox.Show(“The second input is 0. Unable to perform the division.”) We can pass data to the procedure and give some information for the procedure to use. 2

Procedures Global Variables: ‘Create 2 global variables outside of any procedure, can be used anywhere Create variables 1, 2 Button click event procedure: Add() Multiply() End of event procedure Procedure Add(): ‘1 local variable, only used ‘inside this procedure Create variable 3 ‘use global variable 1, and 3 Take the user input and store in variable 1 and 2 Add variable 1 to variable 2 and store the result to variable 3 End of procedure Add Procedure Multiply() … End of Multiply procedure Can be changed to the following: Button click event procedure: Create variables 1, 2 Take the user input and store in variable 1 and 2 ‘Tell the procedure what to add Add(variable1 and variable2) ‘Tell the procedure what to multiply Multiply(variable1 and variable2) End of event procedure Procedure Add(variable1 and variable2): Create variable 3 Add variable 1 to variable 2 and store in variable 3 End of Add procedure Procedure Multiply(variable1 and variable2): Create variable 3 Multiply variable 1 to variable 2 and store in variable 3 End of Multiply procedure

Parameters Sub procedure that takes parameters –Purpose: Pass data into the Sub for the Sub to use –Example: Sub call: Add(2.5, 3.1) Sub Definition: Private Sub Add(ByVal dblValue1 As Double, ByVal dblValue2 As Double) Dim dblResult as Double dblResult = dblValue1 + dblValue2 End Sub 4

Parameters Sub procedure that takes parameters –More than one value can be passed into the Sub. If more than one, use comma to separate the values. –The number of values passed in must match the number of parameters in the definition. –The types of values passed in must match the types of parameters in the definition. 5

Parameters Sub procedure that takes parameters –The parameter name defined in the procedure definition doesn’t have to be the same as the actual variable name passed into the procedure. E.g.: We can call add twice with different variables. Sub call: Add(2.5, 3.1) Add(dblInput1, dblInput2) Add(dblInput3, dblInput4) Sub Definition: Private Sub Add(ByVal dblValue1 As Double, ByVal dblValue2 As Double) Dim dblResult as Double dblResult = dblValue1 + dblValue2 End Sub –Sub procedures with parameters are very useful if we want to perform the same task again with different values. 6

Sub Procedures –E.g. Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click Dim intFirst As Integer Dim intSecond As Integer intFirst = CInt(nudFirst.Value) intSecond = CInt(nudSecond.Value) ‘intFirst and intSecond are local variables, thus they cannot be used ‘inside the Add() procedure. Their values must be passed into the Add(). Add(intFirst, intSecond) ‘Sub call End Sub ‘Sub definition, takes two parameters, both are integers Private Sub Add(ByVal intOne As Integer, ByVal intTwo As Integer) Dim intResult As Integer = 0 intResult= intOne + intTwo txtAddResult.Text = CStr(intResult) End Sub 7