Using the Visio Type Library

3 4

The Microsoft Visio type library contains Automation descriptions of the objects, properties, methods, and events that the Visio engine exposes. Microsoft Visual Basic for Applications (VBA) projects that belong to Visio documents automatically reference the Visio type library, which you use to define Visio object types in your program. Using the Visio object types that are declared in the Visio type library increases the speed of your program because VBA interprets Visio objects at compile time rather than run time. When you compile a program during design time, VBA checks for syntax and programming errors and matches object types against type libraries. If you use a general variable type, such as Object, VBA doesn't interpret it until run time; at that time, VBA queries the Visio engine about object references. This extra querying step decreases the speed of your program.

The type library also contains the global symbolic constants defined for arguments and return values of properties and methods. Because most arguments to properties and methods are numeric values, using these constants can make your code easier to write and to read. For example, suppose you want to find out what type of window a Window object represents. The Type property of a Window object returns an integer that indicates the window's type. If you set a reference to the Visio type library in your project, you can use a constant instead of an integer to check the window's type, in this example, visDrawing instead of 1.

For a list of constants used by a particular method or property, see that method or property in the Developer Reference in Microsoft Visio (on the Help menu, click Developer Reference).

You can view the contents of the Visio type library using the VBA Object Browser.

Note


The examples in this guide assume that you have a reference set to the Visio type library. To verify this, on the Tools menu, click References, and then make sure the Microsoft Visio 2002 type library is selected.

Using the Object Browser

You can use the Object Browser to view the Visio type library. The Object Browser displays constants, classes (objects), and class members (properties, methods, and events) of type libraries referenced by open projects.

The Object Browser displays Visio properties, methods, events, and constants as members in the Members of list. The Details pane displays each member's syntax as a code template that you can copy and paste or drag into a module; you can then substitute your own variables and arguments. Using code templates decreases the chance of typing errors.

Figure 15-6.  The <b>Object Browser.</b> (<b>A</b>) <b>Project/Library</b> box <b>.</b> (<b>B</b>) <b>Search Text</b> box <b>.(C</b>) <b>Classes</b> list.(<b>D</b>) <b>Members of</b> list.(<b>E</b>) <b>Details</b> pane.

Figure 15-6 The Object Browser. (A) Project/Library box . (B) Search Text box .(C) Classes list.(D) Members of list.(E) Details pane.

To use the Object Browser

  1. On the View menu, click Object Browser. Or click the Object Browser button bu_ObjectBrowser.GIF on the toolbar.
  2. To browse or search for a Visio object, property, method, event, or constant, type its name in the Search Text box, or click any member in the Members of list.

Setting References to Type Libraries

Applications that support Automation provide a type library to describe the objects that they expose to Automation. If you want to access the objects of another application from your Visio solution, click References on the Tools menu, and then select the type library you're looking for in the Available References list. You can also use this procedure to set a reference to the Visio application from any other application that supports Automation. For example, you can set a reference to Visio from a Microsoft Word application to enable you to use Visio objects in your Word application.

Any type libraries that are checked in the Available References list will appear in the Project/Library box for your project. You can also set a reference to any open Visio documents or browse to any unopened Visio documents in the References dialog box.

Figure 15-7.  An expanded <b>Available References</b> list.

Figure 15-7 An expanded Available References list.

Note


Toview only the class and members in the Visio type library, click Visio in the Project/Library box in the Object Browser.

Visio does not automatically reference the Microsoft Office Object library; you will need to set a reference to this library if you plan on accessing objects such as command bars and COM add-ins.

Using Visio Object Types

You can take advantage of the Visio type library to write code more effectively. By using Visio object types declared in the Visio type library, you can declare variables as specific types, such as Visio.Page:

 Dim pagObj as Visio.Page 

Using a Visio object type, such as Visio.Page, enables your program to check the type of object it is referencing in the Visio type library at compile time. This is called early binding. This example uses Visio to inform the program that it is referencing Visio object types in the Visio type library, and it uses Page to inform it that the pagObj variable is a Page object. For details about using Visio objects, see Chapter 14, Automation and the Visio Object Model.

Here are a few common object types:

 'A Documents collection Dim docsObj As Visio.Documents 'A Document object Dim docObj As Visio.Document 'A Shapes collection Dim shpsObj As Visio.Shapes 'A Shape object Dim shpObj As Visio.Shape 'A Master object Dim mastObj As Visio.Master 

When you type a period after an object or library type, a list of available object types, properties, and methods for the preceding object or variable type appears automatically in the Auto List window. To insert an object type from the list in your code, double-click the type in the list.

Tip


Ifthe list of available object types, properties, and methods for an object doesn't automatically appear when you're typing in the Code window, on the Tools menu, click Options, click Editor, and then select the Auto List Members check box.

In this example, the appropriate object type is Page.

figure 15-8. the visio type library auto list window.

Figure 15-8 The Visio type library Auto List window.



Developing Microsoft Visio Solutions 2001
Developing Microsoft Visio Solutions (Pro-Documentation)
ISBN: 0735613532
EAN: 2147483647
Year: 2004
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net