Naming Conventions

You may have noticed that all the examples covered so far prefixed each variable and object declaration with a two- or three-character prefix, such as the variable strTest in the prior figure. These prefixes are being used as a naming convention to provide a standardized way of naming objects and variables. Various types of naming conventions are in use today, and one may be just as good as the other.

Following some type of naming convention is a valuable practice. For example, if you name a variable with a prefix that indicates its data type, you do not have to weed through lines and lines of code looking for the place it was declared to see what data type it stores.

The following table illustrates some naming conventions that I like to use for my variables. Other conventions could also be used, as was mentioned previously.

Prefix

Data Type

Example

bln

Boolean

blnResult

byt

Byte

bytResponse

cur

Currency

curTotalSales

dt

Date

dtBirth

dbl

Double

dblGPA

int

Integer

intCount

lng

Long

lngTrackingNum

obj

Object

objControl

sng

Single

sngResult

Continued

Prefix

Data Type

Example

str

String

strMessage

typ

User-Defined Type

typExample

var

Variant

varOutput

The following table lists some naming conventions I like to use for objects. Some objects and variables are not listed in these naming convention tables, but these are the most common to give you the general idea.

Prefix

Object

Example

cls

Class Module

clsProject

frm

Form

frmMain

fsub

SubForm

fsubMainDetail

mcr

Macro

mcrAutoExec

mod

Module

modBusinessLogic

qry

Query

qryCalculateSales

rpt

Report

rptAnnualSales

rsub

Subreport

rsubAccountExecutives

tbl

Table

tblSales

0 0

Post a comment