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
The Immediate Window
At any breakpoint you can select View | Immediate Window (Ctrl+G) to request the Immediate window (sometimes called the Debug window). The Immediate window is a special window in which you can directly type Visual Basic commands and view and change variables and control values during a program's execution.
For displaying variables and controls, apply the Print method (see Hour 16, "Printing with Visual Basic" ) to view variables and controls. When you use Print in the Immediate window, Visual Basic sends the output to the Immediate window and not to the Printer object, as you saw in Hour 16. For example, suppose that you set a breakpoint during a variable's assignment, as described in the previous sections, and you pressed Ctrl+G to open the Immediate window. The Immediate window recognizes simple Visual Basic commands and methods such as Print and assignment statements.
Figure 20.11 shows what happens if you print the value of strComputer after the variable is assigned the string value. Unlike the Quick Watch dialog box, the Immediate window has room to display multiple lines if you display a multiline control such as a text box. You can resize and move the Immediate window. Although they must use the Print command instead of simply clicking a variable or control, many programmers prefer to display values from the Immediate window instead of the Quick Watch dialog box. The Immediate window displays the entire value and contains a vertical scrollbar so that you can scroll through the values printed in the window.
Figure 20.11 The Immediate window displays the values of variables.
The Immediate window's scrolling and resizing features are so handy that some Visual Basic programmers prefer to send messages to the Immediate window at runtime rather than use the Quick Watch dialog box. For example, if you want to see the value of certain arguments when called procedures execute, you can add the Print methods at the top of those procedures that send the argument values to the Immediate window automatically as the program executes. When you get the bugs out of the program, you can remove the Print commands so that the Immediate window stays closed.
To print to the Immediate window, preface the Print method with the special Debug object. The following command, executed anywhere from an application's code, prints the values of two variables with appropriate titles in the Immediate window:
Debug.Print "Age:"; intAgeVal, "Weight:"; intWeightVal
All the Print method's options, including semicolons, commas, and Tab() and Spc() functions, work inside the Immediate window just as they do for the Printer object described in Hour 16. Be careful to specify the Debug object before the Print method, however. If you omit Debug, Visual Basic prints the output directly on the form itself!
The Immediate window recognizes assignments that you make to variables and controls. For example, suppose you know that a certain variable wasn't initialized properly earlier in the execution, but you still want to finish the program's execution as if the variable had its proper value. If you need to, you can assign that variable a new value directly within the Immediate window using the assignment statement. When you resume the program's execution, either in single-step or in runtime mode, the variable, from that point in the program, will contain the value that you assigned to it.
Summary | Next Section

Account Sign In
View your cart