VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering

You are here: Visual Basic > Advanced VB6 tutorial > Chapter 14

Defining Your Active Document's Custom Members

You can define your own properties and methods for an Active Document in the same manner that you define them for ActiveX controls. These considerations are briefly discussed in the following sections.

You shouldn't create custom events in an Active Document project. Recall that custom events are intended for use by a host or client application. A moment's reflection will show that it's impossible for an Active Document's host (the container application) to have foreknowledge of the specific custom events that you might write in your Active Document—the container (Internet Explorer for instance) was created before your application and with no knowledge of you or your application.


You define an Active Document's custom methods just as you would define the methods of any custom object in VB: as Public procedures of the UserDocument object.

Although you can't call custom methods from a container (see the note in the previous section about events), you can still write methods for your document. If you've created more than one Active Document in your project, you can create object references to one or more of them and manipulate the methods of the objects that you've declared.


You implement custom properties for your Active Document in pretty much the same way as you implement properties for ActiveX controls, as discussed in Chapter 13. You should refer to that chapter for a detailed discussion of how to implement properties, including delegated properties from constituent controls. For quick reference, however, the major steps you must take to implement properties in an Active Document are listed, noting any differences from ActiveX control property implementation:

  1. Decide whether to use a Private variable or a constituent control property to store the property's value at runtime.

  2. Create procedures for the custom property with Property Let/Set and Property Get procedures that refer to the Private variable or constituent control property.

  3. Decide on the default first-time value for the property and store this value in a constant in the UserDocument's General Declarations.

  4. In the InitProperties event procedure, write code to assign the property's default value (as described in the previous point) to the underlying runtime storage element (usually a Private variable or constituent control's property).

  5. In the ReadProperties event procedure, write code that uses the Property Bag to retrieve the value of the property from the last session into the underlying runtime storage element (usually a Private variable or constituent control's property).

  6. In the WriteProperties event procedure, write code that uses the Property Bag to store the value of the property from its runtime storage element.

It's possible that some containers might not support a Property Bag concept. You will therefore have to use alternate strategies for persistent data, as discussed in the In-Depth "Saving Information When a Container Doesn't Support the Properties Bag."


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved