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 |
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.