+ All Categories
Home > Documents > © 2012 EMC Publishing, LLC Slide 1 Chapter 6 Sub Procedures A set of statements that perform a...

© 2012 EMC Publishing, LLC Slide 1 Chapter 6 Sub Procedures A set of statements that perform a...

Date post: 02-Jan-2016
Category:
Upload: stewart-brooks
View: 214 times
Download: 0 times
Share this document with a friend
Popular Tags:
17
© 2012 EMC Publishing, LLC Slide 1 Chapter 6 Sub Procedures A set of statements that perform a specific task. Divide a program into smaller, more manageable blocks of code-> “Divide et impera” = “Divide and conquer” 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. May not contain spaces. Executed by using a Call statement.
Transcript

© 2012 EMC Publishing, LLC

Slide 1

Chapter 6

Sub ProceduresChapter 6

Sub Procedures A set of statements that perform a specific

task.

Divide a program into smaller, more manageable blocks of code-> “Divide et impera” = “Divide and conquer”

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. May not contain spaces.

Executed by using a Call statement.

© 2012 EMC Publishing, LLC

Slide 2

Chapter 6

The PictureBox ControlChapter 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.

A Click event procedure is sometimes coded for a picture box. It executes when user clicks image.

© 2012 EMC Publishing, LLC

Slide 3

Chapter 6

Changing an Image at Run TimeChapter 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 at run time:My.pictureBox.Image = My.Resources.imageName

© 2012 EMC Publishing, LLC

Slide 4

Chapter 6

The LinkLabel ControlChapter 6

The LinkLabel Control

The LinkLabel Control is used to add a link to a website

(Name) id for programmer. Prefix: lnk 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

© 2012 EMC Publishing, LLC

Slide 5

Chapter 6

Value ParametersChapter 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.

Data passed to a procedure is called the arguments.

Call ProcedureName(parameter1, parameter2)…Sub ProcedureName(ByVal parameter1 As type,

ByVal parameter2) StatementsEnd Sub

© 2012 EMC Publishing, LLC

Slide 6

Chapter 6

Value Parameters (cont.)

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.

© 2012 EMC Publishing, LLC

Slide 7

Chapter 6

Procedure DocumentationChapter 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.

© 2012 EMC Publishing, LLC

Reference ParametersReference Parameters

A procedure can use reference parameters to send values back to the calling procedure. Reference parameters can alter the variables used in the procedure call

Syntax:

Sub ProcedureName(ByRef parameter1 As type,…)

Statements

End Sub A procedure can have both reference (ByRef)

and value (ByVal) parameters.

Slide 8

© 2012 EMC Publishing, LLC

Slide 9

Chapter 6

Reference Parameters (cont.)Chapter 6

Reference Parameters (cont.)

© 2012 EMC Publishing, LLC

Slide 10

Chapter 6

Reference Parameters (cont.)

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.

© 2012 EMC Publishing, LLC

Slide 11

Chapter 6

Control Object ParametersChapter 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.

Example:

Call GiveHint(Me.lblMessage, secretNumber, guess)

Control argument parameters should be declared ByRef in a procedure using the appropriate class name.

© 2012 EMC Publishing, LLC

Slide 12

Chapter 6

Event Handler ProceduresChapter 6

Event Handler Procedures Execute in response to events

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.

© 2012 EMC Publishing, LLC

Slide 13

Chapter 6

Event Handler ProceduresChapter 6

Event Handler Procedures Event procedures always include 2

parameters: sender and e

sender = the object that raised the event. Data type is Object that can be used to represent any value

e = info about the event. Data type is System.EventArgs

An Event Procedure can handle multiple events (event names separated by commas added after the Handles keyword)

© 2012 EMC Publishing, LLC

Slide 14

Chapter 6

The HotDog ApplicationChapter 6

The HotDog Application

© 2012 EMC Publishing, LLC

Slide 15

Chapter 6

The Tag PropertyChapter 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.

The Tag property is set to a descriptive string and its value is used to determine which action to take.

© 2012 EMC Publishing, LLC

Slide 16

Chapter 6

Function ProceduresChapter 6

Function Procedures

A set of statements that perform a specific task and then return a value.

Built-in functions include Int() and Rnd().

Syntax:

Function ProcedureName(ByVal parm1 As type…) As Returntype

statements

Return value

End Function

© 2012 EMC Publishing, LLC

Slide 17

Chapter 6

Function ProceduresChapter 6

Function Procedures

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.


Recommended