Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering

 


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

Data and Property Persistence in Active Documents

A user uses an Active Document container application such as Internet Explorer or Office Binder to directly open a second application's data file. The container application uses the Windows Registry to determine the application associated with the data file's extension and, if the data file's application is an Active Document server, it runs the server application and its data in an Active Document window.

For instance, if an Internet Explorer or Office Binder user attempts to open a .DOC file, then IE or OB will host that file in an Active Document implemented by Word. If, on the other hand, the user opens an .XLS file, then IE or OB will host that file in an Active Document implemented by Excel.

You might now be wondering: What data file must the user choose to bring up my Active Document application written in VB? This and other questions are answered in the following sections.

Saving Information in the .vbd File

The native document file format for an Active Document application that you create with VB is a file with a .vbd extension. The .vbd file contains persistent property values and other information that the container needs to host your Active Document application. The .vbd file is created at the same time the .EXE file is compiled.

When the user tells the container application to save information from your Active Document (either because the user has chosen a save option or because the user is trying to exit your document), then the container application saves the information back to the .vbd file.

When you run your VB Active Document application from the VB design environment, VB creates a temporary .vbd file in the VB program directory. For more details on testing your Active Document in the design environment, see "Testing Your Active Document."

When you compile and distribute your ActiveX DLL or EXE, the .vbd file is installed in the same directory as the DLL or EXE.

Data Preservation Events and the Properties Bag

As mentioned earlier in this chapter, a UserDocument object has the same ReadProperties and WriteProperties events as the UserControl object of an ActiveX Control project.

Within the event procedures of these events, you can use the Property Bag object's ReadProperty and WriteProperty methods to retrieve and store persistent property values. Container applications implement the Property Bag by reading and writing the .vbd file. This happens transparently to your Active Document application.

SAVING INFORMATION WHEN A CONTAINER DOESN'T SUPPORT THE PROPERTIES BAG

Although Internet Explorer and Office Binder support the Properties Bag with .vbd files, you can expect that other container applications that appear in the future might not use vbd files to implement a Properties Bag.

In this case, you'll need to change the type of code that you put in the ReadProperties and WriteProperties event procedures of the UserDocument.

Instead of calls to the ReadProperty method, you might put filehandling code similar to the code in the listing below into the ReadProperties event procedure. It provides for a code fragment to read data directly from a file into a TextBox that delegates an Active Document property.

Dim lHandle as Long
lHandle = FreeFile
Open lHandle for Input as _
gblstrPropBagFile
txtData.Text = _
Input(Lof(#lHandle), lHandle)
Close #lHandle

Instead of calls to the WriteProperty method, you might put code similar to the code in the listing shown below into the WriteProperties event procedure. It shows a code fragment to write data directly to a file from a TextBox that delegates an Active Document property.

Dim lHandle as Long
lHandle = FreeFile
Open lHandle for Output as _
gblstrPropBagFile
Print #lHandle, txtData.Text
Close #lHandle

Note the use of the Open and Close statements and the Input function to manipulate the file.


  

<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved