Sams Teach Yourself Visual Basic 6 in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- Introduction
- Who Should Read This Book
- What This Book Will Do for You
- Can This Book Really Teach Visual Basic in 24 Hours?
- What You Need
- Files on the Visual Basic Distribution CD-ROM
- Conventions Used in This Book
- Enough! Time Is Ticking!
- Part I: Introducing Visual Basic
- Hour 1. Visual Basic at Work
- Hour 2.Analyzing Visual Basic Programs
- Hour 3.Controls and Properties
- Hour 4.Examining Labels, Buttons, and Text Boxes
- Part II: Coding the Details
- Hour 5.Putting Code into Visual Basic
- Hour 6.Message and Input Boxes
- Hour 7.Making Decisions
- Hour 8.Visual Basic Looping
- Part III:Putting Code to Work
- Hour 9.Combining Code and Controls
- Hour 10.List Boxes and Data Lists
- Hour 11.Additional Controls
- Hour 12.Dialog Box Basics
- Part IV:Programming with Data
- Hour 13.Modular Programming
- Hour 14.Built-In Functions Save Time
- Hour 15.Visual Basic Database Basics
- Hour 16.Printing with Visual Basic
- Part V:Sprucing Up Programs
- Hour 17.Menus and Visual Basic
- Hour 18.The Graphic Image Controls
- Hour 19.Toolbars and More Graphics
- Hour 20.Writing Correct Applications
- Part VI:Advancing Visual Basic Applications
- Hour 21.Visual Basic and ActiveX
- ActiveX: The Tools You Use
- Building ActiveX Controls With VB
- OLE Processing
- ActiveX Documents
- Summary
- Q&A
- Workshop
- Hour 22.Object Basics
- Hour 23.Distributing Your Applications
- Hour 24.Online Visual Basic
- Part VII:Appendixes
- Appendix A.Operator Precedence
- Appendix B.Answers
- Appendix C.Using the CD-ROM
Building ActiveX Controls With VB
Although the Visual Basic Working Model that comes with this text does not support ActiveX control creation, you can use the retail versions of Visual Basic to build your own ActiveX controls. If you like command buttons but you wish they would support a special event or property that your application needs, you can write your own ActiveX command button control, and then use that control as if Visual Basic came with it. You can add the control to your own application's toolbox (through the Project | Components dialog box) and set its properties from the Properties window.
To build an ActiveX control, start a retail version of Visual Basic and select New | Project and select the ActiveX Control icon. Your Visual Basic environment will now look like Figure 21.2.
Figure 21.2 Building an ActiveX control with Visual Basic.
The initial name that VB gives to the control you build is UserControl1; hence the Name property value and the name in the Project window. Most of the tools, windows, and menu objects are exactly the same for the ActiveX control.
Custom controls are tedious to create. Not only must you know Visual Basic and all its language and inner workings (as you do now), but you also need to understand the way ActiveX controls are built, and you must understand the wizards available with VB 6 that help you build the controls. Although you'll need to get some fairly heavy training before you learn to build ActiveX controls, consider the following points:
- Many ActiveX controls are based on existing controls. If you were going to create a new kind of command button, you'd start with the regular command button and build on it. You would place a command button in the center of the Form window and add functionality to the command button to turn it into your own control.
-
If you are building a complex control that contains several additional controls, you can place all the foundation controls on the Form window and work with them to build the complex control.
Inheritance refers to the capability of object-oriented languages (such as C++) to base new capabilities on existing language capabilities or controls.
- Although Visual Basic doesn't support true inheritance, a wizard is available in VB 6 to let you select functionality from existing controls and put that functionality into your new ActiveX control.
- After you design the control, you must design its interface. VB 6 comes with wizard technology that helps you add properties, events, and methods to the control.
- Your new ActiveX control will be capable of mimicking existing controls in all ways. Therefore, if you later add your new control to an application's Toolbox window, the Properties window will display that ActiveX control's properties, including support for drop-down list boxes from which fixed property values are available for selection. In addition, you'll see your ActiveX control's pop-up statement syntax appear inside the Code window editor when you add methods to the control.
OLE Processing | Next Section

Account Sign In
View your cart