5.2. Reading the Object Model

The object model of an OLE Automation server is a hierarchy of classes, each containing methods, properties, and events. These methods, properties, and events determine how you can control the application. First of all, though, you need to know what methods, properties, and events are available to you. The first port of call should be the documentation (if any) available from the producer of the OLE Automation server. In addition, once you've created a project-level reference to the application, you can find out a lot about the application's object model from within the VB development environment.

5.2.1. Using the Object Browser

You can use the Object Browser to explore the contents of each class and to find out, for example, what data types are returned by various methods and properties, or what parameters a particular method is expecting. To open the Object Browser, which is shown in Figure 5.2, do any of the following:

  • Click the Object Browser button on the toolbar.

  • Select the Object Browser option from the View menu.

  • Press F2.

Figure 5.2. The Visual Basic Object Browser

The Object Browser is divided into three panes. The left pane displays the classes contained within the selected library; the right pane displays the properties, methods, events, and constants of the selected class; and the bottom pane displays details about the selected method, property, event, or constant, such as its data type or its parameters. There is a fourth pane that can be opened to show the results of a library search.

5.2.2. IntelliSense and Statement Completion

Both the retail version of VB and the VBA development environment make use of Microsoft's IntelliSense technology. Statement Completion not only helps to speed the development of VB applications, but it acts as a guide, leading you through the object's hierarchy as you are coding by displaying only those objects, methods, properties, and events that are available for the code you are currently writing, as Figure 5.3 shows.

Figure 5.3. Statement Completion

By adding an object reference to your project, you expose the class's type library to the VB development environment, allowing the details of its class hierarchy to be displayed as you enter your code. The main features of IntelliSense and Statement Completion are:

  • Available properties, events, and methods are shown in a drop-down list when you press the dot key.

  • Pressing the Ctrl key and spacebar combination when partway through an object or procedure name either completes the name or displays a list of possible names.

  • Where a property or method takes an argument list, a template of the argument list is shown as a tool tip above or below the line of code. Such a template is shown in Figure 5.4.

When coding object references and calls to methods and properties, you soon find that the number of keystrokes is dramatically reduced by IntelliSense.

Figure 5.4. Microsoft IntelliSense

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.179.171