SlideShare a Scribd company logo
MEM 302: Introduction to
Computer Programming
Function Procedures
Review
 General Form of an If/Else Block…
If condition Then
some code
Else
some other code
End If
 General Form of a Select Case Block
Select Case selector
Case valueList1
action1
Case valueList2
action2
Case Else
actionOfLastResort
End Select
Review
 A value list can be a…(4 things)
 Literal
 Variable
 Expression
 Range
 What property holds whether a radio button or check
box is checked?
 Checked
Function Procedures
 Functions are used in programming to break complex
problems into smaller ones
 We have encountered built-in functions inVB before
 Int(param1)
 FormatNumber(param1,param2)
 These functions output a value to where they are used.
 When a function outputs a value, it is said to return a value.
 When a function is used, it is said to be called.
 You can pass input to a function by supplying it with
arguments.
 Arguments are the values you pass to a function
 Parameters are the local variables used in the function definition.
Function Procedures
 We can define our own functions:
 General Form:
Function FunctionName (ByVal var1 As Type, ByVal var2 As
Type) As ReturnDataType
…
some code
…
Return expression
End Function
 FunctionName is the name of the function
 var1 and var2 are the names of the parameters
 The Types following var1 and var2 tell what type the parameters are
 ReturnDataType is the type of the value that the function returns
 The expression in Return expression is what value is returned by the
function.
Function Example 1
 New Topics:
 Programmer Defined Function
 Parameters/arguments
 Return Statement
 Function Call
Function Procedures
 Notes:
 The code for the function is called the function definition.
 When calling a function, you must supply it with the same
number of arguments as parameters defined in the function
definition.
 You can create functions with no parameters. Just leave the
parentheses empty when defining the function.
 A function MUST return a value.
 Function names inVB:
 Typically are camel case with first letter capitalized.
 Follow the same naming rules as variables
 Should be a verb that describe what the function does
Function Example 2
 New Topics:
 Multiple Parameters/Arguments
Scope
 Scope refers to where a variable can be used (seen).
 Scope is usually defined by where it was declared.
 A variable declared in a function or event procedure can
ONLY be used in the function or event procedure where
it was declared.
 A variable declared inside of a class, but not in any of its
procedures can be used anywhere in the class, including in
any of its procedures.
 Parameters can be used ONLY in the function they
belong to.
Scope
 Example:
Public Class frmMain
Dim var1 As Integer
Function someFunction(ByVal x As Double, ByVal y As Double) As Double
Dim var2 As String
…
End Function
Function otherFunction(ByVal x As String, ByVal y As String) As Double
Dim var3 As String
…
End Function
End Class
Function Documentation
 You should document EVERY function you write:
‘ Function Name: The name of the function
‘ Returns: Return type and brief description of what it
‘ is
‘ Parameters: Types and brief descriptions of what they are
‘ Description: Brief description of what the function does

More Related Content

PPTX
Chapter 6 slides
PDF
Unit iii vb_study_materials
PPS
Procedures functions structures in VB.Net
PPTX
Unit 6: Functions and Subroutines
PPTX
Using general sub procedures
PDF
procedures and arrays
PDF
Programming with Microsoft Visual Basic 2015 7th Edition Zak Solutions Manual
PPTX
VB Function and procedure
Chapter 6 slides
Unit iii vb_study_materials
Procedures functions structures in VB.Net
Unit 6: Functions and Subroutines
Using general sub procedures
procedures and arrays
Programming with Microsoft Visual Basic 2015 7th Edition Zak Solutions Manual
VB Function and procedure

Similar to 10 Functions.pptx DSDFDFDFDFDFDFDFDFFDFDFD (20)

PPTX
E learning excel vba programming lesson 3
PPTX
PPTX
Functions
PPT
ملخص البرمجة المرئية - الوحدة الخامسة
PPT
AVB201.1 MS Access VBA Module 1
PDF
MA3696 Lecture 9
PPT
06 procedures
PPT
AVB201.1 Microsoft Access VBA Module 1
PPTX
Understanding Subroutines and Functions in VB6
PPTX
VB Script
PPTX
Modularisation techniques new
DOCX
VBScript Functions procedures and arrays.docx
DOC
Excel Vba Basic Tutorial 1
PPT
Introduction to VB.Net By William Lacktano.ppt
PPTX
Excel VBA.pptx
PDF
Visualbasic tutorial
PPTX
Function & procedure
PPT
Visual Basic 6.0
PPTX
Functions
PPTX
9 SelectCaseAndSelectionInput (1). pptx
E learning excel vba programming lesson 3
Functions
ملخص البرمجة المرئية - الوحدة الخامسة
AVB201.1 MS Access VBA Module 1
MA3696 Lecture 9
06 procedures
AVB201.1 Microsoft Access VBA Module 1
Understanding Subroutines and Functions in VB6
VB Script
Modularisation techniques new
VBScript Functions procedures and arrays.docx
Excel Vba Basic Tutorial 1
Introduction to VB.Net By William Lacktano.ppt
Excel VBA.pptx
Visualbasic tutorial
Function & procedure
Visual Basic 6.0
Functions
9 SelectCaseAndSelectionInput (1). pptx
Ad

