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


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

Advanced Visual Basic Techniques
(Publisher: John Wiley & Sons, Inc.)
Author(s): Rod Stephens
ISBN: 0471188816
Publication Date: 06/01/97

Search this book:
 
Previous Table of Contents Next


If the initialization file entry is correctly created but the server DLL is not, the Add-In Manager will be unable to install the add-in. When a developer opens the Add-In Manager, it will present an error message similar to the following:

Visual Basic cannot load PropertySetter.PropSet because it is not in the system registry.

Please ensure that all Add-Ins have been installed correctly.


FIGURE 4.7  Setting the server’s name in the Member Options dialog.


FIGURE 4.8  Locating the server class in the Visual Basic 4 Object Browser.

This warning usually means there is a mismatch between the project’s registered name and the project name specified in the initialization file. For example, suppose an add-in designer creates a DLL for a project with the name “PropSetter.” At that point, Visual Basic would create system registry entries that describe the PropSetter server. Now suppose the application’s Main subroutine creates the following initialization entry:

[Add-Ins32]
PropertySetter.PropSet=0

When the Add-In Manager starts, it learns from the initialization file that there is an add-in with ConnectAddIn subroutine contained in the class PropertySetter.PropSet. It then checks the system registry to obtain a server for that class. Because the project name was PropSetter when the DLL was created, the Add-In Manager will be unable to find an entry for PropertySetter.PropSet.

Summarizing Add-In Creation

Creating an add-in server is a complicated process. Each step is simple, but there are so many steps that it is easy to miss one. The following list summarizes the steps required to create an add-in in Visual Basic 4 and Visual Basic 5:

1.  Start a new project.
2.  Set the project options. In Visual Basic 4, use the Options command in the Tool menu to set the Startup Form, Project Name, and StartMode. In Visual Basic 5, use the Properties command in the Project menu to set the Project Type and Project Name.


FIGURE 4.9  Locating the server class in the Visual Basic 5 Object Browser.

3.  Create an add-in class that supplies the ConnectAddIn and DisconnectAddIn subroutines.
4.  Create event handler classes with AfterClick subroutines. If the add-in performs a single task, the class created in step 3 can also provide the AfterClick subroutine.
5.  Create Sub Main. It should register the server in the proper section of VB.INI or VBADDIN.INI.
6.  Using the Object Browser, set the name that should be displayed by the Add-In Manager.
7.  Create the server DLL.

To install the add-in using Visual Basic 4, run the application. To install the add-in using Visual Basic 5, run the subroutine that adds the server entries to VBADDIN.INI.

Testing Add-Ins

Because add-ins are invoked by the Visual Basic development environment, testing them is a bit unusual. The add-in designer should load the add-in project into the Visual Basic programming environment and set breakpoints in the add-in’s subroutines. The project should then be executed. In Visual Basic 4, the program executes the Main subroutine, but that routine does nothing visible. In both Visual Basic 4 and Visual Basic 5, the application appears as if it is not doing anything. It is actually waiting for clients to request service.

Next the developer should start a second instance of the Visual Basic programming environment. Temporarily minimizing the first instance can help make the screen appear less cluttered and confusing. In the second environment, the designer should select the Add-In Manager command from the Add-Ins menu. The Add-In Manager displays a dialog similar to the one shown in Figure 4.10.

If the new add-in is not listed, something is wrong. The add-in may not be correctly installed in the initialization file VB.INI or VBADDIN.INI. One way this can occur is if the add-in was accidentally installed it in the “Add - Ins 32” section instead of the “Add-Ins32” section. A close look at the initialization file should verify that the add-in is installed correctly there.

The add-in also might not be installed correctly in the system registry. This will happen if the project’s name is not the same as the one shown in the initialization file. If the project’s name is changed, the add-in’s DLL must be rebuilt to update the registry.

If the add-in is listed in the Add-In Manager, the designer can check the box next to it and click the OK button. At this point, the Add-In Manager will execute the add-in’s ConnectAddIn subroutine. Using the first programming environment, the designer can step through the ConnectAddIn code.

In the second programming environment, if the designer now opens the Add-Ins menu, any new menu items created by the ConnectAddIn subroutine should appear. By selecting one of the new menu items, the designer can activate the corresponding event handler’s AfterClick subroutine. The designer can use the first programming environment to step through the execution.


FIGURE 4.10  Selecting PropertySetter in the Add-In Manager.

When the add-in is thoroughly tested, the designer should open the Add-In Manager in the second development environment, uncheck the box next to the add-in, and click the OK button. At this point, the Add-In Manager invokes the add-in server’s DisconnectAddIn subroutine. Again, the designer can step through the code using the first programming environment to verify that it works.

The designer should open the second programming environment’s Add-Ins menu one last time to verify that the DisconnectAddIn subroutine successfully removed the add-in’s menu entries.

Now the designer can stop the add-in server running in the first environment. The server must not stop until the client programming environment has removed the server from its Add-Ins menu. Otherwise, the server will not be running when the Add-In Manager needs to invoke the DisconnectAddIn subroutine. If the Add-In Manager cannot run DisconnectAddIn, the menu items created by the add-in will remain in the client’s Add-Ins menu until the client exits from Visual Basic.

Summary

This chapter covers the essentials of add-in creation. It explains how to build the methods necessary to implement an add-in and how to install an add-in for use in the development environment. PropertySetter shows how an add-in can modify the properties of the controls contained within a project.

Using a similar technique, Chapter 5 adjusts the Left and Top properties of a group of controls to align them in rows and columns. Chapters 6 and 7 use more advanced add-in techniques to add new controls and new source code to a project.


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-1999 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.