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
Mastering the Development Environment
Learning the ins and outs of the development environment before you learn Visual Basic is somewhat like learning the parts of an automobile before you learn to drive; you might have a tendency to skip the terms and jump into the fray. If, however, you take the time to learn some of the development environment's fundamental principles, you'll be better able to learn Visual Basic. You then will be more comfortable within VB's environment and will have a better understanding of the related words when subsequent lessons refer to the windows and tools in the development environment.
Figure 1.3 shows the Visual Basic development environment with many of the more important screen components labeled. As you can see from the menu and toolbar, Visual Basic looks somewhat like other Windows programs on the market. Many of Visual Basic's menu bar commands work just as they do in other applications such as Microsoft Word. For example, you can select Edit | Cut and Edit | Paste to cut and paste text from one location to another. These same menu commands appear on almost every other Windows program on the market today.
Figure 1.3 Getting to know the development environment.
Standards: The Menu Bar and Toolbar
Visual Basic's menu bar and toolbars work just as you expect them to. You can click or press a menu bar option's hotkey (for example, Alt+F displays the File menu) to see a pull-down list of menu options that provide commands, another level of menus, or dialog boxes. Many of the menu options have shortcut keys (often called accelerator keys) such as Ctrl+S for the File | Save option. When you press accelerator keys, you don't first have to display the menu to access the option.
The toolbar provides one-button access to many common menu commands. Instead of selecting Edit | Paste, for example, you could click the Paste toolbar button. As with most of today's Windows applications, Visual Basic supports a wide range of toolbars. Select View | Toolbars to see a list of available toolbars. Each one that is currently showing will appear with a check mark by its name.
The Form Window: Where It All Happens
The Form window is your primary work area. Although the Form window first appears small relative to the rest of your screen, the Form window makes up the background of your application. If you write a Windows-based calculator with Visual Basic, the calculator's buttons all reside on the Form window and when someone runs the calculator, the calculator that appears is really just the application's Form window with components placed there and tied together with code.
Consider the sample program running in Figure 1.4's window. The window shows a simple dialog box with a few options, text boxes, and command buttons.
Figure 1.4 A simple dialog box produced from a running Windows programs.
The programmer who created Figure 1.4's dialog box did so by opening a Form window, adding some controls (the items on the Form window that interact with the user—sometimes called tools), and tying the components together with some Visual Basic language code. That's exactly what you will do when writing both simple and complex Visual Basic applications. You will begin with a blank Form window and add controls to it, such as options and command buttons. Perhaps your application will even require multiple Form windows.
Compare Figure 1.4 with Figure 1.5. As you can see, Figure 1.5 shows the same application in the VB development environment, in its design-time state as opposed to its runtime state, which is shown in Figure 1.4. It is during design time that you design, create, edit, and correct the application. When you run the application, you can see the results of your work.
Figure 1.5 The dialog box shown inside VB's development environment.
The parts of the application that you create, such as the forms, the code, and the graphics that you prepare for output compose the source program. When you or another user compiles or runs the source program, VB translates the program into an executable program. You cannot make changes directly to an executable program. If you see bugs when you run the program, you must change the source application (which might contain multiple files in the project) and rerun or recompile the source.
The Toolbox Supplies Controls
The toolbox contains the controls that you place on the Form window. All the controls in Figure 1.5 appear on the toolbox. In the next hour, you'll learn how to place toolbox controls on the Form window. The toolbox never runs out of controls; if you place a command button on the Form window, another awaits you on the toolbox, ready to be placed.
Figure 1.6 names every tool that appears on the standard Toolbox window. These are called the intrinsic controls because all three editions of VB support these standard tools. You can add additional controls to the toolbox as your needs grow. Some extra tools come with all three editions of VB, but these extra tools don't appear on the Toolbox window until you add them through the Project | Components menu option. If you use the Professional or Enterprise Editions, you will be able to add extra controls that don't appear in the Standard Edition's collection of intrinsic and extra controls.
Figure 1.6 The VB toolbox contains intrinsic controls.
The Form Layout Window Places Forms
The Form Layout window displays the initial position and relative size of the current form shown in the Form window. For example, look back at Figure 1.5 to see the Form Layout window. The application shown is a multiple-form application. The form with the title Text Box Properties is just one of several forms. The Form Layout window always shows where the form appears in the current Form window. If you want the form to appear at a different location than the current position, you can move the form inside the Form Layout window to move the position where the form appears when the user runs the application.
This book generally doesn't show the Form Layout window in figures to give more room to the Form window and its contents. You can display the Form Layout window from the View menu, and you can hide the Form Layout window by clicking its Close button.
The Project Explorer Window
The Project Explorer window, often called the Project window, gives you a tree-structured view of all the files in the application. Microsoft changed the formal name from Project window to Project Explorer window between versions 4 and 5 to emphasize the resemblance of the window to the typical Explorer tree-structure file views prevalent in Windows NT and 95. You can expand and collapse branches of the view for more or less detail.
The Project Explorer window displays forms, modules (files that hold supporting code for the application), classes (advanced modules), and more. When you want to work with a particular part of the loaded application, double-click the component in the Project window to bring that component into focus. In other words, if the Project Explorer window displays three forms and you need to edit one of the forms, locate and double-click the form name in the Project window to activate that form in the Form window. Figure 1.7 shows a Project Explorer window that contains several kinds of files.
Figure 1.7 The Project Explorer keeps track of a project's components.
The Properties Window
Properties are detailed descriptive information about a control. A different list appears in the Properties window every time you click over a different Form window tool. The Properties window describes properties (descriptive and functional information) of the form and its controls. Many properties exist for almost every object in Visual Basic. The Properties window lists all the properties of the Form window's selected control.
Help Is at Your Fingertips | Next Section

Account Sign In
View your cart