Microsoft Office Tutorials and References
In Depth Information
Chapter 3: Writing Smarter Code
Following naming conventions for variables
Some programmers use naming conventions to identify the data type of a
variable as part of the variable’s or constant’s name. The naming
conventions are optional; you don’t have to use them. A lot of VBA programmers
follow them, though, so you’re likely to see them in any code you happen to
come across.
The idea behind a naming convention is simple. When you define a new
variable, make the first three letters of the name (referred to as the tag) stand
for the type of variable or object. The following line creates an Integer
variable named intMyVar, where int is short for integer:
Dim intMyVar As Integer
The tag added to the front of the name doesn’t affect how the variable is
stored or how you can use it. The tag serves only as a reminder that MyVar
is an Integer.
Table 3-1 summarizes the tags that you’ll most likely encounter when
reading other people’s code. In the Sample Declaration column of the table, the
italicized word Name means that you can use any variable name of your own
choosing.
Table 3-1
Naming Conventions Used among VBA Programmers
Tag
Stands For
Sample Declaration
Boolean data type
bln
Dim bln Name As Boolean
Byte data type
byt
Dim byt Name As Byte
cur
Currency data type
Dim cur Name As Currency
dbl
Double data type
Dim dbl Name As Double
dtm
Date/Time data type
Dim dtm Name As Date
int
Integer data type
Dim int Name As Integer
lng
Long Integer data type
Dim lng Name As Long
sng
Single data type
Dim sng Name As Single
String data type
str
Dim str Name As String
Variant data type
var
Dim var Name As Variant
Search JabSto ::




Custom Search