A project isn't the same as an applicationA project is the thing you use to create an application, such as a "traditional" program, a dynamic link library, or an ActiveX control. Think of creating a Visual Basic program like baking a cake: you mix ingredients together, bake them, and pull a cake out of the oven. Similarly, you put forms, modules, and controls together, compile them, and get a Visual Basic application.
In Visual Basic, a project is the group of all the files that make up your program. These might include forms, modules (blocks of code not attached to a form), graphics, and ActiveX controls. Other types of files may also be part of a project, but don't worry about that now.
The first thing to keep in mind about a project is that as you create your program, each form, module, graphic, and ActiveX control is saved as an individual file (see Table 5.1).
File Type | Description |
FRM | Form |
BAS | Module |
FRX | Automatically generated file for every graphic in your project |
OCX | ActiveX control |
CLS | Class module |
VBP | Visual Basic project |
Detailed information about all your program's files is stored in the project file. The project file lists all the files your program uses, as well as details such as the project name and how the IDE should be configured while you work on this particular project. Project files have the extension VBP.
You can keep track of all the files in your project with the Project Explorer, a window found on the right side of the Visual Basic IDE (see Figure 5.1). The Project Explorer provides a method to organize your project's files and allows you to access them individually in form or code view.
FIGURE 5.1 Use the Project Explorer to keep track of files in your project. Note that OCX and FRX files aren't listed in the Project Explorer.
Most of your interaction with the Project Explorer will be with its context menu. When you right-click one of your project's files, you'll see a menu similar to that shown in Figure 5.2.
FIGURE 5.2 Most of the interaction with your project will be through the Project Explorer's context menu.
The context menu allows you to
Every time you run Visual Basic, you'll see the New Project dialog (see Figure 5.3). From this window, you can simply select the type of project you want to create and click Open.
FIGURE 5.3 Use the New Project dialog to create a project.
It's also possible to start a new project while Visual Basic is already running.
Starting a new project
Many pieces of information are required to describe a project, including the project name, the version number, and the title that will appear in the title bar of the finished application. Many others can be accessed via the Project Properties dialog (see Figures 5.4 and 5.5).
FIGURE 5.4 You set your project's type, name, and help file on the General page. You can also add a project description.
FIGURE 5.5 On the Make page, you can set your project's version number and version-specific information, as well as the project title and icon.
Access the Project Properties dialog
When you save your project, you actually save each individual part of your project (every form, module, graphic, and so forth) as an individual file, and then save the project file itself. When you save your project for the first time, Visual Basic automatically suggests a name for each file. This filename will be the same as the name of the form (or module, graphic, and so on), with an appropriate extension for the type of file you're saving (refer to Table 5.1). Thus, a module named modStart would be named modStart.bas because modules have the extension .bas.
Save a project
FIGURE 5.6 Visual Basic automatically suggests the filename frmFirst.frm for a form named frmFirst.
Changing filenamesYou don't have to use the filename VB suggests, but you should be careful to use a name that allows you to remember what the file does. If you've already named your files with friendly names, following the VB convention will help you avoid confusion when your project contains large numbers of files. You also should always use the filename extension that Visual Basic suggests, to ensure that all your files can easily be found when you open a file from within Visual Basic.
If you've worked on the file recently, open the File menu. At the bottom of this menu is a list of the files you have most recently worked on. Select the appropriate file to open it. If the desired project doesn't appear in this list, you'll have to look for it.
Opening files when you start Visual BasicWhen you first start Visual Basic, the New Project dialog usually appears. You can save yourself some time by selecting a recent or existing project directly from this dialog. If you don't want this dialog to appear each time you start Visual Basic, deselect the check box at the bottom of this window.
Opening an existing project
FIGURE 5.7 Open existing or recent projects with the Open Project dialog.
Often, your programs will require more than one form or module. For example, if you want to have an About dialog in your program, it will require that you add a form.
You can add new files to your project in two ways: by selecting the file type (such as form or module) that you want to add from the Project menu, or by adding files from the Project Explorer.
Adding new files from the Project Explorer
Whichever method you use, you may be prompted with a dialog that allows you to pick a specific type of form or module to add (see Figure 5.8). Visual Basic provides templates for commonly used files, such as an About dialog, to save you the time and effort of creating it yourself.
FIGURE 5.8 Visual Basic contains many templates for creating commonly used forms.
You can also add existing files to your project, which comes in handy if you want to use a form or module that you previously created for a different project. Adding an existing file is very similar to adding a new file, except that you choose Add File from the Project menu or from the Project Explorer's context menu (see Figure 5.9).
Why should you remove or delete a file?If you don't remove an unnecessary file from your project, it will be included in your program after you compile it. Also, when you remove a file from a project, you don't actually delete the file from your hard drive. To delete the file completely, use Windows Explorer.
If there's a file in your project that you don't want (for example, a form you added accidentally or a module that contains a form you no longer need), you can remove it from the project list.
Removing a file from a project
FIGURE 5.9 Add existing files to your project by selecting Add File.
You also can highlight the file in the Project Explorer and choose Remove filename from the Project menu.
Visual Basic 6 allows you to work with more than one project at a time. As you might imagine, working with multiple forms and modules that are used in different projects can get pretty confusing. To keep track of everything, you can use the Project Explorer and a project group, which is a collection of projects (see Figure 5.10). Project Groups can be saved as a file, just like a form, module, or project. They have the extension .vbg.
Add a project to a project group
FIGURE 5.10 The Project Explorer allows you to track multiple projects at one time by using project groups. The project in boldface type is the project that runs when you press F5.
Project groups don't really become important until you start creating ActiveX controls,
which require you to have multiple projects open at the same time. So don't worry
about project groups right now. Just keep in mind that it's possible to have more
than one project open at the same time.
© Copyright, Macmillan Computer Publishing. All rights reserved.