Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable Naming Conventions... Avoid the Pit Falls.

Office / VBA General

Variable Naming Conventions... Avoid the Pit Falls.

by  SQLBI  Posted    (Edited  )
Many posts on Tek-tips are solved by one helpful member pointing out that the reason a chunk of coded doesn't work is that a RESERVED WORD has been used to define a variable name.

This problem can be avoided and thus save loads of debugging time by adopting simple naming conventions for variables defined at runtime.

By using a 3 letter prefix to all variables created, you can be relatively certain that the reason your code won't run, is not because you've used a reserved word.

I use the following conventions;

Code:
DataType     Prefix     Result

Byte         byt        bytVarName
Integer      int        intVarName
Long         lng        lngVarName
Single       sng        sngVarName
Double       dbl        dblVarName
String       str        strVarName
Boolean      bol        bolVarName

Not only does this prevent the use of a reserved word, but when you are debugging, you can tell at a glance what data type your variable is, without having to trawl through line after line until you find the Dim statement.

Hope this helps.







Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top