📄 vel02.htm
字号:
<LI>Start the Windows File Manager. You will find the File Manager icon in the Main program group.<BR><BR><LI>Click the C: drive to activate C if it is not already the active drive.<BR><BR><LI>You'll see the vbprimer directory file folder in the list of directories in the left panel. Click vbprimer to open the file folder.<BR><BR><LI>Press F8 to open the Copy dialog box. Type <B>A:\PGMS\*.*</B> and press Enter to copy all the working applications to the VBPRIMER directory.<BR><BR><LI>Close the File Manager by double-clicking the control button in the upper-left hand window. You have now successfully copied all the applications to your hard disk along with Visual Basic.<BR><BR></OL><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>Your computer now has this book's Visual Basic program installed. You are ready to start the program and master the environment.<BR><BR><A NAME="E68E15"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Starting and Stopping Visual Basic</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>To write a Windows program with Visual Basic, you have to start Visual Basic. Before exiting Windows, you must exit Visual Basic.<BR><P>Your Window's Program Manager might have placed the Visual Basic 2.0 icon virtually anywhere on the screen. Look through your icons in the Program Manager until you find the one labeled Visual Basic 2.0. Double-click the icon; the Visual Basic program group appears with a single icon labeled Visual Basic Primer.<BR><P>Double-click the Visual Basic Primer icon to start Visual Basic. Figure 2.4 shows the Visual Basic opening screen.<BR><P><B> <A HREF="02vel04.gif">Figure 2.4. The Visual Basic startup screen.</A></B><BR><P>As you can see from Figure 2.4 and probably from your own screen, the underlying Program Manager icons often peek through to the Visual Basic programming area. Go ahead and exit Visual Basic, and you will learn a way to keep those Program Manager icons from coming through.<BR><P>Visual Basic is consistent with most Windows programs in that its menus and commands are similar in many ways to Excel, Access, and other programs with which you might be familiar. To exit Visual Basic, select the Exit command from the File menu. When you do this, Visual Basic quits and you are back at the Program Manager. If the Visual Basic program group is still open, double-click its control button to close the open window.<BR><P>If you want to keep the Program Manager program group icons from showing through to the Visual Basic desktop, click the Program Manager's Options Minimize on Use command. Display the Options menu once more to see that there is now a checkmark next to the second option. The checkmark means that the Program manager shrinks to a small icon when you start any Windows program. The next time you start Visual Basic, the Program Manager icons will no longer get in your way.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>Here's a great shortcut that even many advanced Windows people do not know: Open the Visual Basic 2.0 icon from the Windows Program Manager. With the Visual Basic Primer icon still highlighted, select File Properties from the Windows menu bar. Press Alt+S to move the text cursor to the Shortcut Key prompt. Press the letter <B>V</B> so that the Shortcut Key prompt changes to Ctrl+Alt+V. Press Enter or click the OK button to close the Program Item Properties dialog box. From now on, you will not even have to open the Visual Basic 2.0 program group when you want to start Visual Basic. Simply press Ctrl+Alt+V from the Windows Program Manager; Visual Basic will start immediately.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Warning: </B>Always exit Visual Basic before you shut off your computer or you might lose part or all of the program that you are writing.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>Unless you add a shortcut keystroke to start Visual Basic, starting Visual Basic requires only that you double-click the Visual Basic Primer icon inside the Visual Basic 2.0 Program Manager group. To exit Visual Basic and return to Windows, you can select File Exit.<BR><BR><A NAME="E68E16"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>The Visual Basic Environment</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>Before you learn how to write programs with Visual Basic, you must learn all about the Visual Basic screen. Some people think that the Visual Basic screen is confusing at first. They are wrong. The Visual Basic screen is confusing not only at first but also the <I>whole</I> time you use it! Actually, Visual Basic's screen is more busy than it is confusing. Once you learn how to manage the parts of the screen, however, you will feel much more comfortable using Visual Basic.<BR><P>Being an effective Visual Basic programmer means knowing how to rearrange the Visual Basic screen when needed. Visual Basic does not really look like every Windows program. For example, Microsoft Word is one of the most powerful and most used Windows programs. When you use Word, you basically work within one gigantic window. You can open a second document window and resize the two windows to add more screen elements, but most of the time you work within a single document window.<BR><P>In Visual Basic, you work with several open windows most of the time. There are several windows—sometimes called <I>window panes</I> in this book—open, and you will often need information from each of the windows. Therefore, you should get familiarized with the screen and its components early on.<BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>Learn all you can about the Visual Basic environment now so that you can concentrate on the language and controls later.<BR><BR><A NAME="E68E17"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>The Five Windows</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>The Visual Basic environment contains several windows with which you will work as you build applications.<BR><P>Figure 2.5 illustrates the major parts of the Visual Basic screen. You might not understand all the components of the screen just yet, but learn the names of the screens now so that you will move right along later when you begin learning how to program Visual Basic.<BR><P><B> <A HREF="02vel05.gif">Figure 2.5. The elements of the Visual Basic </B><B>screen.</A></B><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Warning: </B>Actually, Figure 2.5 does not look exactly like your screen probably will look when you first start Visual Basic. You will soon learn how to rearrange the screen so that the screen can look just like the screen in Figure 2.5. Figure 2.5 looks the way it does so that you can see all the major parts of the screen.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Table 2.1 describes each of the five primary windows of Visual Basic. Although you cannot understand all of the descriptions at this point, try to familiarize yourself with the descriptions so that the windows will not be so foreign later when you learn how to program in Visual Basic.<BR><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 2.1. The primary windows inside the Visual Basic environment.</B></FONT></CENTER><BR><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 ><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Window</I></FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Description</I></FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Form</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Contains the background for the Windows program that you are writing. You draw and place items on the form that your program's user will eventually see and interact with. If you use a Windows word processor, the form would hold the document that you are editing. Although not every Visual Basic program requires forms, most do because most Visual Basic programs exist to display information for, and retrieve information from, the user.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Toolbox</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The Toolbox window contains your tools. That might seem obvious, but you need to know that the tools of Visual Basic are more often called <I>controls</I>. The toolbox is where you will find controls that you will place on the Form window as you create a Windows program. For example, when you need to ask the user for text, you will select a text box control from the toolbox and place that text box on the form.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Project</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A Visual Basic Windows program often contains several different kinds and types of files that all work in unison to form the single running application. The Project window contains the list of all the files used in the current application. Given the common Visual Basic terminology, a Visual Basic application is generally called a <I>project</I>. The Project window contains the contents of the project. The Project window is simply a description of the files but the files all reside separately on the disk.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Properties</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The Properties window describes every individual element in your application. For example, there is a Properties window for a project's form because the form contains properties such as color and size. As you place controls from the Toolbox window onto the Form window, each of those controls has its own properties. Although any one Visual Basic program might have several elements with properties, there is only one Properties window. When you want to see the properties of a different form or control, you change the Properties window to display another set of properties.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Code</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Unlike most other programming languages, you do not have to write much code as you develop applications in Visual Basic. The more advanced the application needs to be, the more code you will have to write to tie things together. The visual parts of Visual Basic, however, eliminate much of the code that you would have to write if you were still working in a text-based environment. Although you should not expect to understand anything just yet, Figure 2.6 shows a Code window that contains a fairly complex routine. The code in the Code window is the program's source code, which you learned about in the previous unit. When the user runs the program, Visual Basic and your computer interprets that source code and executes the instructions in the source code.</FONT></TABLE><P><B> <A HREF="02vel06.gif">Figure 2.6. A Code window with lots of code.</A></B><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>Much of the time, the code inside the Code window contains setting and retrieval instructions for form controls. For example, if you need to check whether a user clicked a command button or typed a response, you can use code to check for the click.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>As with most windows used inside Windows applications, you can move, resize, and close the five windows. Use the mouse to make working with windows simple.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><I>Definition: Maximize</I> means to increase a window to its largest size.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>For example, when you first start Visual Basic, the Form window hides the other windows. Usually, the Form window is the largest window because the Form window is the user's background. You can maximize the Form window by double-clicking the mouse on the Form window's title bar or by clicking the maximize button in the window's upper-right hand corner. Double-click the Form window's title bar now to maximize the window. When you do, there is nothing left on the screen.<BR><P>Obviously, there is a way to see the menu and the other windows. Press Alt to get the top of the screen back so that you can see the menu bar and toolbar again. Display the Window pull-down menu, and select the Project window to see the Project window. Click the Project window's View Code button to see the Code window.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>There are two other ways to display the Code window. You can select View Code to see the window. You can also press F7 to display the code.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Click anywhere on the white portion of the Form window. Clicking any window activates that window, highlights its title bar, and makes all its commands and menus available. When you activate the Form window, the Project window and Code window hide behind the form, but you can get them back by following the descriptions just offered.<BR><P>To see the form’s Properties window, press F4 or select Window Properties to see the Properties window. Move the mouse cursor over the Properties window and click and hold the mouse button. You can now move the Properties window by dragging the mouse across the screen. When you let up on the mouse button, Visual Basic anchors the Properties window at that point.<BR><P>Try resizing the Properties window. Move the mouse cursor to any edge or corner of the Properties window. The mouse changes to a double-pointing arrow. By dragging the mouse, you can resize the window.<BR><P>When you are ready to close a window, the easiest way is to double-click its control button. However, if you click the control button once, you will see the window’s control menu, such as the one shown in Figure 2.7. You have probably seen the control menu in other Windows work that you have done. If not, you can use the control menu to move, resize, and close the window with your keyboard. Using the mouse as just described, however, is easier than using the control menu. To close the control menu, you can click the control button once again or press the Esc key twice.<BR><P><B> <A HREF="02vel07.gif">Figure 2.7. The control menu.</A></B><BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>The five primary windows of Visual Basic supply the locations for controls and work areas that you will use to build Visual Basic applications. The Form window is the most important window for the applications that you write because it is on the Form window where you will draw and place interactive controls for the user to work with. The other windows exist to offer help and tools.<BR><BR><A NAME="E68E18"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>The Top of the Screen</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>As you learn more about Visual Basic's environment, you will find that Visual Basic conforms well to the standard look and feel of standard Windows programs. Many Windows programs contain menus and toolbars that work much like Visual Basic's.<BR><P>The top of the screen contains the menu bar and toolbar. The menu bar contains lists of pull-down menus with which you can manage your Visual Basic program. The toolbar supplies quick push-button commands for common tasks.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Warning: </B>Don't confuse the terms <I>toolbar</I> with <I>toolbox</I>. The toolbar appears under the menu bar and contains buttons with icons on them. The toolbox is what is typically called the Toolbox window where the controls are located that you will eventually place on the form.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><BR><A NAME="E69E20"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>The Menu Bar</B></FONT></CENTER></H4><BR><P>If you have worked much with other Windows programs, you are already familiar with the File, Edit, View, Window, and Help menu bar commands because they are similar across many Windows applications. Table 2.2 describes all the Visual Basic menu bar commands with which you will work.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>The menu bar contains additional menus that pull down just like virtually all Windows applications use. These pull-down menus are sometimes called <I>submenus.</I> The commands on the submenus perform tasks or produce dialog boxes that require extra information from you before Visual Basic can issue the commands.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 2.2. The menu bar commands.</B></FONT></CENTER><BR><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 ><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Command</I>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -