⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vel03.htm

📁 简单的说明如何使用VB,非常适合初学使用者,而且是用图表来解说的
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<HTML><HEAD><TITLE>Visual Basic in 12 Easy Lessons vel03.htm </TITLE><LINK REL="ToC" HREF="index.htm"><LINK REL="Index" HREF="htindex.htm"><LINK REL="Next" HREF="vel04.htm"><LINK REL="Previous" HREF="velp01.htm"></HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080"><A NAME="I0"></A><H2>Visual Basic in 12 Easy Lessons vel03.htm</H2><P ALIGN=LEFT><A HREF="velp01.htm" TARGET="_self"><IMG SRC="purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A><A HREF="index.htm" TARGET="_self"><IMG SRC="purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A><A HREF="vel04.htm" TARGET="_self"><IMG SRC="purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A></A><HR ALIGN=CENTER><P><UL><UL><UL><LI><A HREF="#E68E21" >What You'll Learn</A><LI><A HREF="#E68E22" >Loading and Running a Program</A><LI><A HREF="#E68E23" >The Label Control</A><LI><A HREF="#E68E24" >The Text Box Control</A><LI><A HREF="#E68E25" >Command Buttons are Fun!</A><LI><A HREF="#E68E26" >Check Box Controls</A><LI><A HREF="#E68E27" >Option Buttons Limit the Choices</A><LI><A HREF="#E68E28" >Dropdown Combo Lists</A><LI><A HREF="#E68E29" >Simple Combo Box</A><LI><A HREF="#E68E30" >The List Box for Selections</A><LI><A HREF="#E68E31" >Homework</A><UL><LI><A HREF="#E69E29" >General Knowledge</A><LI><A HREF="#E69E30" >Find the Bug</A><LI><A HREF="#E69E31" >Extra Credit</A></UL></UL></UL></UL><HR ALIGN=CENTER><A NAME="E66E4"></A><H1 ALIGN=CENTER><CENTER><FONT SIZE=6 COLOR="#FF0000"><B>Lesson 2, Unit 3</B></FONT></CENTER></H1><BR><A NAME="E67E7"></A><H2 ALIGN=CENTER><CENTER><FONT SIZE=6 COLOR="#FF0000"><B>Contents of Visual Basic Programs</B></FONT></CENTER></H2><BR><BR><A NAME="E68E21"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>What You'll Learn</B></FONT></CENTER></H3><BR><UL><LI> [lb] Loading and running a program<BR><BR><LI> [lb] The label control<BR><BR><LI> [lb] The text box control<BR><BR><LI> [lb] Command buttons are fun!<BR><BR><LI> [lb] Check box controls<BR><BR><LI> [lb] Option buttons limit the choices<BR><BR><LI> [lb] You've been framed<BR><BR><LI> [lb] Drop-down combo lists<BR><BR><LI> [lb] A simple combo box<BR><BR><LI> [lb] The list box for selections<BR><BR></UL><P>This unit explains all about the format of Visual Basic programs. Unlike most programming languages, the Visual Basic language contains text commands as well as graphical controls. The text commands interact with the controls to produce the output of the program and the interactions with the user.<BR><P>This unit concentrates on the graphical controls that you put in Visual Basic programs. As you read further into this book, you will gain a deep understanding of how the commands work. Some of the Visual Basic commands are easy, and some are complex. This unit concentrates on explaining the contents of programs. It shows you how to load and run Visual Basic programs.<BR><P><B>Note: </B>This is a hands-on unit. You will use Visual Basic as you progress through this unit to learn how each of Visual Basic's graphical tools work.<BR><BR><A NAME="E68E22"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Loading and Running a Program</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>Once you start Visual Basic, you can create a program. Once you create a program, you can save that program and load and run it later. This unit gives you practice in loading and running a program that is stored on the disk that comes with this book.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><I>Definition: </I>Users perform I/O with <I>controls</I>.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>This book's disk comes with a program that demonstrates several of the most important controls in Visual Basic. A control handles much of the user's input and output, often called <I>I/O</I>. In other words, when someone (the user) runs the program that you (the programmer) creates, the user must interact with the program by providing answers to questions and selecting options displayed on the screen.<BR><P>Remember that the Toolbox window is where you get the controls that you place on the Form window. The Form window is the background of the application that you are creating. Figure 3.1 shows where the controls appear on the Toolbox window.<BR><P><B> <A HREF="03vel01.gif">Figure 3.1. The controls that your program needs </B><B>are available on the Toolbox window.</A></B><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE>The Project File: A Visual Basic program rarely resides in a single file. Most of the time, it takes several files to describe a single Visual Basic application. It often helps to separate the pieces of a Windows program into multiple files.<BR>For example, there is almost always a form file. The form file holds the contents of the Form window that you create as well as all the code that manipulates the objects on the Form window. You might also write additional code that you want to store in a separate file. If your the application requires special controls that do not regularly appear on the Visual Basic Toolbox window, you must add those control files to the application, too.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE>The Project window contains a list of every file in the application. By default, the Visual Basic Primer disk always adds three files to every application's Project window: A form file with the default name FORM1.FRM and two special Visual Basic controls called GRID.VBX (more commonly known as the <I>grid control</I>) and OLECLIEN.VBX (called the <I>OLE control</I>). For now, don&#146;t worry about the special controls.<BR>The Project window's contents are described in yet another file, which is called the <I>project file</I>. Every application has a project file, which always ends with a .MAK extension. When you want to load and run an application, you load its project file; Visual Basic ensures that all files in the project are loaded as well.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>There is a program on this book's disk described in the project file called CONTROLS.MAK. Follow these steps to load CONTROLS.MAK:<BR><OL><LI>Start Visual Basic if it is not running.<BR><BR><LI>Select File Open Project from the menu bar. Visual Basic displays the standard Windows File Open dialog box.<BR><BR><LI>Select the disk and path name of the Visual Basic Primer system if the disk and pathname are different from the location of your Visual Basic Primer system. Select or type the following filename at the File Name prompt: <B>CONTROLS.MAK</B>. You can type the name in either uppercase or lowercase letters.<BR><BR><LI>  Visual Basic loads the project. When Visual Basic finds the CONTROLS.MAK project file, it reads the file and loads all the files related to that particular project. You can see from the Project window that Visual Basic has loaded three files.<BR><BR><LI>CONTROLS.MAK does not use two of its three files. The GRID.VBX and OLECLIEN.VBX files are extremely advanced; you can ignore them for now. Visual Basic does not usually display the form when you open a project file. To see the form, press the View Form button on the Project window. Your screen will look like the one in Figure 3.2.<BR><BR></OL><P><B> <A HREF="03vel02.gif">Figure 3.2. The Form window is often very </B><B>crowded.</A></B><BR><P>The Form window works like an artist's easel of paper. Actually, the Form window works more like an artist's easel of one or more transparencies with something differently drawn on each transparency. CONTROLS.MAK contains several controls placed on top of one other. The program looks like a mess.<BR><P>When the user runs the program, he sees the Form window. What the user sees, however, does not always look like the Form window when the program is first loaded. In other words, you are now looking at all the pieces of the program piled on top of each other. When the user&#151; <I>you,</I> in this case&#151;runs the program, the program ensures that those pieces appear in a logical order and do not overlap.<BR><P>Before you or anyone else can run a program from within the Visual Basic environment, you must load the program through the File Open command, just as you have done. Once you load a program, you have three ways to run it:<BR><UL><LI> [lb] Select Run Start from the menu bar.<BR><BR><LI> [lb] Press F5, the shortcut access key for the Run Start menu command.<BR><BR><LI> [lb] Press the Start button on the toolbar. (As you saw in the previous unit, the Start button looks like the Play button on a cassette recorder.)<BR><BR></UL><P>Use one of these three methods to run the program. You will see the more organized and less cluttered screen shown in Figure 3.3. The program's initializing instructions cleaned up the mess that you originally saw in the Form window. As you can see, the Form window of the Visual Basic environment becomes the application's background (minus the grid of dots in the background).<BR><P><B> <A HREF="03vel03.gif">Figure 3.3. The running program is much </B><B>cleaner.</A></B><BR><P>This program demonstrates each of the primary Visual Basic controls so that you can familiarize yourself with using them before you place them in your own applications.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>Notice that the program contains an Exit command button in the lower-right corner. All of this book's applications offer an Exit command button so that you can terminate the program whenever you want. When you create your own programs, always give your user a way to exit the program.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>Before you can run a Visual Basic program, you must load it. Generally, you load the project file, which always ends with a .MAK extension. Loading the project causes Visual Basic to load all the files related to the application. Without a mechanism such as a project file, you would have to keep track of all the files related to every application and load each of them individually whenever you wanted to run a Visual Basic program. Once Visual Basic loads all the files related to the project, you can run the program and see what the program does.<BR><BR><A NAME="E68E23"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>The Label Control</B></FONT></CENTER></H3>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -