SlideShare une entreprise Scribd logo
1  sur  34
Visual Basic Chapter 6 - Procedures
Sub Procedures Sub Procedure - A set of statements that perform a specific task. Divide a program into smaller, more manageable blocks of code. An event procedure is written for a specific object event, while a sub procedure can perform tasks unrelated to any specific event. Form:Sub ProcedureName()     statementsEnd Sub
Sub Procedures ProcedureName - A name describing the task performed by the procedure. Should indicate an action Should begin with an uppercase letter and then an uppercase letter should begin each word within the name  (Like standard variable declarations.) May not contain spaces Sub procedures divide a program into a smaller, more manageable blocks of code.
Sub Procedures Sub Procedures result in less code redundancy Statements for a specific task appear just once in the Sub procedure. Example on page 163 A Sub procedure must be called with a Call statement from another procedure in order to execute. ,[object Object],[object Object]
Changing an Image at Run Time Images must be stored in the Resources folder in the project folder. The My.Resources object is used to access an image Form:My.pictureBox.Image = My.Resources.imageNamepictureBox- name of the PictureBox objectimageName- name of the resource in the Resources folder
The LinkLabel Control The LinkLabel Control is used to add a link to a website. (Name) should begin withlnk. ActiveLinkColor sets the color of the link when clicked. LinkColor sets the color of the link. Text sets the text for the destination website. VisitedLinkColor sets the color of a previously visited link.
Review: PetStorepage 165
Value Parameters A procedure often needs data in order to complete its task. pass - giving data to a procedure argument - a variable or value passed to a procedure Call GiveHint(secretNumber, guess) arguments: secretNumber, guess parameter - a variable declared in a procedure to accept the value or address of an argument
Value Parameters Parameters are used inside the procedure to perform the procedure's task. Form:Sub ProcedureName(ByValparameter1 As type, ...) statements End Sub ByVal- keyword used to declare a value parameter in a procedure or function.
Value Parameters value parameter -a variable declaration in a procedure to accept a copy of an argument. cannot alter the value of the actual arguments used in the procedure call. GiveHint() example - page 167 Remember when working with procedures that have value parameters: The order of the arguments passed corresponds to the order of the parameters in the procedure heading.
Value Parameters The number of arguments in a procedure call must match the number of parameters in the procedure declaration. Arguments passed by value can be in the form of constants, variables, values, or expressions. Variable arguments passed by value are not changed by the procedure. Example: Demo() - page 168
Procedure Documentation Just as comments are used to clarify statements, comments should also be used to describe, or document, procedures. Procedure documentation should include a brief description of what the procedure does. Documentation should also include preconditions and postconditions. precondition - The initial requirements of a procedure (e.g. assumptions).  Also referred to as “pre”.
Procedure Documentation postcondition - A statement of what must be true at the end of the execution of a procedure if the procedure has worked properly.  Also referred to as “post”. Note: A procedure may not have a precondition, but every procedure must have a postcondition. Example: GiveHint() - pages 168-169
Review: GuessingGame - part 3 of 4page 169
Reference Parameters reference parameter - A variable declared in a procedure to accept to address of an argument. Can alter the value of the variable arguments used in the procedure call Form: Sub ProcedureName(ByRefparameter1 As type, ...) statements End Sub
Reference Parameters ByRef - Keyword used to declare a reference parameter in a procedure. Note: A procedure can have both reference (ByRef) and value (ByVal) parameters.Example:TwoDigits()- page 170 address - A variable’s location in memory where its value is stored. ,[object Object],[object Object]
Reference Parameters Keep in mind when working with procedures with reference parameters: The order of the arguments passed corresponds to the order of the parameters in the procedure heading. ByRef parameters accept only variable arguments. Variable arguments passed by reference may be changed by the procedure.
Review: NumberBreakdownpage 171Review: SortNumberspage 173
Control Object Parameters Control objects, such as labels, are a data type called a control class. Includes CheckBox, Label, RadioButton, Button, TextBox and PictureBox controls. A control object can be passed as an argument to a procedure. Control argument parameters should be declared  ByRef in a procedure using the appropriate class name. Example: GiveHint() - page 174
Review: GuessingGame - part 4 of 4page 174
Event Handler Procedures Event procedures are used in every program. Called event handler procedures because they execute in response to an event. Can be written to handle more than one event. In the following example, the event procedure executes when the check box is clicked:
Event Handler Procedures Handles - Keyword that determines which events cause an event procedure to execute. Event procedure declarations include the Handles keyword followed by the events to be handled. The keyword, not the procedure name, determines when an event procedure executes. Therefore, changing an event procedure name has no effect on procedure execution. Event procedures handle multiple events when event names, separated by commas, are added after the Handles keyword.
Event Handler Procedures Event procedures always include two parameters: An object to raise the event Information about the event  chkRelish_Click example: ,[object Object]
e is the information about the eventObject - A data type that can be used to represent any value.
The HotDog Application
The Tag Property Every control has a Tag property. tag - Control class property that can be set to a string expression for identifying objects. When an event procedure is handling more than one object, the string in the Tag property can be used to determine which object raised the event. Important when different actions should be taken for different objects. Example: Page 176
Review: ShellGamepage 176
Function Procedures function - A set of statements that perform a specific task and then return a value. Built-in functions include Int() and Rnd(). Form:Function ProcedureName(ByValparameter1 As _ type, ...) As Returntypestatements   Return valueEnd Function Return - Statement used in a function procedure to send a value back to the calling statement.
Function Procedures Function Procedures are called from within an assignment statement or another type of statement that will make use of the returned value. Example:Me.lblStudentGrade.Text = LetterGrade(average) See page 180. Note: A function is a better choice over a Sub procedure when a well-defined task that results in a single value is to be performed.
Function Procedures Keep in mind the following when working with functions: The order of the arguments corresponds to the order of the parameters. Only ByVal parameters should be declared in a function because a function should not alter the arguments it has been passed. A function returns a single value and therefore must be used in a statement such as an assignment statement that makes use of the returned value.
Review: LetterGradepage 181
Coding Conventions Procedures names should indicate an action and begin with an uppercase letter and then an uppercase letter should begin each word within the name. Procedure documentation should include a brief description of the task the procedure performs, a precondition when needed, and a postcondition.
Case Study: CalculatorIIpage 182Review: CalculatorII 1 of 2page 189Review: CalculatorII 2 of 2page 189Review: TestRndIntFunctionpage 189
Chapter 6 slides

