📄 vel04.htm
字号:
<P>cmdExit</UL></UL><UL><UL><P>ListBoxJan</UL></UL><UL><UL><P>Nov95Combo</UL></UL><UL><UL><P>TitleScreen<BR></UL></UL><P>and these are not:<BR><UL><UL><P>Select</UL></UL><UL><UL><P>723</UL></UL><UL><UL><P>cmdExit&Leave<BR></UL></UL><P>Select is a Visual Basic command. 723 does not begin with a letter of the alphabet. cmdExit&Leave contains an invalid character, the ampersand (&).<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Warning: </B>Even though the underscore is a valid character, many programmers prefer not to use the underscore because it sometimes can look like a minus sign.<BR>Many programmers use <I>hump </I>notation—mixing uppercase and lowercase letters in names that contain several words. The term <I>hump</I> comes from a camel's back, which the uppercase letters in the name sort of resemble. For example, cmd_Add_Sales is a valid name, but cmdAddSales is just as readable and it does not contain the underscore characters that sometimes lead to confusion.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Learn these naming conventions well. The naming conventions apply not only to Name properties but also to other aspects of Visual Basic, such as <I>variables</I> and <I>procedures</I>.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE>Write Once, Maintain Often: Rarely are you finished with a program after you write it. You usually have to update the program to reflect changes in the environment in which you use it. When you update a program already written, you are doing what is called <I>program maintenance</I>.<BR>For example, if you wrote an accounting program for a small company that merged with a second firm, the accounting department might have to keep both companies separate until the current fiscal year ends. You must modify the program so that the program distinguishes between the two companies and keeps two sets of data. The more time you spend giving meaningful names to controls, the less time you will spend later trying to figure out what each control is for. It is obvious that a control named cmdComputeProfit triggers the computation of a profit calculation.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>I strongly suggest that you adopt is the standards for naming control prefixes listed in Table 4.1. Table 4.1 shows the three-letter prefix that you should add to the front of a name when you name a control. The prefix describes what the control is. Therefore, from the name itself, you know what kind of control you are working with. Of course, if you placed the control on the form and named the control to begin with, you would know what kind of control you are adding. When you add code to event procedures later, however, the three-letter prefix helps you keep the kinds of controls straight and it prevents you from trying to write an incorrect event procedure for a control that does not produce that particular event.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>Table 4.1 lists all the naming conventions for controls and forms, including those controls that you do not know yet.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 4.1. Standards for naming control prefixes.</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>Prefix</I></FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Control</I></FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>cbo</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Combo box</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>chk</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Check box</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>cmd</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Command button</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>dir</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Directory list box</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>drv</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Drive list box</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>fil</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>File list box</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>fra</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Frame</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>frm</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Form</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>grd</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Grid</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>hsb</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Horizontal scroll bar</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>img</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Image</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>lbl</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Label</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>lin</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Line</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>lst</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>List box</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>mnu</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Menu</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>ole</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>OLE client</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>opt</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Option button</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>pic</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Picture box</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>shp</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Shape</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>tmr</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Timer</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>txt</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Text box</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>vsb</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Vertical scroll bar</FONT></TABLE><P>Here are some control names that use the three-letter prefixes from Table 4.1:<BR><UL><UL><P>frmOpening</UL></UL><UL><UL><P>lstSelections</UL></UL><UL><UL><P>chkBooksInPrint<BR></UL></UL><P>There is a wider blanket of conventions that cover the look and behavior of all Windows programs. The book <I>The Windows Interface: An Application </I><I>Design Guide, </I>by Microsoft,<I> </I>discusses all the standards. It suggests how you can design your Windows programs so that they behave like other Windows programs.<BR><P>When users move from DOS to Windows, they often complain that Windows is different and hard to learn and use. They are correct that Windows is different, but there is there is much disagreement on how difficult and hard-to-use Windows is.<BR><P>Even if you accept that Windows is hard to learn and use, you have to learn the Windows interface only once. That means that after you master a Windows program, such as the Visual Basic programming environment or Microsoft Excel, every other Windows program behaves in almost exactly the same manner. Almost every Windows program contains an Exit command on a File pull-down menu. Almost every Windows program displays the same File Open dialog box. Almost every Windows program displays a white background. Software developers do not have to follow these standards, but users are more likely to learn the programs if they do. The application design guide helps them stay consistent with the standards.<BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>When you name controls, don't assign arbitrary names or even stick to the name that Visual Basic assigns—you won't like Visual Basic's suggestions. Select a name that indicates the purpose of the control, and use one of the three-letter prefixes described in Table 4.1. By following such standards, you will ensure that your program is easier to maintain down the road.<BR><BR><A NAME="E68E36"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>More Consistency: AUTOLOAD.MAK and CONSTANT.TXT</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>With the AUTOLOAD.MAK and CONSTANT.TXT files, you can add even more consistency to your Visual Basic programs.<BR><P>Over time, you incorporate many common elements in your Visual Basic programs. Perhaps you have written a set of routines in the Visual Basic language that you want to make available to several Visual Basic programs. As you already know, by adding files to the project window, you, in effect, add those files to the resulting application.<BR><P>AUTOLOAD.MAK is a special project file that you can load and look at. If you load the file, you won’t see anything that looks very special. The Form window is empty, and the Project window contains the same two files, GRID.VBX and OLECLIEN.VBX, that you saw earlier when you started Visual Basic and loaded and ran an application.<BR><P>The purpose of AUTOLOAD.MAK is to create a base application that you add new features to and build on to create another application. In other words, whenever you start creating a new application using the File New Project command, Visual Basic looks at the contents of AUTOLOAD.MAK and creates a new base application that looks just like AUTOLOAD.MAK. Therefore, if you want to change the default behavior of your new applications, load and change AUTOLOAD.MAK. After you change AUTOLOAD.MAK, all future projects that you create will hold those changes.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>Think of AUTOLOAD.MAK as working as how the DOS AUTOEXEC.BAT file works. Whenever you start your computer, DOS looks at the AUTOEXEC.BAT file and starts the computer according to those instructions. Every time you start a new application, Visual Basic looks at AUTOLOAD.MAK and creates a new application with the same features as AUTOLOAD.MAK.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Now take a look at how changing AUTOLOAD.MAK changes all your new projects. Load AUTOLOAD.MAK if it is not loaded, and look at the Project window. Because you won’t need the GRID.VBX or OLECLIEN.VBX files for a while, there is no reason to load them along with all the others every time you create a new application. Once you load AUTOLOAD.MAK, follow these steps to remove the files:<BR><OL><LI>Display the Project window if you cannot see the Project window.<BR><BR><LI>Highlight the GRID.VBX file.<BR><BR><LI>Select the File Remove File command. As soon as you do, Visual Basic removes GRID.VBX from the Project window. The last file in the project, OLECLIEN.VBX, is still highlighted.<BR><BR><LI>Select File Remove File again. Visual Basic removes OLECLIENsx.VBX from the project window.<BR><BR></OL><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>By the way, your toolbox now contains two fewer controls because the two .VBX files that you just removed contained special controlling tools called <I>custom </I><I>controls</I>.</NOTE><BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -