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 entirely 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 (the tag) stand for the type of variable or object. For example, the following line creates an Integer variable named intMyVar, where int is short for integer:

Dim intMyVar as Integer

The tag (int) 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 4-2 summarizes the tags that you will most likely encounter when reading other people's code. In the Sample Declaration column of the table, Name means that you can put in any variable name you choose.

Table 4-2 Naming Conventions Used among VBA Programmers

Tag

Stands for This Data Type

Sample Declaration

byt

Byte

Dim

bytName

As

Byte

cur

Currency

Dim

curName

As

Currency

dtm

Date/Time

Dim

dtmName

As

Date

dbl

Double

Dim

dblName

As

Double

int

Integer

Dim

intName

As

Integer

lng

Long integer

Dim

lngName

As

Long

sng

Single

Dim

sngName

As

Single

bln

Boolean

Dim

blnName

As

Boolean

str

String

Dim

str Name

As

String

var

Variant

Dim

varName

As

Variant

0 0

Post a comment

  • Receive news updates via email from this site