Contenu connexe

Tendances

Tendances (20)

Functions assignment
Functions assignmentFunctions assignment
Functions assignment
 
Presentation of computer
Presentation of computerPresentation of computer
Presentation of computer
 
4. function
4. function4. function
4. function
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
Python algorithm
Python algorithmPython algorithm
Python algorithm
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
Function
FunctionFunction
Function
 
Processes in Query Optimization in (ABMS) Advanced Database Management Systems
Processes in Query Optimization in (ABMS) Advanced Database Management Systems Processes in Query Optimization in (ABMS) Advanced Database Management Systems
Processes in Query Optimization in (ABMS) Advanced Database Management Systems
 
Qtp Presentation
Qtp PresentationQtp Presentation
Qtp Presentation
 
Booa8 Slide 09
Booa8 Slide 09Booa8 Slide 09
Booa8 Slide 09
 
Python recursion
Python recursionPython recursion
Python recursion
 
Maximum Price Limitation
Maximum Price LimitationMaximum Price Limitation
Maximum Price Limitation
 
Procedures functions structures in VB.Net
Procedures  functions  structures in VB.NetProcedures  functions  structures in VB.Net
Procedures functions structures in VB.Net
 
Basics of cpp
Basics of cppBasics of cpp
Basics of cpp
 
Understanding Subroutines and Functions in VB6
Understanding Subroutines and Functions in VB6Understanding Subroutines and Functions in VB6
Understanding Subroutines and Functions in VB6
 
VB Function and procedure
VB Function and procedureVB Function and procedure
VB Function and procedure
 
Class 10
Class 10Class 10
Class 10
 
Python - Lecture 2
Python - Lecture 2Python - Lecture 2
Python - Lecture 2
 

Similaire à Chapter 6 slides

Function & procedure
Function & procedureFunction & procedure
Function & procedureatishupadhyay
 
