Company Software Department VB Group code writing Interim Agreement probezy (paste)
SOURCE http://www.vbprobe.com
One, variables and objects
The variables in the program follow the Hungarian notation, "prefix + variable meaning", the meaning of the variable is one or more English words, the first letter of each word capitalized, do not use Hanyu Pinyin instead. The variable prefix is three lowercase letters indicating its type, and the prefix you need to add follows Microsoft's recommendation in MSDN. The list is as follows:
Basic data types
Example of a variable type prefix
Boolean bln BlnFound
Byte byt Bytrasterdata
Collection Object Col colwidgets
Currency cur currevenue
Date (time) DTM Dtmstart
Double Dbl dbltolerance
Error Err Errordernum
Integer int Intquantity
Long LNG lngdistance
Object obj objcurrent
Single SNG Sngaverage
String Str strFName
user-defined type UDT Udtemployee
Variant vnt Vntchecksum
control or form, module object
Example of a control type prefix
3D Panel PNL Pnlgroup
ADO Data ADO Adobiblio
Animated button ANI Animailbox
Check Box Chk chkreadonly
Combo box, drop-down list box CBO Cboenglish
Command button cmd cmdexit
Common Dialog Dlg Dlgfileopen
Communications com comfax
Control (variable of the type that is used in the procedure is not specified)
Ctr Ctrcurrent
In addition, add additional prefixes for variables of varying levels, for example:
Example of a level prefix
global variable G ty
For the data type defined by the user using the Type keyword, add u before the three-letter prefix. For example, a user-defined variable called a client type with a prefix of UCLI.
With regard to the use of variables, the recommendations are as follows:
1, the variable to be declared before use (in the form code in the first line plus option Explicit, to prevent undeclared variable calls, or in the menu Tools->options->editor select Require Variable Declaration items. )
2, try to use long variables to replace the integer type, this can reduce some data overflow errors, and on the Win32 platform, CPU processing 32 bits of data faster than 16-bit data.
3, as little as possible with variant variables, as far as possible to give each variable a clear type
4. Try not to use as any in the API declaration, and if you encounter the default parameter as any, declare the API function for each required parameter type, such as the default declaration of the ReadFile function:
Public Declare Function ReadFile Lib "kernel32" Alias "ReadFile" (ByVal hfile as Long, lpbuffer as any, ByVal nnumberofbyt Estoread as Long, lpnumberofbytesread as long, lpoverlapped as overlapped) as long
The members of the Panel shall change it to read:
Public Declare Function readfilebyt Lib "kernel32" Alias "ReadFile" (ByVal hfile as Long, lpbuffer as Byte, ByVal Nnumbero Fbytestoread as Long, lpnumberofbytesread as long, lpoverlapped as overlapped) as long
Public Declare Function readfileint Lib "kernel32" Alias "ReadFile" (ByVal hfile as Long, lpbuffer as Integer, ByVal Nnumb Erofbytestoread as Long, lpnumberofbytesread as long, lpoverlapped as overlapped) as long
Public Declare Function readfilelng Lib "kernel32" Alias "ReadFile" (ByVal hfile as Long, lpbuffer as long, ByVal Nnumbero Fbytestoread as Long, lpnumberofbytesread as long, lpoverlapped as overlapped) as long
5, do not convert the type of work to VB automatically to do, and use the following types of conversion functions
CBool (expression)
CByte (expression)
CCur (expression)
CDate (expression)
CDBL (expression)
CDEC (expression)
CINT (expression)
CLng (expression)
CSng (expression)
CSTR (expression)
CVar (expression)
Second, form layout
The layout of each control within the window is recommended as follows:
1. All controls adjacent to the top, bottom, left, and right four edges of the form are 120 twips away from the edge of the form
2, the spacing between the controls are: related controls 60 twips, not related controls 120 twips
3, Button control size recommended for the high 300 twips, 1200 twips, this is the operating system default button size
4, each control font recommended for the song Body fifth word
Third, the Code
1, the program to start the object
The program rate starts with the main () function (select Menu View->project Explorer, right click on the current item in the Project window, select Menu "...) Properties "->general, select Sub Main in the Startup Object dropdown box
2, code indentation and spacing
The code indent for each unit is a tab, and the unrelated code leaves a blank interval, for example:
Private Function Getmax (Byref lngarray () as long) as long
Getmax=0
Dim Lngmax as Long
Dim Lngcount as Long
For Lngcount =0 to Ubound (Lngarray)
If Lngarray (lngcount) >lngmax Then
Lngmax=lngarray (Lngcount)
End If
Next
End Function
3. Note Translation
The more detailed the program, the more careful the better. The following references must be translated.
Each variable declared in the program can be added with the best note translation, at least the variables used to compute or save the key data must be added to the annotation.
For each logical piece of code that implements a basic function, it is best to add a simple note to the line above it.
For each custom function, regardless of size must be added to the annotation, and the format of the note translation is as follows:
'******************************************************
'
Functions implemented by the function
' The meaning of parameter 1 of the function: XXXXX
' The meaning of parameter 2 of the function: XXXXX
'......
' function returns the error message represented by the value: XXXXX (the function as far as possible declared as a function, not declared as a sub,
' function with a return value of 0 for execution success, for other values to indicate execution failure.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.