Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 10 Creating Modules and Procedures 271


To Do This
Call a Function
procedure

Type the function name and any necessary arguments in a program
statement, and assign it to a variable or property of the appropriate
return type. For example:
lblRate.Text = HitRate(Wins, Spins)
Create a public
Sub procedure

Place the procedure statements between the Sub and End Sub keywords
in a module. Sub procedures are public by default. For example:
Sub CostPlusInterest(ByVal Cost As Single, _
ByRef Total As Single)
Cost = Cost * 1.05
Total = Int(Cost)
End Sub
Call a Sub procedure Type the procedure name and any necessary arguments in a program
statement. For example:
CostPlusInterest(Price, TotalPrice)
Pass an argument
by value

Use the ByVal keyword in the procedure declaration. For example:
Sub GreetPerson(ByVal Name As String)
Pass an argument
by reference

Use the ByRef keyword in the procedure declaration. For example:
Sub GreetPerson(ByRef Name As String)
Free download pdf