You are on page 1of 13

Cc chun mc lp trnh VB6

V i Lng - 09T1

K THUT LP TRNH VB
Cc chun mc lp trnh VB6

Tp hun VB6 Nhm 09T Lu hnh ni b

Cc chun mc lp trnh VB6

V i Lng - 09T1

1. Tiu chun vit m lnh - Coding conventions


1.1. Tn i tng
Tn i tng gm 2 phn: tin t v m t
Cc tin t lm cho chng ta d dng xc nh cc loi i tng, m t cp n tn ca
i tng.
- Quy c ca phn m t l:
+ Nn vit bng ting Anh.
+ C th cha nhiu t, mi t c tip gip vi nhng t khc (khng c du gch
ngang - ).
+ Khng c t vit tt tr cc t c lit k trong bng t vit tt.
+ Vit hoa ch ci u tin ca mi t.
(Lu : Cc quy c ny s c p dng cho tt c cc loi tn c cp sau trong
ti liu ny)
- Quy c Tin t cho mt s i tng c h tr bi Visual Basic c lit k di
y (sp xp theo tn kim sot):
i tng

Tin t

V d

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 (used within procedures when


ctr
the specific type is unknown)

ctrCurrent

Data

dat

datBiblio

Data-bound combo box

dbcbo

dbcboLanguage

Data-bound grid

dbgrd

dbgrdQueryResult

Tp hun VB6 Nhm 09T Lu hnh ni b

Cc chun mc lp trnh VB6

V i Lng - 09T1

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

lwcmdRemove

Lightweight frame

lwfra

lwfraSaveOptions

Tp hun VB6 Nhm 09T Lu hnh ni b

Cc chun mc lp trnh VB6

V i Lng - 09T1

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

ch

chSalesbyRegion

MS Flex grid

mfg

mfgClients

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

Tp hun VB6 Nhm 09T Lu hnh ni b

Cc chun mc lp trnh VB6

V i Lng - 09T1

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

1.2. Tin t cho Menu


Tin t iu khin menu s c m rng vt ra ngoi nhn hiu ban u "mnu" bng cch
thm mt tin t b sung i vi tng mc , vi ch thch n cui cng vo cui ca
chui tn. Bng sau y lit k mt s v d.
Chui tn nhn menu

Tn menu

File Open

mnuFileOpen

File Send Email

mnuFileSendEmail

File Send Fax

mnuFileSendFax

Format Character

mnuFormatCharacter

Help Contents

mnuHelpContents

1.3. Tn bin
Tn bin phi m t kiu d liu, phm vi v nhn dng ca mt bin.
Kiu d liu

Tin t

Boolean

bln

Byte

byt

Currency

cur

Tp hun VB6 Nhm 09T Lu hnh ni b

Cc chun mc lp trnh VB6

V i Lng - 09T1

Date (Time)

dtm

Double

dbl

Error

err

Integer

int

Long

lng

Object

obj

Single

sng

String

str

User-defined type

udt

Variant

vnt

1.4. Tin t bin phm vi


Phm vi

Tin t

V d

Lu

Global

gstrUserName

Bin string ton cc

Module-level

mblnCalcInProgress

Bin boolean trong module

Local to procedure

None

dblVelocity

Bin double cc b

1.5. Tn hng
Tn hng c vit in hoa vi du gch di gia cc t. V d: USER_LIST_MAX, NEW_LINE
1.6. Tin t cho ActiveX Data Objects (ADO)
S dng cc tin t sau y ch ra cc ActiveX Data Objects.
ADO object

Tin t

V d

Command

Cm

cmTitles

Connection

Cn

cnTitles

Field

Fld

fldName

Field Collection

flds

fldsTitles

Parameter

prm

prmTitleName

Parameter Collection

prms

prmsNames

Tp hun VB6 Nhm 09T Lu hnh ni b

Cc chun mc lp trnh VB6

Recordset

V i Lng - 09T1

Rs

rsTitles

1.7. Chun cu trc m lnh


