|
 |
 |
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
Chapter 2 Visual Basic For Intelligent Folks
Lets 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 its time to see it in action. Ill show you the fundamentals of using Visual Basic, and then we will work through the creation of a simple program from start to finish. Whats 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. Well start by learning how to use some of Visual Basics tools, then well 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 Microsofts 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. Youll 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, dont worry; well deal with that in a moment. Dont let the complexity of the screen scare youyoull 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 youll 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 Basics menus, which contain the programs 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 (dont click), Visual Basic will display a brief description, called a tool tip, of the buttons function.
Form Design Window
Near the center of the screen is the Form Design window where you will draw your programs 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 toolboxthe arrowis 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 modulea form with the default name Form1. Likewise, the project itself has the default name Project1. Youll 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 objects properties control its appearance and behaviorfor example, the color of a forms background is one of its properties. Youll be learning a lot about object properties throughout this book, so I wont 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 projects forms. You use the Form Layout window to view the relationships among your programs forms. If you point at a form icon and drag it to a new location, youll change the screen position where the form initially displays during program execution.
|