Using Project Templates

[Previous] [Next]

It seems as though software development these days is largely focused on reuse. Programming with objects is one of the hottest topics for programmers, and objects are really all about code reuse. It only makes sense that if you can take advantage of previous development by using some or all of an existing object, you can reduce development and testing time. Creating object templates as I discussed at the beginning of this chapter is a great way to make common objects easily accessible to new and existing projects. In addition to enabling you to make object templates, Visual Basic also gives you the ability to create complete project templates.

Exploring Visual Basic Project Templates

Project templates can be skeletal templates containing a few base objects, such as a form and a module, or they can be half-completed applications containing intricate code, such as a multiple-document interface (MDI) front end. To see examples of project templates, you need go no further than starting up Visual Basic itself. If you haven't disabled the New Project dialog box shown in Figure 2-3see "Enabling and Disabling Templates" later in this chapterit will be displayed each time you start Visual Basic. The default project templates displayed in this dialog box are installed with Visual Basic. These project templates are located in the Template\Projects folder in the main Visual Basic folder. (See Figure 2-4.)

click to view at full size.

Figure 2-3. Visual Basic's available projects for new development are simply default templates.

click to view at full size.

Figure 2-4. Visual Basic project templates are located in the Template\Projects folder.

When you double-click a project icon in the New Project dialog box, Visual Basic creates a temporary copy of the corresponding project file from the Template\Projects folder. When you save the project, Visual Basic asks you to name all the objects within the project as well as the project itself. This behavior is much the same as when you are adding objects based on templates to a projectVisual Basic never overwrites the original template files.

You can make changes to Visual Basic's default templates, except to the basic projects: Standard EXE, ActiveX EXE, and ActiveX DLL. To modify any of the existing project templates, you must open the projects directly. When you open a project template directly, rather than create a new project based on the template, Visual Basic treats the template like any other project. When you save changes, the actual template files are overwritten with your modifications. This is a great way to tweak standard project templates so that they're more immediately usable in your environment.

Creating Custom Project Templates

Modifying the existing project templates is one way to promote consistency and jump-start your new projects, but it's not the only way. A much better approach is to create your own project templates. By creating custom project templates, you remove the risk of having your templates overwritten in the event that you need to reinstall Visual Basic. To create a new project template, simply create a new project of any type and set all of its properties to the appropriate values. Next create the objects (such as forms and modules) just as you want them to appear in projects based on the template. When you're finished, save the project file along with all of its object files in the Template\Projects folder.

NOTE
Since every module (including form modules) should have full error trapping (as I'll discuss in Chapter 7, "Error Handling"), you should add the proper error handling to each object template. The idea is to make each object template as complete as possible. If objects based on a common template need to have the same work done to them each time they're added to a project, that work should be done in the template file itself.


Practical Standards for Microsoft Visual Basic
Practical Standards for Microsoft Visual Basic .NET (Pro-Developer)
ISBN: 0735613567
EAN: 2147483647
Year: 2000
Pages: 57

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