0% found this document useful (0 votes)
157 views2 pages

CS116 Week 5 Lecture

CS116Week5Lecture
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
157 views2 pages

CS116 Week 5 Lecture

CS116Week5Lecture
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Overview

InVisualBasic,proceduresarestatementsorcollectionsofstatementsthatwill
performtasks(e.g.eventhandlers).Generalpurposeproceduresdonotrelyon
events.Functions,likeprocedures,consistofstatements(orcollectionsof
statements)whichperformtasksbutalsoreturnvaluestotheexecutionpoint.
Collectivelybothfunctionsandproceduresarereferredtoas

methods.
Modularizingcodeisawaytobreakdowncodeintomoremanageablegroupsor
sectionsthatsavetimeandeffortaswellasavoidredundancy.Ratherthan
repeatingprocedures,theprocedurecanbewrittenonetimeand"called"when
needed.

Notethewordssubandendsub.Alsonotehow,unlikeinmorespecificprocedures
likeeventhandlers,thereisnoprefixinfrontofthecontrol.Generalpurpose
proceduresarenotassociatedwithcontrols.

ExecutingProcedures

Nowthatwehaveageneralpurposeprocedure,howdoweexecuteit?Writinga
procedurecallwilltriggerexecution.Whenweneedtheprocedure,itwillbecalled
usingthenamedeclaredfortheprocedure:

Oronecansimplycalltheprocedureusingthecallkeyword.
CallDisplayMessage
Proceduresaredeclaredusing:

Proceduresarenamedusingscalecasing,inotherwordscapitalizingeverywordin
thename.Parametersreceivevaluespassedintoprocedures.Therearealsovalues
calledarguments.Argumentscanbepassedbyvalue(acopyispassedtothe
procedure)andbyreference(allowingtheprocedureaccesstotheoriginalargument
aswellistheabilitytomakechanges).
Functions,aspreviouslydiscussed,returnvaluestothepointintheprogramfor
whichtheywerecalled.Afunctiondeclarationfollowsthebasicformat:

Inbothproceduresandfunctions,accesscanbespecifiedusingtheAccessSpecifier
aheadofthefirstlineusingkeywordslikePublic,Protected,Private,andmore.
ThedefaultisPublicifnootherspecifierischosen.

You might also like