Difference between revisions of "Microsoft Access VBA Naming Conventions"

From database24
Jump to navigation Jump to search
(Replaced content with 'Category:VBA Category:Conventions == General == Please read the [http://wiki.vb24.net/index.php?title=Naming_Conventions vb24.net Article] about Naming Conventions.')
 
(9 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
[[Category:Conventions]]
 
[[Category:Conventions]]
 
== General ==
 
== General ==
As novice developer you usually define names for constants, variables and methods as they occur;
+
Please read the [http://wiki.vb24.net/index.php?title=Naming_Conventions vb24.net Article] about Naming Conventions.
you look at a problem, think of a function, add some parameters and that's it.
 
 
 
After a few years of coding—especially once you are forced to refactor some of your legacy
 
coding—you will realize that the code is hard to read; it somehow feels "inconsistent".
 
 
 
Also during normal development you will notice that you keep stumpling upon the same issues again
 
and again: you're trying to access variables, which are not accessible, you try to use a variable
 
for a text value and run in to an error as it has been defined for numbers: the list of little
 
annoyances which are implied when not sticking to consistent conventions is long—add your
 
favourite annoyance here.
 
 
 
The naming conventions depend on the language you are using, but for VBA it is common conviction
 
to use either the [http://www.xoc.net/standards/rvbanc.asp Reddick VBA Naming Conventions] or the
 
[http://en.wikipedia.org/wiki/Leszynski_naming_convention Leszynski VBA Naming Conventions], which
 
are both versions of the [http://en.wikipedia.org/wiki/Hungarian_notation Hungarian notation].
 
 
 
The main idea is to prefix everything with a tag which indicates the type of the variable.
 
 
 
 
 
== Tag ==
 
A tag is a usually three letter long lowercase mnemonic for the variable type. As there is not a
 
tag for every kind of variable, you sometimes need to "invent" a tag of your own. The usual steps
 
for finding an appropriate tag are:
 
 
 
# Take the name of the object type
 
# Remove all vowels from the name
 
# Take the first three letters
 
 
 
As soon as you found a tag you should consider the following questions too:
 
 
 
* Is the tag already taken by another object type?
 
* Does it phonetically sound like the object type?
 
 
 
If you should answer one of these questions with "yes", you should adjust the tag name accordingly.
 
 
 
=== Data Type ===
 
{| class="wikitable"
 
|+ align="bottom" | Tag: Data Type
 
! style="text-align:left;" | Data Type !! style="text-align:left;" | Tag
 
|-
 
| Boolean || bln
 
|-
 
| Integer || int
 
|-
 
| Long || lng
 
|-
 
| Single || sng
 
|-
 
| Double || dbl
 
|-
 
| Currency || cur
 
|-
 
| String || str
 
|-
 
| Variant || var
 
|-
 
| Type || typ
 
|}
 

Latest revision as of 16:26, 7 April 2011

General

Please read the vb24.net Article about Naming Conventions.