Recently uploaded (20)

PPT
Total quality management ppt for engineering students
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
Safety Seminar civil to be ensured for safe working.
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PDF
86236642-Electric-Loco-Shed.pdf jfkduklg
PPT
Occupational Health and Safety Management System
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPT
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
Analyzing Impact of Pakistan Economic Corridor on Import and Export in Pakist...
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PDF
PPT on Performance Review to get promotions
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
Artificial Intelligence
Total quality management ppt for engineering students
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Safety Seminar civil to be ensured for safe working.
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
III.4.1.2_The_Space_Environment.p pdffdf
86236642-Electric-Loco-Shed.pdf jfkduklg
Occupational Health and Safety Management System
Nature of X-rays, X- Ray Equipment, Fluoroscopy
R24 SURVEYING LAB MANUAL for civil enggi
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Analyzing Impact of Pakistan Economic Corridor on Import and Export in Pakist...
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PPT on Performance Review to get promotions
Information Storage and Retrieval Techniques Unit III
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Artificial Intelligence
Ad

10 Functions.pptx DSDFDFDFDFDFDFDFDFFDFDFD

  • 1. MEM 302: Introduction to Computer Programming Function Procedures
  • 2. Review  General Form of an If/Else Block… If condition Then some code Else some other code End If  General Form of a Select Case Block Select Case selector Case valueList1 action1 Case valueList2 action2 Case Else actionOfLastResort End Select
  • 3. Review  A value list can be a…(4 things)  Literal  Variable  Expression  Range  What property holds whether a radio button or check box is checked?  Checked
  • 4. Function Procedures  Functions are used in programming to break complex problems into smaller ones  We have encountered built-in functions inVB before  Int(param1)  FormatNumber(param1,param2)  These functions output a value to where they are used.  When a function outputs a value, it is said to return a value.  When a function is used, it is said to be called.  You can pass input to a function by supplying it with arguments.  Arguments are the values you pass to a function  Parameters are the local variables used in the function definition.
  • 5. Function Procedures  We can define our own functions:  General Form: Function FunctionName (ByVal var1 As Type, ByVal var2 As Type) As ReturnDataType … some code … Return expression End Function  FunctionName is the name of the function  var1 and var2 are the names of the parameters  The Types following var1 and var2 tell what type the parameters are  ReturnDataType is the type of the value that the function returns  The expression in Return expression is what value is returned by the function.
  • 6. Function Example 1  New Topics:  Programmer Defined Function  Parameters/arguments  Return Statement  Function Call
  • 7. Function Procedures  Notes:  The code for the function is called the function definition.  When calling a function, you must supply it with the same number of arguments as parameters defined in the function definition.  You can create functions with no parameters. Just leave the parentheses empty when defining the function.  A function MUST return a value.  Function names inVB:  Typically are camel case with first letter capitalized.  Follow the same naming rules as variables  Should be a verb that describe what the function does
  • 8. Function Example 2  New Topics:  Multiple Parameters/Arguments
  • 9. Scope  Scope refers to where a variable can be used (seen).  Scope is usually defined by where it was declared.  A variable declared in a function or event procedure can ONLY be used in the function or event procedure where it was declared.  A variable declared inside of a class, but not in any of its procedures can be used anywhere in the class, including in any of its procedures.  Parameters can be used ONLY in the function they belong to.
  • 10. Scope  Example: Public Class frmMain Dim var1 As Integer Function someFunction(ByVal x As Double, ByVal y As Double) As Double Dim var2 As String … End Function Function otherFunction(ByVal x As String, ByVal y As String) As Double Dim var3 As String … End Function End Class
  • 11. Function Documentation  You should document EVERY function you write: ‘ Function Name: The name of the function ‘ Returns: Return type and brief description of what it ‘ is ‘ Parameters: Types and brief descriptions of what they are ‘ Description: Brief description of what the function does