Chapter 10 Quick Reference


Chapter 10 Quick Reference

To

Do this

Create a new module

Click the Add New Item button on the Standard toolbar, and then select the Module template.

or

Click the Add New Item command on the Project menu, and then select the Module template.

Save a module with a new name

Select the module in Solution Explorer, click the Save Module1.vb As command on the File menu, and then specify a new name.

Remove a module from a program

Select the module in Solution Explorer, and then click the Exclude From Project command on the Project menu.

Add an existing module to a project

On the Project menu, click the Add Existing Item command.

Create a public variable

Declare the variable by using the Public keyword between the Module and End Module keywords in a module. For example:

Public TotalSales As Integer

Create a public function

Place the function statements between the Function and End Function keywords in a module. Functions are public by default. For example:

Function HitRate(ByVal Hits As Short, ByVal _    Tries As Short) As String      Dim Percent As Single      Percent = Hits / Tries      Return Format(Percent, "0.0%") End Function

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)



Microsoft Visual Basic 2005 Step by Step
Microsoft Visual Basic 2005 Step by Step (Step by Step (Microsoft))
ISBN: B003E7EV06
EAN: N/A
Year: 2003
Pages: 168

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net