现在的位置: 首页 > 综合 > 正文

重拾VB6(33):发布、限制、编程规范、编译器开关及添加帮助

2013年06月17日 ⁄ 综合 ⁄ 共 4697字 ⁄ 字号 评论关闭

来自MSDN-2001-OCT: Visual Tools and Languages/Visual Studio 6.0 Documentation/Visual Basic Documentation/Using Visual Basic/Programmer’s Guide/Part 2: What Can You Do With Visual Basic/Distributing Your Applications and its following chapters

1. Distributing Your Applications

分发包括打包和部署两个步骤。打包工具有两个:the Package and Deployment Wizard (formerly the Setup Wizard), or the Setup Toolkit provided with your Visual Basic installation. 前者比较傻瓜,后者有更多的控制。

2. Visual Basic Specifications, Limitations, and File Formats

(1) Variable names in Visual Basic can be no longer than 255 characters, and the names of forms, controls, modules, and classes cannot be longer than 40 characters.

(2) 还有其他各种极限约束,略。

(3) VB6的各种文件后缀,略。

(4) While many of the files in a typical Visual Basic project are in a binary format and are readable only by specific processes and functions of Visual Basic or your application, the form (.frm) and project (.vbp) files are saved as ASCII text. These are readable in a text viewer.

frm文件的结构,错误log及信息,略。

vbp文件的结构,略。

3. Visual Basic Naming Conventions

(1) Object Naming Conventions: This section lists recommended conventions for controls, data access objects, and menus.

(2) Variable Naming Conventions

In a Visual Basic application, global variables should be used only when there is no other convenient way to share data between forms. When global variables must be used, it is good practice to declare them all in a single module, grouped by function. Give the module a meaningful name that indicates its purpose, such as Public.bas.

Global variables that are used in procedures should be identified in the declaration section at the beginning of the procedure.

In addition, you should pass arguments to subs and functions using ByVal, unless you explicitly need to change the value of the passed argument.

A variable has global scope if it is declared Public in a standard module or a form module. A variable has module-level scope if declared Private in a standard module or form module, respectively.

Variables should be prefixed to indicate their data type. 完整列表,略。

(3) Constant Naming Conventions

The body of constant names should be mixed case with capitals initiating each word.

(4) Descriptive Variable and Procedure Names

function names should begin with a verb, such as InitNameArray or CloseDialog.

(5) User-Defined Types

In a large project with many user-defined types, it is often useful to give each such type a three-character prefix of its own. If these prefixes begin with "u," they will still be easy to recognize quickly when you are working with a user-defined type. For example, “ucli” could be used as the prefix for variables of a user-defined Client type.

4. Code Commenting Conventions

(1) All procedures and functions should begin with a brief comment describing the functional characteristics of the procedure (what it does).

(2) Arguments passed to a procedure should be described when their functions are not obvious and when the procedure expects the arguments to be in a specific range.

(3) Function return values and global variables that are changed by the procedure, especially through reference arguments, must also be described at the beginning of each procedure.

(4) Procedure header comment blocks should include the following section headings. For examples, see the next section, "Formatting Your Code."

Section heading Comment description
Purpose What the procedure does (not how).
Assumptions List of each external variable, control, open file, or other element that is not obvious.
Effects List of each affected external variable, control, or file and the effect it has (only if this is not obvious).
Inputs Each argument that may not be obvious. Arguments are on a separate line with inline comments.
Returns Explanation of the values returned by functions.

(5) Every important variable declaration should include an inline comment describing the use of the variable being declared.

(6) At the start of the .bas module that contains the project's Visual Basic generic constant declarations, you should include an overview that describes the application, enumerating primary data objects, procedures, algorithms, dialogs, databases, and system dependencies. Sometimes a piece of pseudocode describing the algorithm can be helpful.

5. Structured Coding Conventions

(1) Formatting Your Code: Standard, tab-based, nested blocks should be indented four spaces (the default).

The functional overview comment of a procedure should be indented one space. The highest level statements that follow the overview comment should be indented one tab, with each nested block indented an additional tab.

(2) Grouping Constants: Variables and defined constants should be grouped by function rather than split into isolated areas or special files. Visual Basic generic constants should be grouped in a single module to separate them from application-specific declarations.

6. Native Code Compiler Switches

Native code compilation provides several options for optimizing and debugging that aren't available with p-code.

所有选项挨个解释一遍,略。

7. Adding Help to Your Application

(1) Visual Basic provides support for two different Help systems: the traditional Windows Help system (WinHelp), and the newer HTML Help.

(2) This appendix covers the steps necessary to add either WinHelp or HTML Help to your application, pointing out the few differences between the two where applicable. 略

(3) What it doesn't cover is how to author a Help file — there are numerous authoring tools available that can help you to do that.

抱歉!评论已关闭.