Unit iii vb_study_materials
Unit iii vb_study_materialsUnit iii vb_study_materials
Unit iii vb_study_materialsgayaramesh
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxvekariyakashyap
 
Functions and Arguments in Python
Functions and Arguments in PythonFunctions and Arguments in Python
Functions and Arguments in PythonMars Devs
 
procedures and arrays
procedures and arraysprocedures and arrays
procedures and arraysDivyaR219113
 
Day2 j meter_training_script_enhancements
Day2 j meter_training_script_enhancementsDay2 j meter_training_script_enhancements
Day2 j meter_training_script_enhancementsSravanthi N
 
Day2_Apache_JMeter_Script_Enhancements
Day2_Apache_JMeter_Script_EnhancementsDay2_Apache_JMeter_Script_Enhancements
Day2_Apache_JMeter_Script_EnhancementsSravanthi N
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfTeshaleSiyum
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdfTeshaleSiyum
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1YOGESH SINGH
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c languageTanmay Modi
 

Similaire à Chapter 6 slides (20)

Function & procedure
Function & procedureFunction & procedure
Function & procedure
 
Unit iii vb_study_materials
Unit iii vb_study_materialsUnit iii vb_study_materials
Unit iii vb_study_materials
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
 
Functions and Arguments in Python
Functions and Arguments in PythonFunctions and Arguments in Python
Functions and Arguments in Python
 
procedures and arrays
procedures and arraysprocedures and arrays
procedures and arrays
 
Day2 j meter_training_script_enhancements
Day2 j meter_training_script_enhancementsDay2 j meter_training_script_enhancements
Day2 j meter_training_script_enhancements
 
Day2_Apache_JMeter_Script_Enhancements
Day2_Apache_JMeter_Script_EnhancementsDay2_Apache_JMeter_Script_Enhancements
Day2_Apache_JMeter_Script_Enhancements
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdf
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdf
 
Cpp functions
Cpp functionsCpp functions
Cpp functions
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
Savitch ch 04
Savitch ch 04Savitch ch 04
Savitch ch 04
 
Python-Functions.pptx
Python-Functions.pptxPython-Functions.pptx
Python-Functions.pptx
 
Unit iv functions
Unit  iv functionsUnit  iv functions
Unit iv functions
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
 
Subprogramms
SubprogrammsSubprogramms
Subprogramms
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
Function in c
Function in cFunction in c
Function in c
 

