home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Creating A Form-Free Startup Procedure

To start a program from code not in any form, you add a subroutine named Main() to your program. Follow these steps:

1.  Select the Properties item in the Project menu to open the Project Properties box, as shown in Figure 2.14.


Figure 2.14  The Project Properties box.

2.  Click the General tab in the Project Properties box (if it’s not already selected), select Sub Main in the Startup Object drop-down list, and click on OK.
3.  Select Add Module in the Project menu, and double-click the Module icon in the Add Module box that opens.
4.  Add this code to the new module’s (General) section in the code window:
   Sub Main()
   End Sub
5.  Place the code you want in the Main() subroutine.

Selecting The Startup Form

On the other hand, you might have a number of forms in a project—how do you specify which one is displayed first? You do that with the General tab of the Project Properties box, just as we’ve added a Main() subroutine to our program.

To specify the startup form for a project, just open the Project Properties box as we’ve done in the previous section and select the appropriate form in the Startup Object box, as shown in Figure 2.15. Now when your program starts, that form will act as the startup form.


Figure 2.15  Setting a project’s startup form.

Using Visual Basic Predefined Forms, Menus, And Projects

You’re designing a new program, and you want a form with a complete File menu on it. You don’t want to use the Application Wizard, because that add-in would redesign your whole project for you. Rather than designing a complete standard File menu from scratch, there’s an easier way: you can use one of the predefined menus that come with Visual Basic.

To add one of the predefined Visual Basic menus, follow these steps:

1.  Select the form you want to add the menu to by clicking it with the mouse.
2.  Open the Visual Component Manager from the Tools menu. If the Visual Component Manager is not already loaded into Visual Basic, open the Add-In Manager in the Add-Ins menu, click the box labeled Visual Component Manager, and close the Add-In Manager. If your version of Visual Basic does not come with the Visual Component Manager, refer to the discussion after these steps.
3.  Open the Visual Basic folder in the Visual Component Manager.
4.  Open the Templates folder in the Visual Basic folder.
5.  Open the Menus folder in the Templates folder, as shown in Figure 2.16.


Figure 2.16  Opening the Menus folder in the Visual Component Manager.

6.  Select the type of menu you want and double-click it. These are the available menus:
  Edit menu
  File menu
  Help menu
  View menu
  Window menu
7.  The new menu will be added to the form you selected, as shown in Figure 2.17.


Figure 2.17  Adding a predefined Visual Basic menu to a form.

Besides menus, you can add a whole selection of predefined forms to your projects by finding the Forms folder in the Templates folder in the Visual Component Manager. Here are the available forms, ready to be added to your project with a click of the mouse:

  Blank forms
  About dialog boxes (two types)
  Addin forms
  Browser forms
  Data grid forms
  Dialog forms
  Tip forms
  Log-in forms
  ODBC log-in forms
  Options forms
  Query forms

As you’ll see in the Visual Component Manager’s Templates folder, you can add the following pre-defined elements to a Visual Basis Project:

  Classes
  Code procedures
  Control sets
  Forms
  MDI forms
  Menus
  Modules
  Project templates
  Property pages
  User controls
  User documents

After you’ve created components like these in Visual Basic, you can add them to other projects using the Visual Component Manager—in fact, reusing components like this is one of the things professional programmers and programming teams do best.

If You Don’t Have The Visual Component Manager

If your version of Visual Basic does not come with the Visual Component Manager, you can still add many predefined components to a project, including forms, MDI forms, modules, class modules, user controls, and property pages. For example, to add a predefined form to your project, just select Add Form from the Project menu, opening the Add Form dialog box, as shown in Figure 2.18.


Figure 2.18  The Add Form dialog box.

As you can see, the predefined forms are here, so you can add them to your project with a simple click of the mouse.

Adding menus is a little different here, because you actually add a whole new form with that menu, instead of adding that menu to an already-existing form. For example, to add a new form with a File menu already in place, click the Existing tab in the Add Form dialog box, click the Menus folder, and double-click the Filemenu.frm entry. This adds a new form to your project, complete with File menu.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.