Active Server Developer's Journal

July 1999

Naming Your ASP Variables with VBScript

by Sarah Remelt

In VBScript, the only variable type available is the variant. However, in most cases, you'll want to store a specific data type in a variable. To help avoid errors, and to make your code easier to read and easier to debug when things aren't working correctly, it's good practice to use a naming convention for all your variables. There are several conventions to choose from, and Table A lists one of many approaches. The advantage of this naming convention is that the data type is clear from the naming convention.

Table A: Variable naming convention

Data Type Prefix Example VarType()
Boolean bln blnAccepted
11
Byte byt bytPixelValue
17
Date or Time dtm or dat dtmFirstTime
7
Double dbl dblTotalDistance
5
Error err errOverflow
10
Integer int intCount
2
Long lng lngFreeSpace
3
Object obj objListBox
9 or 13
Single sng sngLength
4
String str strAddress
8

The VarType function can be used to determine how a value is stored in a variant. The results for each of the variant types are shown in Table A.

This same type of naming convention is useful for controls, as well. Take a look at Table B; it shows a similar naming convention for controls.

Table B: Naming convention for controls

Control Type Prefix Example
Check Box chk chkFullPacksOnly
Combo List Box cbo cboThickness
Command Button cmd or btn cmdCalculate
Horizontal Scroll Bar hsb hsbWidth
Image Control img imgDisplayPicture
Label lbl lblDescription
List Box lst lstBrickTypes
Pop-up Menu mnu mnuSelection
Radio/Option Button opt optIncludeCement
Spin Button spn spnVolume
Tab Strip tab tabOptionPages
Text Box txt txtCustomer
Vertical Scroll Bar vsb vsbHeight
Notes As we mentioned previously, the variable naming convention is only one form of naming convention. If you have others you'd like to share, send them in to us at asp@zdjournals.com. Conclusion In this article, we showed you some useful naming conventions to help identify different variables and controls within your code. Hopefully you're able to use this information to help you avoid errors and make your code easier to understand.


Copyright © 1999, ZD Inc. All rights reserved. ZD Journals and the ZD Journals logo are trademarks of ZD Inc. Reproduction in whole or in part in any form or medium without express written permission of ZD Inc. is prohibited. All other product names and logos are trademarks or registered trademarks of their respective owners.