6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.

Slides:



Advertisements
Similar presentations
Practical Programming COMP153-08S Lecture: Repetition Continued.
Advertisements

7 – Arrays Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette Sept 9, 2004 Last update:
Compunet Corporation Programming with Visual Studio.NET GUI Week 13 Tariq Aziz and Kevin Jones.
5.05 Apply Looping Structures
Apply Sub Procedures/Methods and User Defined Functions
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
CS0004: Introduction to Programming Variables – Numbers.
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in String Functions (3%)
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Chapter 3 – Fundamentals of Programming in VB.NET VB.NET Controls VB.NET Events Numbers Strings Input and Output.
Lecture 8 Visual Basic (2).
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9.
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.
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 6 Sub Procedures
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
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.
1 CSCI N201 Programming Concepts and Database 9 – Loops Lingma Acheson Department of Computer and Information Science, IUPUI.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 10: Chapter 6: Slide 1 Unit 10 Sub Procedures and Functions Chapter 6 Sub.
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
3.2 VB.NET Events An Event Procedure Properties and Event Procedures of the Form Tab Order of Controls Exercises.
1 Advanced Computer Programming Lab Calculator Project.
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.
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 5.04 Apply Decision Making Structures.
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
Week Procedures And Functions 7 A procedure is a collection of statements that performs a task.
6b – Sub Procedure With Parameters Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
31/01/ Selection If selection construct.
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.
Practical Programming COMP153-08S Lecture: Repetition.
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.
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.
MIC305 Week 6 Beyond controls Review of properties Differences with VB6: using classes and instances Programming constructs.
COM148X1 Interactive Programming Lecture 8. Topics Today Review.
5a – While Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
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.
Sub Procedures And Functions
Use TryParse to Validate User Input
Visual Basic Fundamental Concepts
5.03 Apply operators and Boolean expressions
Objective 7.04 Apply Built-in String Functions (3%)
UNIT 5 Lesson 15 Looping.
Objective 7.03 Apply Built-in Math Class Functions
Use TryParse to Validate User Input
للمزيد زورونا على موقعنا الإلكتروني:
Visual Basic..
1.الدوال Function 2.الاجراءاتSub Procedure 3.وحده نمطيه Add Module
CIS16 Application Development and Programming using Visual Basic.net
Programming Concepts and Database
7 – Variables, Input and Output
2b – Labels and Pictures Lingma Acheson CSCI N331 VB .NET Programming
Programming Concepts and Database
GUI Programming in Visual Studio .NET
4a- If And Else Lingma Acheson CSCI N331 VB .NET Programming
4d – Program Design Lingma Acheson CSCI N331 VB .NET Programming
Presentation transcript:

6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming

Function Procedures Sometimes a procedure produces a result, e.g. –CStr(intResult) will change the type of the intResult value from an Integer type to a String type. The result is the value in the String format. –Add(1, 2) will produce an addition result of 3. A procedure that generates a result is called a Function Procedure. A procedure that doesn’t generate a result is called a Sub Procedure. We can give the result to another variable. E.g. intResult = Add(intInput1, intInput2) lblResult.Text = CStr(intResult) 2

Procedures Sub Procedures: 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) End of event procedure Procedure Add(variable1 and variable2): Create variable 3 Add variable 1 to variable 2 and store in variable 3 display result in label End of Add procedure Can be changed to: Button click event procedure: Create variables 1, 2 Create variable 3 Take the user input and store in variable 1 and 2 variable 3 = Add(variable1 and variable 2) ‘use the result in this procedure display variable 3 in label End of event procedure Procedure Add(variable1 and variable2) Create variable 4 Add variable 1 to variable 2 and store in variable 4 pass the value of variable 4 out End of Add procedure

Function Procedures Function - A type of procedure that produces a result –Example: Function procedure call and use the result: dblResult = Add(dblInput1, dblInput2) Function procedure definition: ‘”As Double” indicates that the function produces a double value Private Function Add( ByVal dblValue1 As Double, ByVal dblValue2 As Double ) As Double Dim dblValue3 As Double dblValue3 = dblValue1 + dblValue2 Return dblValue3 End Function –Return xxx: when the Function finishes execution, xxx is the value to be passed out. Can be a value or a variable name. –Functions can also take parameters, just like Subs 4

Function Procedures –E.g. Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click … ‘Function Add takes two parameters, does the addition and passes the ‘result out to the intAddResult. intAddResult = Add(intFirst, intSecond) ‘Function call txtAddResult.Text = CStr(intAddResult) End Sub ‘Function takes two integer parameters and returns an integer as the result Private Function Add(ByVal intOne As Integer, ByVal intTwo As Integer) As Integer Dim intResult As Integer = 0 intResult= intOne + intTwo Return intResult ‘ pass the result out ‘intResult is unnecessary. The above three lines can be replaced by the ‘following line ‘Return (intOne + intTwo) End Function

Function Procedures –Each function can only return one value. E.g, In the following code, although there are two return statements, only one return statement will be executed. If (a condition is true) Then return True ‘return a boolean value Else return False End If –Boolean data type revisit – A boolean variable only has two values, True or False. It is often used to indicate a situation is true or false. E.g. Dim blnPass As Boolean If (intScore >=60) Then blnPass = True Else blnPass = False