Appendix B. Variable Naming Convention
Because variables are used to hold values, it makes sense to choose names for them that describe their purpose or what they contain. The bigger the project you are working on is, the more important it is to keep track of its variables. This appendix offers some things to keep in mind, including standards:
You'll want to keep your naming consistent. For example if you use
Cnt
as a variable in one part of the script andCount
in another when you are in fact dealing with the same data, you're very likely to introduce runtime errors by confusing the variables.It is useful to include the scope of a variable by prefixing it with
g
for global, orl
for local (to a subprocedure), such asgstrCompanyName
andlstrDepartmentName
.One of the best ways to organize variable names is to prefix all variable names you use with a shorthand representation of the data type that the variable will hold. The standard prefixes used to accomplish this are called Hungarian notation.
Following is a listing of data types and their associated Hungarian prefixes, complete with examples of use.
Data Type | Hungarian Prefix | Example | VarType() |
---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Following is a listing of control types and their associated Hungarian prefixes, complete with ...
Get VBScript Programmer's Reference, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.