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
- 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
OLE Processing
You can place objects into your application that aren't normally considered to be ActiveX controls. Although you should stick with true ActiveX controls when possible, you can use the Toolbox window's OLE control to drop items from several different applications onto the form window.
For example, suppose that you want your user to be able to see a Microsoft Excel worksheet on your form and interact with the worksheet as if the worksheet were a regular Visual Basic control. Add the OLE control to your Form window. As soon as you do, the Insert Object dialog box appears, as shown in Figure 21.3.
Figure 21.3 Adding objects from other applications.
The Insert Object dialog box gives you the choice of inserting an existing Excel worksheet object (by clicking Create From File) or creating a new object from scratch (by clicking Create From New). You will only be able to create objects if you have those applications on your system, but as stated earlier, your Registry knows what is installed, so only those applications appear in the Insert Object dialog box.
Creating Inserted Objects
If you elect to create the new object from scratch, you can choose that option and double-click the object type (which, in this example, will be an Excel worksheet). Visual Basic loads a blank object into your OLE control as shown in Figure 21.4. You'll also notice that Visual Basic menus change to Excel menus.
Figure 21.4 You can create an Excel worksheet in the middle of the form window.
After you create the worksheet, click the Form window outside the worksheet area and you can continue placing the other controls and completing your application. When you finish, run the application to see the worksheet embedded in the form.
Inserting Existing Objects
Instead of inserting new objects that you must create at design time, you can insert existing objects, such as Excel worksheets. When you select the Insert Object's Create From File option (see Figure 21.5), Visual Basic changes the Insert Object dialog box to the file browsing dialog box.
Figure 21.5 Selecting a worksheet to insert.
To link an object means that your application will contain a pointer to the object. If the object ever changes, your application's form will reflect those changes. The object isn't stored with your application, but the link to the object is.
To embed an object means that your application gets a copy of the object. Therefore, if the original object changes, that change won't be reflected in your application until you or your user make the same change to the application's object. The object is stored with your application so if something happens to the original, no link exists to be broken.
The Link option informs Visual Basic that you want to link the new object and not embed it. You can choose to link or not depending on how current the object must be with the original object's file.
When the user runs your application, she can double-click the worksheet (or the icon) to add Excel menus to the Form window and to change the worksheet.
ActiveX Documents | Next Section

Account Sign In
View your cart