Download presentation
Presentation is loading. Please wait.
1
Functions Chapter 6-Part 2
2
Functions Built-in Function Examples Functions don’t stand alone.
Val(txtTextBox.Text) InputBox(“Prompt”) Functions don’t stand alone. intAge = Val(txtAge.Text) Chapter 6 Part 2
3
Function Information Similar to General Procedure
Set of statements that perform a task when called Not associated with controls Parameter lists like general sub procedures Local variables allowed Different from General Procedure The function must return a value result used in an expression. Function name is a variable in itself. Chapter 6 Part 2
4
Differences between Procedure & Function
Does not return a value; can pass values by reference or value though. Returns a value to its call statement. Called procedure can be on its own line. Invokes function but must contain code on same line to do something with returned value. Use when end result is not just a single value. Use when end result is a single value. Chapter 6 Part 2
5
Process Encounters function call.
Invokes function (and passes any arguments). Completes function code. Returns a value through the name of the function. Stores function value in something—a variable. Chapter 6 Part 2
6
Function Syntax Access: Private, Public, etc.
[Access] Function FunctionName(ParameterList) As DataType [Statements] End Function Access: Private, Public, etc. Function: specifies function FunctionName: name of function you create ParameterList: variables declared to receive arguments passed; specifiy ByVal or ByRef As DataType: declaration of function return type Chapter 6 Part 2
7
Function Header Function Name Parameter passed by value Return Type
Chapter 6 Part 2
8
Function Example: Return Value Through Return Keyword
Parameter variable to receive a copy of the incoming argument Local variable Contents of local variable returned Return keyword returns value to the function call. Chapter 6 Part 2
9
Alternative Function: Assign Value to Function Name
Chapter 6 Part 2
10
Function Call Syntax Variable = FunctionName(arguments)
Variable stores results of function FunctionName calls (invokes) the function Arguments variables passed to the function Chapter 6 Part 2
11
decShipping ShippingCharge decPurchase
Variable to store results of function ShippingCharge Function call decPurchase Variable to pass as argument to function Chapter 6 Part 2
12
Process (10 contained in decPurchase variable)
Step 4 Step 3 Step 1 Step 1: Passes 10 by value to the function. Step 2: Select Case determines shipping is 2.95. Step 3: 2.95 returned through function name to calling statement. Step 4: 2.95 return value is assigned to decShipping variable. Chapter 6 Part 2
13
Function Return Value Stored in Variable
Chapter 6 Part 2
14
Function Notes The function name is a “store-only” variable.
The function name value contains the value at the end of the function. A function never is displayed on the right side of an assignment statement inside that function. Doing so would invoke itself (the function) again. Chapter 6 Part 2
15
Additional Return Information
Also return nonnumeric results String Boolean (pp ) Chapter 6 Part 2
16
Section 6.6 Read scenario, study sketches, examine methods and flowcharts, and interpret pseudocode. Build application (Tutorial 6-7). Chapter 6 Part 2
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.