Subscribe to Windows IT Pro
April 01, 1997 12:00 AM

Build a Network Systems ActiveX control Using VB 5.0 Control Creation Edition

Windows IT Pro
InstantDoc ID #560
Rating: (6)
Downloads
vbcode.zip

Take advantage of VB's new features to streamline your code development

[Editor's Note: VB Solutions is about using Visual Basic (VB) to build a variety of solutions to specific business problems. This column doesn't teach you how to write VB, but how to use VB as a tool to provide quick, easy-to-implement solutions that you can use right away.]

Each VB Solutions column presents a different utility, but the programs in three VB Solutions columns ("Building a Network Security Monitor," November 1996, "Managing SQL Server with VB," December 1996, and "Exporting Data from SQL Server," January 1997) contained one common element: Each program displayed a specific subset of networked systems in a drop-down combo box. Instead of rewriting the code to retrieve the networked system names in each of these programs, why not create a custom control from Visual Basic's (VB's) toolbox? Then you can simply drag the control to each VB project--and to other projects--in which you need to select from a list of networked systems. You can design the custom control to appear as a combo box automatically filled with a set of networked system names. Better still, if the control is an ActiveX control, you can use it with other Object Linking and Embedding (OLE)-compliant applications, such as Access or Excel.

Unfortunately, VB 4.0 doesn't come with any built-in controls that have the ability to query the network, and you cannot use VB 4.0 to develop ActiveX controls. However, the newest version of VB, VB 5.0 Control Creation Edition (VB5CCE), changes everything: Now you can write ActiveX controls using VB.

As of press time, you can download the VB5CCE beta from Microsoft's Web site at http://www.microsoft.com/vbasic. The VB5CCE beta can give you a good indication of what the general release version of VB 5.0 is like. VB5CCE delivers a substantially revised development environment. More important, VB5CCE addresses one of VB's primary limitations--the inability to create ActiveX controls. The sidebar, "A Brief Preview of the Visual Basic 5.0 Development Environment ," page 162, provides additional information about VB5CCE.

An Overview of the Network Systems Control
In this month's column, I'll demonstrate how to use VB5CCE to create a Network Systems ActiveX control that automatically retrieves a specific set of networked system names and displays them in a combo box. You can regulate what type of names the combo box displays by setting the System Type property in the Network Systems ActiveX control. You can list all NT systems, all NT Server systems, all Primary Domain Controllers (PDCs), or all SQL Servers on your network. You can snap the Network Systems ActiveX control into other VB projects or into any OLE-compliant applications to instantly get a combo box that displays a list of networked systems--without additional coding. Screen 1, page 163, shows a very simple VB5CCE example program that uses the Network Systems ActiveX control.

Building the Network Systems ActiveX Control
You can build OLE controls with VB5CCE three ways: You can use the controls included in the VB toolbox (easy), you can subclass a control from one of the standard Windows controls (more difficult), or you can manually create and draw the control using VB code (most difficult). Because this column focuses on expedient solutions, let's build the Network Systems ActiveX control using the combo box control provided in VB5CCE's toolbox.

When VB5CCE first starts, it presents a project wizard that lets you select the type of application to create. You can choose an ActiveX Control project, a Standard EXE project, or a CTLGROUP project. ("A Brief Preview of the Visual Basic 5.0 Development Environment," describes the basic VB5CCE development environment.) As you might expect, you can use the ActiveX Control project wizard to create an ActiveX Control and the Standard EXE project to create a standard Win32 program. The CTLGROUP project is a concept new to VB5CCE that lets you combine one or more ActiveX Control projects and a Standard EXE project. The CTLGROUP project is quite useful for testing ActiveX controls because you typically run them from another application.

To begin building the Network Systems ActiveX control, select the ActiveX Project, which displays a design Window that contains the UserControl1 ActiveX control template. From a design perspective, UserControl1 is similar to a VB 4.0 form: You drag controls from the toolbox to a window in the design environment. The difference is that VB5CCE calls the window UserControl1, instead of Form1. Double-click the combo box icon in the VB5CCE toolbox to put the combo box control in the UserControl1 window.

Reposition the control to the upper left corner of the UserControl1 window, and resize the control, as shown in Screen 2. Next, resize the UserControl1 window to fit the combo box. You need to resize the window because it can cover other controls or interface objects if it remains larger than the standard combo box control it contains. Because the purpose of this control is to display just a combo box, you don't want the interface to show anything other than the combo box.

Next, rename the ActiveX project by changing the Name property in VB5CCE's Project window from Project1 (the default name) to NetworkSystems. Changing the project name identifies the ActiveX control as NetworkSystems.ocx. That's all you have to do to create the basic interface for the Network Systems control.

Adding a Custom Property
After creating the user interface, the next step is to add custom properties, methods, and events. The simple Network Systems control uses only one custom property, SystemType. The SystemType property specifies the type of networked systems to be displayed in the Network Systems combo box. The SystemType property lets you use the Network Systems control in a variety of network applications without changing any of the code. For instance, you can set the SystemType property to retrieve all NT systems on the network, just NT Server systems on the network, or only SQL Server systems on the network. This flexibility lets you use the Network Systems control for many different purposes.

To add the custom SystemType property, run the ActiveX Control Interface Wizard from VBCCE's Add-Ins menu. The ActiveX Control Interface Wizard lets you interactively define the ActiveX control's properties, methods, and events. First, you select the desired properties from a list of default ActiveX properties. Then you can add the custom properties that you want. Screen 3 shows the VB5CCE ActiveX Control Interface Wizard dialog box to add the SystemType property. When the ActiveX Control Interface Wizard finishes, it automatically adds the underlying VB code that supports the custom properties, events, and methods.

Related Content:

ARTICLE TOOLS

Comments
  • Anonymous User
    8 years ago
    Oct 21, 2004

    Thank you!

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.