VBScript Naming Convention

Some recommended prefixes for VBScript variables.

DataType  ShortPrefix Prefix Example

String      s          str   strFirstName
DateTime    t          dtm   dtmStart

Integer     i          int   intQuantity
Double      d          dbl   dblTolerance
Single                 sng   sngAverage
Long        l          lng   lngDistance
Byte                   byt   bytRasterData
Boolean     b          bln   blnFound

Array       a          arr   arrMyArray
Collection  c          col   colMyCollrction
Class                  cls   clsMyObject
Error                  err   errOrderNum
Object      o          obj   objCurrent

This is designed to generate variable names which are both short and descriptive. For example without a naming convention you might have variables called PartNumber, PartDescription, and Delivery_Date following this naming convention they would become intPart, strPart, dtmDelivery.

Try to avoid variable names which duplicate the prefix naming, i.e for a File System Object objFS makes more sense than objFSO (we already know its an object)

The prefix can also be abbreviated to a single digit e.g. sFirstName, iQuantity

All VBScript variables are variants meaning that a variable can contain a string or an integer number or a date etc, This makes it easy to write VBScript code but it can also be easy to lose track of which variable should contain which type of data.

“If I had to live my life again, I'd make the same mistakes, only sooner” ~ Tallulah Bankhead.


The Reddick VBA Naming Conventions (VBA not VBScript)

Copyright © SS64.com 1999-2017
Some rights reserved