Quick References
ADO
ASP
CSS2
HTML
JavaScript
Jet SQL
VBScript
WML
WMLScript
WSH
XHTML
XML DOM
XSLT
Features
Knowledge Base
Tutorials
Partners
ZVON.ORG
XML
Planet Source Code
VisualBuilder
Web Design
Your HTML Source
XML/XSLT Forums
ASPAlliance
Scripts
Programmers Heaven
Tek-Tips Forums
Developer Fusion
Code Project
A100221: Recommended VBScript/VBA/VB Coding Guidelines.
Here are some easy-to-use guidelines that will make your VB/VBA/VBScript code look clean and professional.
Primary Headers
Each module of code should have a primary header block that:
Explains the overall purpose and serves as a general introduction to the code.
Lists the date it was created and gives the name of the programmers
Lists all dates it was modified, explains all modifications, and gives the names of the programmers.
Function and Subroutine Headers
Every function and subroutine should have a header block that:
Explains the specify purpose of the function or subroutine.
Lists the date it was created and gives the name of the programmers
Lists all dates it was modified, explains all modifications, and gives the names of the programmers.
ASP Headers
All ASP pages should include a header at the top detailing each mode of the page and the inputs the page expects in each mode (i.e. Form variables, QueryString variables, and Session variables).
Commenting
For VBA and VB, the body of the code should be well commented, including any tricky code, or hard-coded constants. However, comments in ASP pages need to be kept brief and to-the-point. Since ASP pages are interpreted at run-time, comments actually slow down their execution. It can be very useful to define and explain the purpose of each new variable as it is created.
For example:
'step thru email addresses from database
Do While Not rsEmailAddressList.EOF
Variable Naming Convention
Variable names should be prefixed with a letter code that indicates the type of the object. Additionally, the scope of non-local variables should be indicated by a single letter code that is a prefix to the type-string.
Standard codes are:
str
string
int
integer
lng
long
dtm
datetime
dbl
double
bln
Boolean
byt
byte
sng
single
obj
object
vnt
variant
usr
a user-defined type declared with the Type statement
rs
ADO Recordset
cnn
ADO Connection
a
array (append the type of array to this; e.g., adtm is an array of dates. For multi-dimensional arrays, append the number of dimensions, followed by the type of the array; e.g., a2str indicates a 2-d array of strings)
d
dictionary (append type of dictionary to this; e.g. dint is a dictionary that contains integers)
cl
collection (append type of collection to this; e.g. clstr is a collection of strings)
m_
indicates a Member-variable - a variable that is available to all methods in a class; e.g., m_intScore would be a member variable of type Integer
g_
indicates a global variable - is used in ASP pages or non-Class modules to indicate variables declared outside of all subs or functions
The type-prefix is all lower case letters. After the prefix, the variable name must use the proper case by capitalizing the first character of each word.
For example:
strDocumentName
g_intColumnCount
m_rsEmailAddresses
Function and Sub Naming Convention
Choose a name that explains the purpose of a function or sub. All names should use proper case where the first character of each word is upper case and the remaining characters are lower case.
For example:
GetCompanyAddress()
SendAskDevGuruEmail()
Option Explicit is Mandatory
Always use Option Explicit in all VBScript, VBA, and VB code. This will require you to declare all variables. This is traditionally placed at the top of the code.
Declaring Variables
When declaring variables in VBA or VB, give them an explicit type (if you know it). If you do not type variables, they will be defined as Variants. Processing the Variant data type adds additional overhead to many operations, so explicit typing is always preferred where possible. Note that explicit typing is not available in VBScript.
Indent
Always indent your code to reflect the block structure of the program. All conditional and loop blocks must be indented.
For example:
For Each intX In aintExxes
If intX = 5 Then
MsgBox "X=5 Please Click OK", vbOKCancel
End If
Next intX
Proper Case
Use proper case by capitalizing the first letter of each word for all VB keywords and statements.
The Guru
Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information
knoxville photographer
knoxville wedding photographer