Ngoi cc quy c t tn, ta cn chun cu trc m lnh, chng hn nh canh m cho cc
ghi ch v nht qun, rt c th ci thin kh nng c m.
1.8. nh dng code ca bn
Di y l mt vi gi :
- Tiu chun, khi tab, khi lng nhau nn c tht vo 4 khong trng (nh l mc nh
Visual Basic).
- Cc nhn xt tng quan chc nng ca mt th tc nn c tht vo mt khong
trng. Cc bo co mc cao nht theo nhng nhn xt tng quan nn c tht vo mt
tab, vi mi khi lng nhau tht vo mt tab mi. V d:
'*****************************************************
' Purpose:
Locates the first occurrence of a
'
specified user in the UserList array.
' Inputs:
'
strUserList():
the list of users to be searched.
'
strTargetUser:
the name of the user to search for.
' Returns:
The index of the first occurrence of the
'
rsTargetUser in the rasUserList array.
'
If target user is not found, return -1.
'*****************************************************
Function FindUser (strUserList() As String, strTargetUser As _
String)As Integer
Dim inti As Integer
' Loop counter.
Dim blnFound As Integer
' Target found flag.
intFindUser = -1
inti = 0
While inti <= Ubound(strUserList) and Not blnFound
If strUserList(inti) = strTargetUser Then
blnFound = True
intFindUser = inti
End If
Wend
End Function

1.9. Phn nhm hng s


Nhng hng s trong Visual Basic ni chung c nhm li trong 1 module ngn cch chng
vi cc ng dng c th.
1.10. Ton t & v +
Lun lun s dng ton t & khi lin kt chui v cc ton t + khi lm vic vi cc gi tr s.
S dng ton t + ni c th gy ra mt s vn khi hot ng trn hai bin variant. V
d:
vntVar1 = "10.01"
Tp hun VB6 Nhm 09T Lu hnh ni b

Cc chun mc lp trnh VB6

vntVar2 = 11
vntResult = vntVar1 + vntVar2
vntResult = vntVar1 & vntVar2

V i Lng - 09T1

'vntResult = 21.01
'vntResult = 10.0111

1.11. To Strings cho MsgBox, InputBox, v truy vn SQL


Khi to mt chui di, s dng du gch di _ to ra nhiu dng m bn c th c
hoc g li chui mt cch d dng. K thut ny c bit hu ch khi hin th mt hp thng
bo (MsgBox) hoc u vo hp (InputBox) hoc khi to ra mt chui SQL. V d:
Dim Msg As String
Msg = "This is a paragraph that will be " _
& "in a message box. The text is" _
& " broken into several lines of code" _
& " in the source code, making it easier" _
& " for the programmer to read and debug."
MsgBox Msg
Dim QRY As String
QRY = "SELECT *" _
& " FROM Titles" _
& " WHERE [Year Published] > 1988"
TitlesQry.SQL = QRY

1.12. Cc tiu chun khc


By li trong qu trnh pht trin code phi tun theo cc quy tc sau:
- By li xp tng: iu c ngha l tt c cc chc nng c gi s tr li m li h
thng, v hin th hp thng bo s c thc hin bn ngoi chc nng / th tc.
- Tt c cc h thng tin nhn s c t trong tp tin ti nguyn.
- Hin hp thng bo c thc hin bi cc thng s vt qua mt hin th tin nhn
hm ton cc.
- M li cha 3 s.
- nh phin bn cho tt c cc m-un: m-un hnh thc, m-un m ...
- Gii php hin th: 800x600 pixels
- Ci t c ch: phng ch ln
- Tt c cc tn file (*. vbp, *. frm, *. bas ...) phi t hn 3 k t.
- M li = 0 l OK.
- M li < 0 l li.
- M li > 0 l cnh bo.
- Tn hm nn bt u vi mt ng t, chng hn nh InitNameArray hoc CloseDialog.

Tp hun VB6 Nhm 09T Lu hnh ni b

Cc chun mc lp trnh VB6

V i Lng - 09T1

2. Tiu chun thit k biu mu - Form design standard


2.1. Cc tiu chun chung
Mc

Chun

Ghi ch

Interface

In Vietnamese

Font name

MS Sans serif

Font size

Default

Font color

Black

Default

Font style

