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
- The Interest Calculation Application
- Using Control Arrays
- Finishing the Form
- Adding Code
- The Unload Statement
- Finishing Touches
- Error Checking
- Summary
- Q&A
- Workshop
- 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 Interest Calculation Application
The previous lesson describes how to compute compound interest using a For loop. You studied the code in the previous lesson, and this lesson will build a simple application around that interest calculation.
Figure 9.1 shows the application that you'll create today.
Figure 9.1 The interest calculating application's window.
Perform these steps to create the interest calculating application:
- Start a new Standard EXE project by selecting File | New Project or double-clicking the Standard EXE icon (the icon you'll most often choose for regular applications).
- Change the form's Name property to frmInterest. Change the Caption property to Interest Calculation.
- Change the form's StartUpPosition property to 2-CenterScreen. You haven't seen the StartUpPosition property yet; it determines the location of the Form window when the user runs the program. Let Visual Basic center the form on your user's screen because you don't know the exact measurements of the screen that your users will use. If you set StartUpPosition to 2-CenterScreen, Visual Basic always places the form in the middle of the screen no matter what the user's screen size and resolution are. (Use the WindowState property to open the Form window in its maximized state if you want a full-screen Form window when the application starts.)
- Now you need to add the labels and text boxes. The form's title label is easy to generate. Place a label on the form and set the following properties:
Name: lblTitle Alignment: 2-Center BorderStyle: 1-Fixed Single Caption: Interest Calculator Font: Bold 18 Height: 495 Left: 2090 Top: 240 Width: 3855
You now must set up a series of three label/text box pairs. Notice that the labels in Figure 9.1 all have hotkeys. Although a label cannot accept the focus, pressing Alt+hotkey sends the focus to the next control in line, which will be the text box next to the label (assuming that you place the text box right after you place the corresponding label). - Set the interest rate label as follows:
Name: lblRate Alignment: 1-RightJustify Caption: &Interest rate (8 for 8%): Font: Regular 14 Height: 375 Left: 2040 Top: 1080 Width 2895
- Set the interest rate text box as follows:
Name: txtRate Alignment: 0-LeftJustify Font: 10 Height: 375 Left: 5160 ToolTipText: Annual rate investment grows Top: 1080 Width: 615
- Blank out the Text property so nothing appears in the text box at startup (this can be done by deleting the default value of the Text property). Notice that you're adding ToolTipText at the same time you add the control that the user interacts with.
Using Control Arrays | Next Section

Account Sign In
View your cart