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
Scrollbars
Scrollbars let users control value changes. Rather than type specific values, the user can move the scrollbars with the mouse to specify relative positions within a range of values. The toolbox includes both a Horizontal Scrollbar and a Vertical Scrollbar control.
Table 11.2 contains a list of important scrollbar properties that determine the behavior of the scrollbar.
Table 11.2. Fundamental scrollbar properties.
| Property | Description |
| LargeChange | Specifies the amount that the scrollbar changes when the user clicks within the scrollbar's shaft area. |
| Max | Indicates the maximum number of units that the scrollbar value represents at its highest setting. The range is from 1 to 32,767 (the default Max value). |
| Min | Indicates the minimum number of units the scrollbar value represents at its lowest setting. The range is from 1 (the default Min value) to 32,767. |
| SmallChange | Specifies the amount that the scrollbar changes when the user clicks an arrow at either end of the scrollbar. |
| Value | Contains the unit of measurement currently represented by the position of the scrollbar. |
When you place a scrollbar on a form, you must decide at that time what range of values the scrollbar is to represent. The scrollbar's full range can extend from 1 to 32,767. Set the Min property to the lowest value you want represented by the scrollbar. Set the Max property to the highest value you want represented by the scrollbar.
When the user eventually uses the scrollbar, the scrollbar arrows control small movements in the scrollbar's value, determined by the SmallChange property. Clicking the empty part of the shaft on either side of the scrollbox produces a positive or negative change in the value represented by the LargeChange property. The user can drag the scrollbox itself to any position within the scrollbar shaft to jump to a specific location instead of changing the value gradually.
Suppose, for example, that a horizontal scrollbar represented a range of whole dollar amounts from $5 to $100. When the user clicks the scroll arrows, the scrollbar's value changes by $1. When the user clicks the empty shaft on either side of the scrollbox, the scrollbar's value changes by $5. Here are the property values that you would set that determine how VB interprets each click of the scrollbar: Min: 5, Max: 100, SmallChange: 1, and LargeChange: 5.
The physical size of the scrollbar has no bearing on the scrollbar's returned values when the user selects from the scrollbar. Adjust the scrollbars on your form so that the scrollbars are wide enough or tall enough to be appropriately sized for the items that they represent.
The thumb is the scrollbar's moving scrollbox (the elevator-like box).
Figure 11.7 shows an application that uses a vertical scrollbar to change the size of a label's font size. As the user clicks the top scrollbar arrow, the font size shrinks by the SmallChange value. As the user clicks the bottom scrollbar arrow, the font size increases by the SmallChange value. (The application's SmallChange property value is 1.) If the user clicks in the scrollbar's shaft on either side of the scrollbar's thumb, the LargeChange property value of 5 is either added to or subtracted from the font size.
Figure 11.7 The vertical scrollbar determines the label's font size.
Listing 11.2 shows the code behind Figure 11.7. The code isn't lengthy because the scrollbar's Click() event procedure must change only the label's text font size and the label that displays the current font size. Any time the user changes the scrollbar, the scrollbar's Change() event procedure executes.
Example 11.2. The code behind the scrollbar application.
1: Private Sub vsbHeight_Change() 2: lblScroll.FontSize = vsbHeight.Value 3: lblFontHeight.Caption = vsbHeight.Value 4: End Sub
VB's Clock: The Timer Control | Next Section

Account Sign In
View your cart