This page details the programming standards that Software Africa
uses for Visual Basic code (including VBA code in Excel and Access),
the Form and Report design in Access, and Form design in Visual
Basic. Our examples on this web site follow these standards.
When programming for clients we deviate from these standards when
necesary, for example to design forms in the client's corporate
colours.
In most browsers, you can press Ctrl+F, or Edit >
Find, to search this page for keywords.
- Editor – Tab Width: 2, Require Variable Declaration ON
- Editor Format – Font = Fixedsys 9 pt.
- General – Show Grid 6 x 3 points
- Editor – Tab Width: 2, Require Variable Declaration
ON
- Editor Format – Font = Fixedsys 9 pt.
- General – Show Grid 60 x 60 twips
- Advanced – SDI Environment.
·
Use
Option Compare Text,
Option Explicit and
Option Base 1 at top of
all Modules and Forms. If you use something different, say why
·
Indention = 2
characters.
·
Comment freely.
Start long comments on line above item referred to, line up quote
(‘) with code below, end comment with colon (:). Put short
comments on same line, end in full stop (.). Put single space
after quote.
·
Use
FlagChanges to flag all
changed lines of code with your initials and the date.
Exception: New procedures have just the procedure line ending in
comment: ‘ New: <
FlagChanges flag> and no individual lines flagged.
·
Where changes are not
obvious, comment out old line and put new line below (both lines
flagged).
·
Start each procedure
(Sub or Function) with description that says what procedure does,
what parameters it takes (and permissible values for these), and
what it returns.
·
Leave a line blank
between all procedures, and where sensible in code.
·
Start each module
with description that says what module does, and then list changes
in reverse date order (newest at top) flagged by FlagChanges.
Use version number too if appropriate.
·
At top of one form
(typically Main.frm, if
there is one) list versions in reverse date order (newest at top)
and major changes to each version.
·
All significant
routines are to have at least standard error-trapping:
On
Error GoTo Err_
<Main body of code>
Exit_: DoCmd.Hourglass False '
Hourglass off (Access).
Exit Sub
Err_: ' General Error-Handling Routine:
MsgBox Error$, vbInformation, "Error in Sub <Procedure Name>"
Resume Exit_
Resume
- Use a prefix when naming these objects on forms:
Command Buttons – cmd
Labels – lbl
- Exception: Bound controls, e.g. Text Boxes – use same name
as bound field.
- Do not name a module with the same name as a procedure:
Later versions of Access have a bug that will cause an error if
you do this. Avoid this by typically naming modules in the
plural.
- Use type-declaration suffixes where these are available
because Visual Basic checks them for you. We only use prefixes
where suffixes are not available, i.e.
Prefix |
Suffix |
Variable
Type |
Examples |
|
% |
Integer index (type integer or
long) |
I%, Cnt% |
|
& |
Long Integer |
L& |
|
! |
Single (Real Number) |
MyPay! |
|
# |
Double (Real Number) |
Precise# |
|
@ |
Currency |
Cost@ |
x,y,z |
|
x, y and z coordinates of
points |
xPos, yTop |
f |
|
Boolean |
fFlag |
b |
|
Byte |
bFlags |
v |
|
Variant |
vAnyNo |
ti |
|
Time |
tiNow |
da |
|
Date |
daStart |
dt |
|
Date and Time combined in
Variant |
|
|
$ |
String |
Name1$ |
a |
|
Array (used at the beginning
of any other, e.g.) |
|
a |
$ |
String Array |
aNames$ |
c |
|
Collection |
|
From Microsoft Knowledge Base Article –
209187: “ACC2000: Reserved Words in Microsoft Access”
This article lists words and symbols
that you should not use
in field, object, and variable
names because they are "reserved words." Reserved words
have a specific meaning to Microsoft Access or to the Microsoft Jet
database engine. If you use a reserved word or symbol, you may
receive an error such as the following:
“The wizard was unable to preview your
report, possibly because a table needed by your report is
exclusively locked.”
For existing objects with names that
contain reserved words, you can avoid errors by surrounding the
object name with brackets ([ ]).
MORE INFORMATION
Because it is not practical to provide
a list of all reserved words, such as built-in function names or
Microsoft Access user-defined names, please check your product
documentation for additional reserved words. Note that if you set a
reference to a type library, an object library, or an ActiveX
control, that library's reserved words are also reserved words in
your database. For example, if you add an ActiveX control to a form,
a reference is set, and the names of the objects, methods, and
properties of that control become reserved words in your database.
Reserved Word List
(case insensitive!)
A:
ADD, ALL, Alphanumeric, ALTER, AND, ANY, Application, AS, ASC,
Assistant, AUTOINCREMENT, Avg.
B:
BETWEEN, BINARY, BIT, BOOLEAN, BY, BYTE.
C:
CHAR, CHARACTER, COLUMN, CompactDatabase, CONSTRAINT, Container,
Count, COUNTER, CREATE, CreateDatabase, CreateField, CreateGroup,
CreateIndex, CreateObject, CreateProperty, CreateRelation,
CreateTableDef, CreateUser, CreateWorkspace, CURRENCY, CurrentUser.
D:
DATABASE, DATE, DATETIME, DELETE, DESC, Description, DISALLOW,
DISTINCT, DISTINCTROW, Document, DOUBLE, DROP.
E:
Echo, Else, End, Eqv, Error, EXISTS, Exit.
F:
FALSE, Field, Fields, FillCache, FLOAT, FLOAT4, FLOAT8, FOREIGN,
Form, Forms, FROM, Full, FUNCTION.
G:
GENERAL, GetObject, GetOption, GotoPage, GROUP, GROUP BY, GUID.
H:
HAVING.
I:
Idle, IEEEDOUBLE, IEEESINGLE, If, IGNORE, Imp, IN, In, INDEX, Index,
Indexes, INNER, INSERT, InsertText, INT, INTEGER, INTEGER1,
INTEGER2, INTEGER4, INTO, IS, Is.
J:
JOIN.
K:
KEY.
L:
LastModified, LEFT, Level, Like, LOGICAL, LOGICAL1, LONG,
LONGBINARY, LONGTEXT
M:
Macro, Match, Max, Min, Mod, MEMO, Module, MONEY, Move.
N:
NAME, NewPassword, NO, Not, NULL, NUMBER, NUMERIC.
O:
Object, OLEOBJECT, OFF, ON, OpenRecordset, OPTION, OR, Or, ORDER,
Orientation, Outer, OWNERACCESS,
P:
Parameter, PARAMETERS, Partial, PERCENT, PIVOT, PRIMARY, PROCEDURE,
Property.
Q:
Queries, Query, Quit.
R:
REAL, Recalc, Recordset, REFERENCES, Refresh, RefreshLink,
RegisterDatabase, Relation, Repaint, RepairDatabase, Report,
Reports, Requery, RIGHT.
S:
SCREEN, SECTION, SELECT), SET, SetFocus, SetOption, SHORT, SINGLE,
SMALLINT, SOME, SQL, StDev, StDevP, STRING, Sum.
T:
TABLE, TableDef, TableDefs, TableID, TEXT, TIME, TIMESTAMP, TOP,
TRANSFORM, TRUE, Type.
U:
UNION, UNIQUE, UPDATE, User.
V:
VALUE, VALUES, Var, VarP, VARBINARY, VARCHAR.
W:
WHERE, WITH, Workspace.
X:
Xor.
Y:
Year, YES, YESNO
The
following symbols should not be used as part of a field name:
/ , *, :, !,
#, &, ?, ; ,
" , ' , $
- Form Size: To fit on a 14” screen with 1 menu, 1
toolbar, and vertical and horizontal scroll bars, form must not
exceed 21 cm wide by 13 cm high. This is not always possible.
Use Page breaks if the form is more than 13 cm high. Grid X = 5,
Grid Y = 10.
- Headings must have an 16-point Arial font and bold.
- Subheadings must use a 10-point Arial bold.
- Leftmost setting (minimum value of the "Left"
property for any control) on Forms with record selectors should
be 0.2 cm; on forms without record selectors it should be 0.5
cm.
- Text boxes and Combo boxes should have a height of
0.5 cm and have 0.1 cm vertical spacing between them and must
use a 10-point Arial font.
- Command Buttons should have a height of 0.7 cm with a
width of 2 cm which can increment by 0.5 cm depending on the
length of text required and also be spaced at 0.1 cm apart. Use
a 10-point Arial font.
- Labels must use a 10-point Arial font.
- Align horizontally on the nearest 0.2 cm.
- Vertically stacked groups of labels, text boxes, etc, should
have the same "Left" setting (set manually), and preferably the
same Width, which should be sized in increments of 1 cm whenever
possible.
- All text must be black or bright blue (Fore
Color=16711680) as decided for the project.
- Background colour must be Light blue (Back
Color=16777164).
- Margins: Aim for 2 cm all round. If essential, reduce
to 1.5 or even 1 cm.
- Size: Fit on A4 paper, portrait
orientation if possible: With 2 cm margins all round, width
should not exceed 16.8 cm. For Landscape orientation and 2 cm
margins all round, width should not exceed 25.8 cm.
-
Headings must have an 18-point Arial font and bold.
-
Subheadings must use a 10-point Arial bold.
-
Leftmost setting on Reports should be 0 cm.
-
Text boxes should have a height of 0.5 cm and have 0.1 cm
vertical spacing between them and must use a 10-point Arial
font.
- Labels must use a 10-point Arial font.
- All
text must be
black.
- Background colour must be white.
·
Always use a prefix
when naming objects:
Prefix |
Object Type |
Example |
cbo |
Combo box and drop down list
box |
cboLanguage |
chk |
Checkbox |
chkReadOnly |
cmd |
Command button |
cmdOk |
dir |
Directory list box |
dirSource |
dlg |
Common dialog control |
dlgFileOpen |
drv |
Drive list box |
drvTarget |
fil |
File list box |
filSource |
frm |
Form |
frmEntry |
fra |
Frame |
fraStyle |
grd |
Grid |
grdPrices |
img |
Image |
imgIcon |
lbl |
Label |
lblHelpMessage |
lin |
Line |
linVertical |
lst |
List box |
lstPolicyCodes |
mdi |
MDI child form |
mdiNote |
mnu |
Menu* |
mnuFileOpen |
opt |
Option Button |
optRed |
pic |
Picture |
picVGA |
spn |
Spin control |
spnPages |
txt |
Text Box |
txtLastName |
vsb |
Vertical scroll bar |
vsbRate |
hsb |
Horizontal scroll bar |
hsbVolume |
*Menu Items
– mnu, All menu Items should have an underlined letter.
Submenus should start with the prefix and first 4 letters of the
main menu name, e.g. mnuFile may contain mnuFileExit; mnuSetup may
contain mnuSetuOptions.
See also:
Excel Programming Primer,
Excel Spreadsheet Tips,
Microsoft Word Tips,
Microsoft Access Tips,
Maximizer Tips,
Tips on Windows and other Windows Programs,
Free Software for
Programmers.
|
|
|