Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 6 Sub Procedures

Similar presentations


Presentation on theme: "Chapter 6 Sub Procedures"— Presentation transcript:

1 Chapter 6 Sub Procedures
11/16/2018 6:49 PM Chapter 6 Sub Procedures 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. Procedure names should begin with an uppercase letter and then an uppercase letter should begin each word within the name. Executed by using a Call statement. Refer to page 163 in the text. © 2010 Lawrenceville Press

2 Chapter 6 The PictureBox Control
11/16/2018 6:49 PM Chapter 6 The PictureBox Control (Name) should begin with pic. Image is used to add images to the Resource folder with the selected image displayed in the picture box. SizeMode is typically set to AutoSize so that the picture box is automatically sized to the image size. Visible is set to False to hide an image at run time. Size changes automatically when SizeMode is AutoSize. Refer to page 164 in the text. A Click event procedure is sometimes coded for a picture box. © 2010 Lawrenceville Press

3 Chapter 6 Changing an Image at Run Time
11/16/2018 6:49 PM Chapter 6 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: My.pictureBox.Image = My.Resources.imageName Refer to page 165 in the text. © 2010 Lawrenceville Press

4 Chapter 6 The LinkLabel Control
11/16/2018 6:49 PM Chapter 6 The LinkLabel Control The LinkLabel Control is used to add a link to a website Refer to page 165 in the text. © 2010 Lawrenceville Press

5 Chapter 6 Value Parameters
11/16/2018 6:49 PM Chapter 6 Value Parameters A procedure can have parameters for accepting values from a calling statement. Parameters are used inside the procedure to perform the procedure's task. The data passed to a procedure are called the arguments. GiveHint() has two parameters: Sub GiveHint(ByVal firstNum As Integer, _ ByVal secondNum As Integer) … Refer to page 167 in the text. © 2010 Lawrenceville Press

6 Chapter 6 Value Parameters (cont.)
11/16/2018 6:49 PM Chapter 6 Value Parameters (cont.) The order of the arguments passed corresponds to the order of the parameters in the procedure heading. 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. Refer to pages 167 and 168 in the text. © 2010 Lawrenceville Press

7 Chapter 6 Procedure Documentation
11/16/2018 6:49 PM Chapter 6 Procedure Documentation Procedure documentation should include a brief description of what the procedure does. Documentation should also include the assumptions, or initial requirements, of a procedure called preconditions (pre:). Documentation should include a postcondition (post:), which is what must be true at the end of the execution of a procedure if the procedure has worked properly. Refer to page 168 in the text. © 2010 Lawrenceville Press

8 Chapter 6 Reference Parameters
11/16/2018 6:49 PM Chapter 6 Reference Parameters Refer to page 170 in the text. © 2010 Lawrenceville Press

9 Chapter 6 Reference Parameters (cont.)
11/16/2018 6:49 PM Chapter 6 Reference Parameters (cont.) 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. Refer to page 170 in the text. © 2010 Lawrenceville Press

10 Chapter 6 Control Object Parameters
11/16/2018 6:49 PM Chapter 6 Control Object Parameters Control objects are a data type called a control class. 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. Refer to page 173 in the text. © 2010 Lawrenceville Press

11 Chapter 6 Event Handler Procedures
11/16/2018 6:49 PM Chapter 6 Event Handler Procedures Can be written to handle more than one event. Procedure name can be changed because the events after the Handles keyword is what indicates when the procedure will execute. Refer to page 174 in the text. © 2010 Lawrenceville Press

12 Chapter 6 The HotDog Application
11/16/2018 6:49 PM Chapter 6 The HotDog Application Refer to page 175 in the text. © 2010 Lawrenceville Press

13 Chapter 6 The Tag Property
11/16/2018 6:49 PM Chapter 6 The Tag Property Every control has a Tag property. Can be set to a string that is useful for identifying the object. 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. Refer to page 175 in the text. © 2010 Lawrenceville Press

14 Chapter 6 Function Procedures
11/16/2018 6:49 PM Chapter 6 Function Procedures A set of statements that perform a specific task and then return a value. Built-in functions include Int() and Rnd(). A function often has at least one parameter for data that is required to perform its task. Parameters are ByVal because a function returns a single value without changing argument values. Called from within an assignment statement or another type of statement that will make use of the returned value. Refer to pages 179 and 180 in the text. © 2010 Lawrenceville Press


Download ppt "Chapter 6 Sub Procedures"

Similar presentations


Ads by Google