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
Analyzing Sample Applications
Perhaps the best way to begin learning about VB application creation is to analyze sample applications. You will gain practice working within the development environment and master the various windows quickly.
To begin, perform these steps:
- Start Visual Basic. If the New Project dialog box appears, close it; you will open a project without the dialog box's help.
- Select File | Open Project (a toolbar button does this, too) to display folders from which to choose. Select the drive and directory containing the source code you retrieved from the CD that accompanies this book. You will see various project names.
- Locate the project with the filename Lesson 9 Int Proj.vbp (the extension may not appear if you've turned off the display of filename extensions in Windows Explorer). The project describes a simple interest rate application that you'll learn how to create in Hour 9, "Combining Code and Controls."
Several files other than those you see in the dialog box actually reside in the Source folder. Visual Basic knows, however, that when you select File | Open Project, you want to open a project and not another kind of file, so Visual Basic displays only project files in the dialog box. All project files end with the .vbp filename extension to distinguish them from form files that end with the .frm extension and module files that end with .bas (other Visual Basic file types exist, but we won't cover them here).
The advantage that projects present to the Visual Basic programmer is that a project is a bookkeeping record of the entire collection of files that compose an application. When you write even a simple Visual Basic application, Visual Basic creates a project for that application so that as the application's functionality grows, the project can track all the files related to that project. No matter how many files go with a project, when you open the project, Visual Basic puts the project's files at your fingertips in the Project window.
Double-click the Lesson 9 Int Proj.vbp project file now. The Project window now displays two folders, one named Forms and one named Modules. Open the Forms folder and then double-click the form named frmInterest in the Project Explorer window. Your development environment changes dramatically to display the project, as shown in Figure 2.2.
Figure 2.2 The Lesson 9 Int Prog project.
As you might guess from the name of the project and from the window in front of you, this application calculates interest rates for loans and investments. Click any plus signs you see in the Project window to expand the list. You now know that this application is a collection of two files: a form and a module file. Actually, a third file goes with the project: the Lesson 9 Int Proj.vbp project file itself, which Visual Basic keeps track of and updates as needed. (Drag the edge of the Project window to see more of the text within the window.)
The Project window describes two important aspects of a VB project: the external disk drive filenames for each project file and the internal names used inside the project. For example, the current form open in the Form window is named frmInterest. VB's title bar shows the name of the open form file and also shows that the file is a form and not another kind of file.
To every area of your project, the form is called frmInterest. This form got its name from the program writer, who named the form frmInterest. As you'll see throughout this tutorial, programmers often precede items they name with a three-letter abbreviation for the object. Thereafter, when you look through a list of object names, you'll know just from the names what the names represent.
The form isn't stored on the disk drive under the name frmInterest, however. As the Project window's parentheses show, the form named frmInterest is called Lesson 9 Int Form.frm on the disk. Rarely will the actual filename match that of the internal name used in the project. In a way, the three-letter abbreviated prefix works like a file extension in that the prefix describes the object type.
The naming rules for internal Visual Basic names differ from those of files. Therefore, you will need to give each object you create in the Project window both a filename and an internal VB name. If you don't supply a name, Visual Basic supplies one for you, but VB isn't good at assigning names to objects. VB would be happy calling every command button on your form Command1, Command2, and so on. When you name command buttons, however, you'll make up names that better match their meaning, such as cmdOK and cmdExit.
Naming Objects | Next Section

Account Sign In
View your cart