Dernier

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Dernier (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 

Chapter 6 slides

  • 1. Visual Basic Chapter 6 - Procedures
  • 2. Sub Procedures Sub Procedure - A set of statements that perform a specific task. Divide a program into smaller, more manageable blocks of code. An event procedure is written for a specific object event, while a sub procedure can perform tasks unrelated to any specific event. Form:Sub ProcedureName() statementsEnd Sub
  • 3. Sub Procedures ProcedureName - A name describing the task performed by the procedure. Should indicate an action Should begin with an uppercase letter and then an uppercase letter should begin each word within the name (Like standard variable declarations.) May not contain spaces Sub procedures divide a program into a smaller, more manageable blocks of code.
  • 4.
  • 5. Changing an Image at Run Time Images must be stored in the Resources folder in the project folder. The My.Resources object is used to access an image Form:My.pictureBox.Image = My.Resources.imageNamepictureBox- name of the PictureBox objectimageName- name of the resource in the Resources folder
  • 6. The LinkLabel Control The LinkLabel Control is used to add a link to a website. (Name) should begin withlnk. ActiveLinkColor sets the color of the link when clicked. LinkColor sets the color of the link. Text sets the text for the destination website. VisitedLinkColor sets the color of a previously visited link.
  • 8. Value Parameters A procedure often needs data in order to complete its task. pass - giving data to a procedure argument - a variable or value passed to a procedure Call GiveHint(secretNumber, guess) arguments: secretNumber, guess parameter - a variable declared in a procedure to accept the value or address of an argument
  • 9. Value Parameters Parameters are used inside the procedure to perform the procedure's task. Form:Sub ProcedureName(ByValparameter1 As type, ...) statements End Sub ByVal- keyword used to declare a value parameter in a procedure or function.
  • 10. Value Parameters value parameter -a variable declaration in a procedure to accept a copy of an argument. cannot alter the value of the actual arguments used in the procedure call. GiveHint() example - page 167 Remember when working with procedures that have value parameters: The order of the arguments passed corresponds to the order of the parameters in the procedure heading.
  • 11. Value Parameters The number of arguments in a procedure call must match the number of parameters in the procedure declaration. Arguments passed by value can be in the form of constants, variables, values, or expressions. Variable arguments passed by value are not changed by the procedure. Example: Demo() - page 168
  • 12. Procedure Documentation Just as comments are used to clarify statements, comments should also be used to describe, or document, procedures. Procedure documentation should include a brief description of what the procedure does. Documentation should also include preconditions and postconditions. precondition - The initial requirements of a procedure (e.g. assumptions). Also referred to as “pre”.
  • 13. Procedure Documentation postcondition - A statement of what must be true at the end of the execution of a procedure if the procedure has worked properly. Also referred to as “post”. Note: A procedure may not have a precondition, but every procedure must have a postcondition. Example: GiveHint() - pages 168-169
  • 14. Review: GuessingGame - part 3 of 4page 169
  • 15. Reference Parameters reference parameter - A variable declared in a procedure to accept to address of an argument. Can alter the value of the variable arguments used in the procedure call Form: Sub ProcedureName(ByRefparameter1 As type, ...) statements End Sub
  • 16.
  • 17. Reference Parameters Keep in mind when working with procedures with reference parameters: The order of the arguments passed corresponds to the order of the parameters in the procedure heading. ByRef parameters accept only variable arguments. Variable arguments passed by reference may be changed by the procedure.
  • 19. Control Object Parameters Control objects, such as labels, are a data type called a control class. Includes CheckBox, Label, RadioButton, Button, TextBox and PictureBox controls. A control object can be passed as an argument to a procedure. Control argument parameters should be declared ByRef in a procedure using the appropriate class name. Example: GiveHint() - page 174
  • 20. Review: GuessingGame - part 4 of 4page 174
  • 21. Event Handler Procedures Event procedures are used in every program. Called event handler procedures because they execute in response to an event. Can be written to handle more than one event. In the following example, the event procedure executes when the check box is clicked:
  • 22. Event Handler Procedures Handles - Keyword that determines which events cause an event procedure to execute. Event procedure declarations include the Handles keyword followed by the events to be handled. The keyword, not the procedure name, determines when an event procedure executes. Therefore, changing an event procedure name has no effect on procedure execution. Event procedures handle multiple events when event names, separated by commas, are added after the Handles keyword.
  • 23.
  • 24. e is the information about the eventObject - A data type that can be used to represent any value.
  • 26. The Tag Property Every control has a Tag property. tag - Control class property that can be set to a string expression for identifying objects. When an event procedure is handling more than one object, the string in the Tag property can be used to determine which object raised the event. Important when different actions should be taken for different objects. Example: Page 176
  • 28. Function Procedures function - A set of statements that perform a specific task and then return a value. Built-in functions include Int() and Rnd(). Form:Function ProcedureName(ByValparameter1 As _ type, ...) As Returntypestatements Return valueEnd Function Return - Statement used in a function procedure to send a value back to the calling statement.
  • 29. Function Procedures Function Procedures are called from within an assignment statement or another type of statement that will make use of the returned value. Example:Me.lblStudentGrade.Text = LetterGrade(average) See page 180. Note: A function is a better choice over a Sub procedure when a well-defined task that results in a single value is to be performed.
  • 30. Function Procedures Keep in mind the following when working with functions: The order of the arguments corresponds to the order of the parameters. Only ByVal parameters should be declared in a function because a function should not alter the arguments it has been passed. A function returns a single value and therefore must be used in a statement such as an assignment statement that makes use of the returned value.
  • 32. Coding Conventions Procedures names should indicate an action and begin with an uppercase letter and then an uppercase letter should begin each word within the name. Procedure documentation should include a brief description of the task the procedure performs, a precondition when needed, and a postcondition.
  • 33. Case Study: CalculatorIIpage 182Review: CalculatorII 1 of 2page 189Review: CalculatorII 2 of 2page 189Review: TestRndIntFunctionpage 189