Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
(Publisher: The Coriolis Group)
Author(s): Peter G. Aitken
ISBN: 1576102815
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Chapter 2
Visual Basic For Intelligent Folks

Let’s get to work and write your first Visual Basic program.

If someone were to ask me to sum up my approach to teaching programming, I would say, “Learn by doing.” There is just no substitute for sitting down at your computer and putting together a working program, even if you start out with something small and simple. In the previous chapter, you got an overview of Visual Basic; now it’s time to see it in action. I’ll show you the fundamentals of using Visual Basic, and then we will work through the creation of a simple program from start to finish. What’s more, it will be a real program that actually does something useful.

I assume that Visual Basic is already installed on your system. If not, follow the installation instructions in your Visual Basic package. We’ll start by learning how to use some of Visual Basic’s tools, then we’ll move on to the sample program that I promised you.

Visual Basic Basics

After installing Visual Basic on your system, you start it from the Windows Start menu. The exact details will depend on how you got Visual Basic, which is available both as a standalone product and as part of Microsoft’s Visual Studio development platform. In any case, the process will be as follows:

1.  Click on the Start button on the Windows taskbar.
2.  Click on Programs.
3.  On the next menu, click on Microsoft Visual Basic 98 or Microsoft Visual Studio 98.
4.  Finally, click on Visual Basic 98.


TIP:  Is It Visual Basic 6 Or Visual Basic 98?

As of this writing, Microsoft has not decided whether to refer to the new Visual Basic by its version number, 6, or by its year of release, 98. Be assured that Visual Basic 6 and Visual Basic 98 refer to the same product.


When Visual Basic starts, it displays the New Project dialog box, as shown in Figure 2.1. (Depending on the details of your Visual Basic installation, you may see one or more other dialog boxes as well; you can ignore them for now.) In this dialog box, you specify whether you will be working on an existing project or starting a new one. If you are starting a new project, you select the type from the list of project types that Visual Basic supports. You’ll learn more about these options in later chapters. For now, select the Standard EXE icon and click on Open.


Figure 2.1  The New Project dialog box is displayed when you start Visual Basic.

Visual Basic next displays its main window on the screen. As you can see from Figure 2.2, this window contains a lot and can be somewhat intimidating. If your screen does not appear exactly as the figure, don’t worry; we’ll deal with that in a moment. Don’t let the complexity of the screen scare you—you’ll be learning all about these elements soon. Remember, our goal now is to create a working Visual Basic program without stopping to explain all the details along the way. Visual Basic is carefully designed to provide an efficient and easy-to-use interface. Once it becomes more familiar to you, I think you’ll agree.

The next step is to open the View menu and select Toolbox, which will display the Visual Basic toolbox. If your screen did not initially look like Figure 2.2, it should now. (If your toolbox was already displayed, this command will have no effect.) We are now ready to examine some of the individual elements on the screen.


Note:  I assume that while readers of this book may be new to Visual Basic, you have at least a basic familiarity with Windows. Thus, I expect that you already know how to select commands from menus, use the mouse, and so on.

Aside from the menu and toolbar, the initial Visual Basic screen has six different elements, or windows (counting the main window itself).


Figure 2.2  The elements of the main Visual Basic screen.

Main Window

The main Visual Basic window serves two primary purposes. First, it contains the other windows that the program displays. Second, it displays the menu bar and toolbar along the top of the window. The menu bar contains the titles of Visual Basic’s menus, which contain the program’s commands. The toolbar displays buttons you can click on to carry out commonly needed commands. Note that if you position the mouse pointer over a toolbar button for a moment (don’t click), Visual Basic will display a brief description, called a tool tip, of the button’s function.

Form Design Window

Near the center of the screen is the Form Design window where you will draw your program’s visual interface. You start each new project with one blank form, adding others as you develop the project. Each form in a project corresponds to a window or dialog box in the final program. During program design, a grid of dots aids you in aligning the elements placed on the form. These dots are not displayed in the final program.

Toolbox Window

On the left side of the screen is the toolbox. This window contains icons representing the various visual objects, or controls, that you can place on a Visual Basic form. To place a control, click on the corresponding toolbox button, then point and drag on the form to specify the size and location of the control. The toolbox buttons display tool tips in the same manner as the toolbar buttons. The top left button in the toolbox—the arrow—is not a control, but represents the pointer. Select it when you want to edit controls that you have already placed on the form.

Project Explorer Window

At the top right of the screen is the Project Explorer window, which lists all the modules in the current project. The term project simply means a Visual Basic program under development, with all its component objects. A module is just a component of a Visual Basic project. For example, each form is a module. When you start a new project, it contains only a single module—a form with the default name Form1. Likewise, the project itself has the default name Project1. You’ll assign more meaningful names to modules and the project as you work.

Properties Window

Below the Project Explorer window is the Properties window. This window lists the properties of the currently selected object, the name of which is displayed in the box at the top of the window. A form is an object, and the controls you place on it are also objects. An object’s properties control its appearance and behavior—for example, the color of a form’s background is one of its properties. You’ll be learning a lot about object properties throughout this book, so I won’t go into any further detail right now.

Form Layout Window

In the lower right corner of the Visual Basic screen is the Form Layout window. It shows a miniature representation of a computer screen with a small icon showing the relative size and position of each of your project’s forms. You use the Form Layout window to view the relationships among your program’s forms. If you point at a form icon and drag it to a new location, you’ll change the screen position where the form initially displays during program execution.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.