SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (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
 

Similar a 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
 

Similar a 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
 

Último

Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Celine George
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 

Último (20)

Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 

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