Visual Basic Concepts

Parts of an ActiveX Document

An ActiveX document created with Visual Basic is always composed of a UserDocument object, code, code modules, and controls that you place on the UserDocument.

Project Files

Like Visual Basic forms, UserDocument objects have code modules and visual designers, as shown in Figure 11.2.

Figure 11.2 UserDocument designer and code window

Like forms, UserDocument objects are stored in plain text files that contain the source code and property values of the UserDocument and the controls placed on it. Visual Basic uses the extension .dob for these source files.

If a UserDocument contains controls that use graphical elements which cannot be stored as plain text, such as bitmaps, Visual Basic stores those elements in a .dox file. This is analogous to the .frx files used to store graphical elements used in forms.

The .dob and .dox files completely define an ActiveX control's appearance and interface (properties, events, and methods). A compiled ActiveX document will then consist of either an ActiveX .exe or .dll and an accompanying .vbd file. In a browser such as Internet Explorer, the user must navigate to the .vbd file to open the ActiveX document.

Compiled Files

An ActiveX document can be built as an out-of-process component (an .exe file) or an in-process component (a .dll file). In both cases, when you run or compile the project, in addition to creating an .exe. or a .dll file, Visual Basic creates a Visual Basic Document file, which has the extension "vbd." When you compile an .exe or .dll, the .vbd file will be placed in the same directory as the compiled component.

The .vbd file is actually an OLE structured storage — this basically means that data in the file can be accessed and manipulated via standard OLE interfaces. Other Microsoft applications, such as Word and Excel, save data in this manner.

*Note* When you run an ActiveX project from the Visual Basic IDE, a temporary .vbd file will be created in the directory where Visual Basic has been installed. The temporary .vbd file will have the same name as the UserDocument with the "vbd" extension. If a .vbd with the same name exists (in the Visual Basic directory), that .vbd file will be moved to a temporary file location. When the project stops running, the original file will be restored. While the project is running, however, you can navigate to the temporary file (from a browser or other application).

To view the ActiveX document in a container application, such as Internet Explorer or Microsoft Office Binder, you must navigate to the .vbd file. For example, if you created an ActiveX document named "DocObject1.vbd," and it is in the default directory of the Visual Basic program, you might type the following URL in the Address box of Internet Explorer:

file://c:\Program Files\VB\DocObject1.vbd

*Note* This path will vary depending on which version of Visual Basic you have installed. If Visual Basic has been installed as part of Microsoft Visual Studio, for example, the URL shown above may instead be file://c:\Program Files\Microsoft Visual Studio\VB\DocObject1.vbd.

You can also use the Hyperlink object's NavigateTo method, from within an ActiveX document, to open another ActiveX document, as shown:

Private Sub cmdGoNext_Click()
   UserDocument.Hyperlink.NavigateTo _
      "c:\Program Files\VB\DocObject1.vbd"
End Sub

*Note* Once you have compiled your ActiveX document, you can change the extension of the .vbd file. In other words, instead of having users navigate to "Nice.vbd," you can have them navigate to ""

*For More Information* To learn how to navigate between ActiveX documents in a browser, see "Using the HyperLink Object with ActiveX Documents."