VB code writes temporary agreement ------------------
I. Variables in the variables and object programs follow Hungarian representations, "prefix variable meanings", and variables the meaning of one or more English words, the first letter of each word, do not use Chinese Pinyin replacement. Variable prefixes For three lowercase letters, the prefix you want to follow, follow Microsoft's recommendations in MSDN.
The list is as follows: Basic Data Type:
Variable type Prefix Example Boolean bln blnFound Byte byt bytRasterData Collection 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 Control Type Prefix Sample 3D Panel Pnl Pnlgroup Ado Data Ado Adobiblio Animated Button Animailbox Check Box Chk ChkReadonly Combo Box,
cbo cboEnglish Command button cmd cmdExit Common dialog dlg dlgFileOpen Communications com comFax Control (type used in the process of unknown control variables) ctr ctrCurrent Data dat datBiblio Data-bound combo box dbcbo dbcboLanguage Data-bound grid dbgrd dbgrdQueryResult Data-bound list box dblst dblstJobType Data combo dbc dbcAuthor Data grid dgd dgdTitles Data list dbl dblPublisher Data repeater drp drpLocation Date picker dtp dtpPublished Directory list box dir dirSource Drive list box drv drvTarget File list box fil filSource Flat scroll bar fsb fsbMove Form frm frmEntry Frame fra fraLanguage Gauge gau gauStatus Graph gra graRevenue Grid grd grdPrices Hierarchical flexgrid flex flexOrders Horizontal scroll bar hsb hsbVolume Image img imgIcon Image combo imgcbo imgcboProduct ImageList ils ilsAllIcons Label lbl lblHelpMessage Lightweight check b ox lwchk lwchkArchive Lightweight combo box lwcbo lwcboGerman Lightweight command button lwcmd lwcmdRemove Lightweight frame lwfra lwfraSaveOptions Lightweight horizontal scroll bar lwhsb lwhsbVolume Lightweight list box lwlst lwlstCostCenters Lightweight option button lwopt lwoptIncomeLevel Lightweight text box lwtxt lwoptStreet Lightweight vertical scroll bar lwvsb lwvsbYear Line lin linVertical List box lst lstPolicyCodes ListView lvw lvwHeadings MAPI message mpm mpmSentMessage MAPI session mps mpsSession MCI mci mciVideo Menu mnu mnuFileOpen Month view mvw mvwPeriod MS Chart cht chtSalesbyRegion MS Flex grid
msg msgClients MS Tab mst mstFirst OLE container ole oleWorksheet Option button opt optGender Picture box pic picVGA Picture clip clp clpToolbar ProgressBar prg prgLoadFile Remote Data rd rdTitles RichTextBox rtf rtfReport Shape shp shpCircle Slider sld sldScale Spin spn spnPages StatusBar sta staDateTime SysInfo sys sysMonitor TabStrip tab tabOptions Text box txt txtLastName Timer tmr tmrAlarm Toolbar tlb tlbActions TreeView tre treOrganization UpDown upd updDirection Vertical scroll bar vsb vsbRate database object database object prefix exemplary Container con conReports database db dbAccounts DBEngine dbe dbeJet Document doc docSalesReport Field fld fldAddress Group grp grpFinance Index idx idxAge Parameter prm PRMJOBCODE Querydef Qry QrysalesbyRegion Recordset Rec Recforcast Relation Rel ReleMPloyeedEpt Table DEF TBD TBDCUSpace User USR USRNEW Workspace WSP Wspmine
In addition, there is also an additional prefix for some different levels of variables, for example: Level Prefix Example GlStruserName Module Class Variable M MblncalcinProgress Process Calcular Variable None DBLVELOCITY Data Types defined by the user using Type keywords, Add U before the prefix of three letters. For example: a user-defined variable called Client type, which is prefixed as UCLI.
With regard to variable use, it is recommended as follows: 1. Variables must first declare reuse (in the first line of form code plus Option Explicit, to prohibit calls of variables, or in menus Tools-> Options-> Editor Require Variable Declaration item.) 2, try to use the long-type variable instead of the Integer type, which can reduce some data overflow errors, and on the Win32 platform, the CPU handles 32-bit data faster than 16 bits. . 3, try to use a variant variable as much as possible to give each variable clear type. 4. Try not to use as any in the API declaration. If you encounter its default parameter as ANY, you need for each required parameter type declaration of the API function, e.g. ReadFile function default statement is: Public declare function ReadFile Lib "kernel32" Alias "ReadFile" (ByVal hFile as Long, lpBuffer as Any, ByVal nNumberOfBytesToRead as Long, lpNumberOfBytesRead as Long, lpOverlapped as OVERLAPPED ) As Long Panel members shall change it: Public Declare Function ReadFileByt Lib "kernel32" Alias "ReadFile" (ByVal hFile As Long, lpBuffer As Byte, ByVal nNumberOfBytesToRead 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 nNumberOfBytesToRead 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 NNumberofbyteread As Long, LpNumberofbytesRead As Long, LPOVERLAPPED As Overlapped AS LONG
5, do not hand over the type of conversion to VB automatic, use the following type conversion function. CBOOL (Expression) CCUR (Expression) CDEC (Expression) CDEC (Expression) CINT (Expression) CSNG (Expression) CSTR (Expression) CVAR (Expression) Second, the layout of various controls in the form layout form, the recommendations are as follows: 1. All adjacent to the form, lower, left, left and right boundary adjacent The control and the edge of the control are 120 缇. 2, the spacing between the various controls is: 60 相关 related controls, non-related controls 120 缇. 3, button control size is recommended to be 300 缇, 1200, this is also operating system The default button size 4, the font of each control is recommended for the Song 5th word. Third, the code 1, the launch target program of the program is unified from the main () function (select menu view-> Project Explorer, right click in the engineering window Current project, select menu "... Properties" -> General, select Sub Main in the Startup Object drop-down box 2, code indentation with spacing each unit code indent into a Tab, non-related 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 Function3, the more detailed comments, the more you do it, the better. The following should be added below. Each variable declared in the program can be added to the error, at least the variables used to operate or save critical data must be added. For each logical implementation of a few code, it is best to add simple index. For each custom function, no matter how the size must be added, and the format of the index is as follows: '*********************** **************************************** The function 'function of the function' function of the function "The meaning of the parameter 2 of the xxxxx 'function Meaning: XXXXX '...' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '********************************************************** ***** PUBLIC (Private) Function Forexample (......................) as long
'............................................
End function 4, error handling (undefined) Add the following code during main () function or main form LOAD: '********************** ***************************** The error log file is turned off in Form_unload () "***** ******************************************************************* DIM strExePath As String If Right (App.Path, 1) = "/" Then strExePath = App.Path Else strExePath = App.Path & "/" End If intErrLogFileHandle = FreeFile () Open strExePath "err.log" For Append Shared As InterrlogfileHandle
Add the following code in the main form exit function:
'********************************************************** ***** '' Close error log file '' ****************************************************** ******************
Close # InterrlogfileHandle
Add: '*************************************************** *********** '' Write Error Log '' **************************************** ***********************
Public Sub WriteerRlogfile (byval strsub as string, byval strs
Print #InterrlogfileHandle, Date, Time, Strsub, Strerr
End Sub
In each process or custom function, use the following system error capture mechanism: public function forexample (............) as long
ON Error Goto Funcerror
Forexample = true ...................................................
EXIT FUNCTION
Funcerror: Forexample = false WriteERRLOGFILE "Forexample", "Error number:" & Err.Number & ", Error Source:" & Err.Source & ", Error Description:" & Err.Description Msgbox ".........", vbcritical ' Memory resource recycling work
END FUNCTION