Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 10 Creating Modules and Procedures 251



  1. Return the Properties window and Solution Explorer to their regular docked positions
    by pressing the CTRL key and double-clicking their title bars.
    As you can see, working with modules in a project is a lot like working with forms. In the next
    exercise, you’ll add a public variable to a module.


Tip To remove a module from a project, click the module in Solution Explorer, and then click the
Exclude From Project command on the Project menu. (Visual Basic 2010 Express does not include
the Exclude From Project command .) Exclude From Project doesn’t delete the module from your
hard disk, but it does remove the link between the specified module and the current project.
You can reverse the effects of this command by clicking the Add Existing Item command on the
Project menu, selecting the file that you want to add to the project, and then clicking Add.

Working with Public Variables


Declaring a global, or public, variable in a module is simple—you type the keyword Public
followed by the variable name and a type declaration. After you declare the variable, you
can read it, change it, or display it in any procedure in your program. For example, the
program statement:
Public RunningTotal As Integer
declares a public variable named RunningTotal of type Integer.
The following exercises demonstrate how you can use a public variable named Wins in
a module. You’ll revisit Lucky Seven, the first program you created in this book, and you’ll
use the Wins variable to record how many spins you win as the slot machine runs.

Note Lucky Seven is the slot machine program from Chapter 2, “Writing Your First Program .”

Revisit the Lucky Seven project


  1. Click the Close Project command on the File menu to close the Module Test project.


Because you have named (but not saved) the project yet, you see the following
dialog box:
Free download pdf