Use of Controls

As we observed in Chapter 1, controls are one of the distinguishing features of Visual Basic, and probably Visual Basic's greatest contribution to the software industry.

VBX Controls

Unfortunately, VBX technology has some severe limitations. In particular, there's very little flexibility in the way that Visual Basic interacts with the controls. VBX controls have to provide a predefined list of methods, regardless of what the control actually does. Furthermore, a control developer can't add new methods to a control, making it very difficult to provide advanced functionality to the end developer. Instead, many controls provide an Action property, where the developer can set the property to a whole range of values to get different effects. This certainly doesn't lead to readable code; who knows what this might do:

myControl.Action = 21

To cap it off, Microsoft chose not to support the VBX standard in the Win32 environment. This means that VBX controls are now only available to developers working in 16-bit Windows. For 32-bit development, we need to use ActiveX controls.

ActiveX Controls

ActiveX controls have largely removed the limitations of VBX controls by extending the VBX concept with more flexibility and more powerful capabilities. Like VBX controls, ActiveX controls typically provide a visual 'widget' for use in developing user-interfaces. However, they are also binary components; that is, they can contain multiple objects. This means that ActiveX controls can implement a complex interface, including any properties or methods that are needed to make the control useful.

Rather than implementing a generic and hard-to-read Action property, an ActiveX control can implement a descriptive method, for example:

myControl.SpinLeft

As the Visual Basic tool has matured, so have its capabilities with regard to controls. Today, ActiveX controls are a specialised form of component for use in building user-interfaces. As a component, ActiveX controls can contain objects, and they can make those objects available to help implement any required functionality in a program.

With Visual Basic 5.0, we have the ability to create our own ActiveX controls. We can create them as purely visual widgets for use in developing user-interfaces, or we can make them more complex by treating the control as a component and including objects.

Certainly, most controls are just visual widgets, and that is their primary function. At the same time, there are more techniques available for the distribution of controls to client workstations, or across the Internet, than there are for other ActiveX servers such as DLLs or EXEs. There are times when it's preferable to package objects within a control simply because that control can be automatically downloaded to a Web browser or other client where the objects are needed.

© 1997 by Wrox Press. All rights reserved.