Share via


Visual Basic Concepts

Programming with Components

Do you sometimes need to provide the same analysis and calculation capabilities as Microsoft Excel in your Visual Basic application? Or, perhaps you'd like to format a document using Microsoft Word formatting tools, or store and manage data using the Microsoft Jet database engine. Even better, would you like to be able to create or buy standard components, then use them in multiple applications without having to modify them?

All this and more can be accomplished by building your applications using ActiveX components. An ActiveX component is a reusable piece of programming code and data made up of one or more objects created using ActiveX technology. Your applications can use existing components, such as those included in Microsoft Office applications, code components, ActiveX documents, or ActiveX controls (formerly called OLE controls) provided by a variety of vendors. Or, if you have the Visual Basic, Professional or Enterprise Edition, you can create your own ActiveX controls.

For components that support object linking and embedding, you can insert objects into your application without writing any code by using the component's visual interface. You can insert an OLE-enabled object into your application by using the OLE container control or by adding the object's class to the Toolbox.

To fully understand ActiveX components, you should first be familiar with how to work with classes, objects, properties, and methods, which are explained in "Programming with Objects."

Topics

Types of ActiveX Components

Introducing the different types of ActiveX components.

In-Process and Out-of-Process Servers

The difference between in-process and out-of-process components.

Working with ActiveX Components

The basics of working with most objects provided by ActiveX components.

Creating a Reference to an Object

How to declare and set object variables for objects provided by components.

Using an Object's Properties, Methods, and Events

The basics of manipulating an object's properties, methods, and events.

Releasing an ActiveX Component

Clearing an object variable so it can be released from memory.

Navigating Object Models

Working with objects in large components that supply an object hierarchy.

Handling Run-Time Errors in ActiveX Components

Trapping errors when you work with ActiveX components.

Handling Requests Pending to an ActiveX Component

Handling requests to an ActiveX component that may not be finished immediately.

Using an ActiveX Component's Visual Interface

How to link or embed component objects in your application without writing code.

Sample applications

Geofacts.vbp and Olecont.vbp

Many of the concepts in this chapter are demonstrated in the sample applications Geofacts.vbp and Olecont.vbp. The sample applications are listed in the directory.