http://lingobuddy.51.net/larry/index.php/2004/12/effective-visual-basic/Effective Visual Basic: How to Improve Your VB / COM Applicationsby Joe Hummel, Ted Pattison, Justin Gehtland, Doug Turnure, Brian A. Randell, Copyright © 2001isbn: 0-201-70476-5Http://www.developmentor.com
Visual Basic Efficient Programming: Improved VB / Com Application Simplified Chinese Copyright © 2003 by Pearson Education Asia Ltd. & Tsinghua University Press. Yan Jing Dong Guo Civilization and other translations and other translations of the TXT Southern Southern University of Technology 2003.12http: // www. Tup.com.cnisbn: 7-302-07701-0tp · 5639
Chapter 1 is converted from random programming to comply with software engineering principles.
# Name Rules: ## Type Prefix: c Custom Cable i Custom Interface T UDT
## Variable prefix: A array b Boole C currency col CollectionDB ADO Connectione Enum Variable I integer L Long Integer R Object Reference RS ADO RecordSets StringTxt TextBox Control U UDT Variety V Variant Variable
# 补 补: Module internal variable m_ module internal constant MC_ project global variable G_Bend Global Constant GC_PRIVATE Method / Property Prefix PFRIEND Method / Property Prefix F Engineering Group Name Prefix G
1.1 Rule 1-1: Maximize the potential of VB compile period type check
# It is best to make mistakes exposed in the compile period.
# Vb type check is weak
1.1.1 Using an Option Explicit statement at the top of each module
# No Use this option may make errors
1.1.2 Avoid unused use of Variant data types
# 不 指 指 类 变 变 为 为 为
# Suitable for using Variant: The field value read from the database; the class used by the script (VBScript only supports the call of the Byref mode)
1.1.3 When running in VB IDE, use the start with full compile command
# Tools | Options, General: Compile ON Demand
1.2 Rules 1-2: Explicitly declared assumption using debug.assert
# 假 假 包括 包括 外 假 (such as file presence) and internal assumptions, such as: DIM I as integer I = 0 to ubound (a) ...
# Note that different assumptions may appear during multiplayer, bring logic errors.
# 对 外 传 入 对 本 本 本 假........ 设............
# Debug.Assert helps test, integrate, and maintenance, find logic errors, should be retained and maintained in your code.
Outside # integrated environment can define your own Assert routine: Public Sub Assert (bCondition As Boolean, sMsg As String) #If ASSERT_OUTSIDE_IDE ThenIf Not bCondition ThenApp.LogEvent "Assertion failed:" & sMsgEnd If # End If # If ASSERT_INSIDE_IDE ThenIf Not bCondition Thendebug.Print "Assertion Failed:" & SMSGDebug.Assert Falsend IF # End IFEND SUB1.3 Rules 1-3: When the compile period is different, consider using a #IF statement
#If debug_x <> 0 or debug_all <> 0 THEN
# 优先 顺:: Project Properties dialog <- Module #const <- vb6.exe / make propj.vbp / d var = 1 command line parameters
# Mode: If there is only a small difference, use the conditional compilation to generate multiple versions may be too big.
1.4 Rules 1-4: Throw errors to prompt an abnormal
# Before throwing an error, pay attention to the status of the subroutine should be clear as possible, such as turning off ADO Connection, Recordset, etc.
1.5 Rules 1-5: Effective Error Handling: Partial Capture, Global Processing
# After calling the API function that may generate an error, you need to check the API error code.
# 全 全 处理 错 错 方案 Errhdl.rar
1.6 Rules 1-6: Understand the difference between type and class
# 类 类 多 多
# Note: Only UDT defined in the public class module can be stored in a Variant variable.
1.7 Rule 1-7: Object-oriented design method
1. Package: Pack the data and code into a class, map the status and behavior of the entities in the real world to the class's properties and methods. 2. Abstract: Extract the recurring code, increase the object's method, simplify the steps of the client to use the object to complete the task. 3. Data Hide: Hide the service class's implementation details, blocking service classes implement detailed changes to the customer program.
# Custom Customization You Iterate Class Procedure Attributes: ID = -4public function newum () as iUnknownset newunum = colitems. [_ Newenum] End Function
# Control the degree of abstraction and avoid excessive design. The principle is to consider whether the design is conveniently used by the customer's customer perspective.
1.8 Rules 1-8: It is recommended to use a user-defined type instead of a class to define value types
# Create a class object overhead. # The UDT can pass the value copy during cross-process call, and members of the accessed class will need to schedulize across the process. # So, when performing efficiency problems is important, use UDT to replace unnecessary classes as much as possible.
1.9 Rules 1-9: Automation of General Tasks
# Compile with NMAKE. The necessary part can be selected according to the dependency. Targets = c1.dll C2.dllvb = "pathtovb6.exe" args = / d dbug = 1
Component: $ (Targets)
C1.dll: c1.vbp class1.cls Class2.csl $ (vb) / make c1.vbp $ (args) ...
C2.dll: ...
.Suffixes: .vbp .frm .cls .bas
Clean: Regsvr32 / U / S $ (Targets) Del $ (Targets)
# Use WSH Object Model Set rScriptArgs = WScript.ArgumentsIf rScriptArgs.Count <> 1 ThenWScript.Echo "Usage: ..." WScript.Quit (1) End IfSet rFS = WScript.CreateObject ( "Scripting.FileSystemObject")
Set sshell = wscript.createObject ("wscript.shell") Rshell.Popuprshell.Run SVB & SC1 & SARGS, 0, TRUE
# You can combine MakeFile and WSH automation daily tasks.
# Create a project with VB6 IDE, reference Windows Script Host Object Model to use the Auto-Complete function help to write VBS scripts.