Normal

Default

Distance between command buttons

100 Points

Command buttons alignment

Right

Label alignment

Left

Default

All labels in a form must be collected in an array


All command buttons in a form must have same width
Caption of OK button

Chp nhn

Caption of Cancel button

Thot

Caption of Help button

Hng dn

Caption of Add button

Thm mi

Caption of Delete button

Xo

Caption of Edit button

Sa

Caption of Close button

ng

Caption of Save button

Ghi

Order of buttons in from (Left to right):


Thm mi-Ghi-Sa-Xo-Chp nhn-Thot-H-ng dn
Default button

Chp nhn

Cancel button

ng

Tp hun VB6 Nhm 09T Lu hnh ni b

Cc chun mc lp trnh VB6

V i Lng - 09T1

2.2. V d
Form di y c thit k ng theo quy chun

Control

Property

Value

Check box

All colors

Default

Height

315

All colors

Default

Height

375 Points

Back color

Button face

Border style

Fixed length

Back color

Button face

Startup position

CenterScreen

Label

Back color

Button face

Vervical scroll bar

Width

260 Points

Horizontal scroll bar

Height

260 Points

Option button

Height

255 Points

Height

285 Points

All color

Default

Note

Combo box, drop-down list box

Command button

Form

VB Default

VB Default

VB Default

Text box

Tp hun VB6 Nhm 09T Lu hnh ni b

10

Cc chun mc lp trnh VB6

V i Lng - 09T1

3. Tiu chun kt xut bo co - Report design standard (Crystal Report)


3.1. Cc tiu chun chung
Mc

Chun

Above of each total row must be a line, called


Grouping line
Report boder

Only title row is bordered

Colour of all objects in report (line, character...)

Black

3.2. Tiu chun hnh thc i tng bo co


i tng

Report
title

Thuc tnh

Ci t

Font name

.VnArialH

Font style

Bold

Justify

Paper center

Space between report 50 Points


title
and
collumn
heading

Colunm
heading

Report
body
(data)

Font name

.VnArialNarrow

Font style

Bold

Font size

10

Justify

Column left

Before row spacing

6 Points

After row spacing

6 Points

Font name

.VnArialNarrow

Font style

Bold

Font size

Justify

Depend on column data type


(Number: right, string: right,
date: center)

Tp hun VB6 Nhm 09T Lu hnh ni b

Ghi ch

Should
be
reviewed

11

Cc chun mc lp trnh VB6

V i Lng - 09T1

Row spacing

Font name

.VnArialNarrow

Font style

Bold

Font size

Justify

Right

Position

Under
data
summarized

Grouping
line

Width

1 Point

Report
boder

Width

1 Point

Total row

Page
number

Left sub
title

Right sub
title

block

that

Boder column title only


Font name

.VnArial

Font size

Font style

Normal

Position

Right, bottom of page (Report


footer)

Style

Page/Total page

Font name

.VnArial

Font size

10

Font style

Normal

Justify

Margin left

Font name

.VnArial

Font size

10

Font style

Normal

V d:

Tp hun VB6 Nhm 09T Lu hnh ni b

12

Cc chun mc lp trnh VB6

V i Lng - 09T1

Left subtitle

Report title

Right subtitle

Column heading 1

Column heading 2

Column heading 3

Column heading 4

Report body 1

Report body 2

Report body 3

Report body 4

Report body 1

Report body 2

Report body 3

Report body 4

Total row 4
Report body 1

Report body 2

Report body 3

Report body 4

Report body 1

Report body 2

Report body 3

Report body 4

Total row 4
(Page number) 1/5

4. Tiu chun thit k c s d liu


Tt c cc tn i tng (bao gm: cc tn bng, tn xem, tn trng ...) trong c s d liu
phi tun theo cc quy c:
- Vit trong ting Anh.
- Cha mt hoc nhiu hn 1 t v khng c gch di gia nhng t ny.
- Khng vit tt ngoi tr danh sch c lit k trong bng t vit tt di y
- Ch ci u tin ca mi t phi c vit hoa.

Tp hun VB6 Nhm 09T Lu hnh ni b

13

You might also like