Company Software Department VB Group code writing Interim Agreement probezy (paste)

Source: Internet
Author: User
Tags date exit error handling execution expression functions integer ole
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

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 box
Lwchk lwchkarchive Lightweight combo box
LWCBO Lwcbogerman
Lightweight command button
Lwcmd Month View
MVW Mvwperiod

MS Chart Ch chsalesbyregion

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 objects

Database Object Prefix Example

Container Con conreports

Database DB dbaccounts

DBEngine DBE Dbejet Document Doc Docsalesreport

Field FLD fldaddress
Group GRP grpfinance

Index IX Idxage

Parameter PRM Prmjobcode

QueryDef qry Qrysalesbyregion

Recordset Rec Recforecast

Relation rel Relemployeedept

TableDef TBD Tbdcustomers

User usr usrnew

Workspace wsp Wspmine


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.

'
'******************************************************

Public (Private) Function forexample (..... ............) As Long
'................................................

End Function
4. Error handling (undecided)

Add the following code to the main () function or the main form load process:

'******************************************************

'

' Open error log file, close 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

In the main form Exit function, add the following code:

'******************************************************
'
' Turn off error log files

'******************************************************

Close #intErrLogFileHandle

Add in a module:

'******************************************************

'
' Write error log

'
'******************************************************

Public Sub Writeerrlogfile (ByVal strsub As String, ByVal Strerr as String)

Print #intErrLogFileHandle, Date, Time, Strsub, Strerr

End Sub

In each procedure or custom function, the following system error trapping mechanism is used:

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.descriptio N

MsgBox "..... ", vbcritical

' Here's a memory resource recovery effort

End Function



Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.