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
- Option Buttons
- Frames and Option Buttons
- Check Boxes
- Scrollbars
- VB's Clock: The Timer Control
- Summary
- Q&A
- Workshop
- 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
VB's Clock: The Timer Control
The Timer control acts unlike any other control you've seen so far. The Timer control always works in the background, and the user never sees the timer on the form. You will see the Timer control during design time because you need to be able to select the control and change its properties. Nevertheless, the timer's purpose is to work in the background, triggering an event every once in a while according to the clock ticks.
Your computer has an internal clock to keep things running smoothly. The hardware requires an accurate clock for memory refreshes and CPU cycle coordination efforts. Software such as Visual Basic can tap into the internal clock and use its timing to control certain time-based events that your application may need to perform.
Figure 11.8 shows the Timer control as it appears when you place the control on a form. The Timer control supports only seven properties because the Timer control never appears on the form at runtime. Therefore, the control has no need for many of the style and size properties used for other controls that the user sees.
Figure 11.8 The Timer control appears on the form only at design time.
You can place the timer out of the way of your form's other controls because its physical location is trivial. After you place the timer on the form, you should set its Interval property; Interval is the most important timer property. The Interval property contains a value that must range from 1 to 65,535. The value is in milliseconds (or thousandths of a second), so an Interval value of 500 would equate to half a second. The Timer control generates only one event: the Timer event. The Timer control triggers a Timer event after each interval of time goes by. Therefore, if you named a Timer control tmrClock, and if you set the control's Interval property to 1000, Visual Basic would execute the tmrClock_Timer() event procedure approximately every second.
A millisecond is one-thousandth of a second.
If you need an interval that's larger than the 65,535 Interval value allows (this maximum Interval value provides only about a 10-second interval), insert some If logic at the top of the Timer() event procedure that checks to see if the required amount of time has passed since the last interval. (To do this, you will need some of the time functions described in Hour 14, "Built-In Functions Save Time." )
Summary | Next Section

Account Sign In
View your cart