Naming Conventions in VB6


The Name property of a control is very important as it helps you identify the control in the code. Every control has the Name property. When you create a control, Visual Basic sets the default Name property like Text1, Command1, Form1 etc.  It is suggested to use some specific prefixes for the Name property especially when you'll use the controls in your code. This is a good programming habit to modify the name so that it expresses or identifies a particular control with the meaningful name. See the table below for the three-letter prefixes that you will use for the naming purpose.


Table: Standard three-letter prefixes for controls

Controls                                    Prefix  Controls                               Prefix 

CommandButton

cmd

Data

dat

TextBox

txt

HScrollBar

hsb

Label

lbl

VScrollBar

vsb

PictureBox

pic

DriveListBox

drv

OptionButton

opt

DirListBox

dir

CheckBox

chk

FileListBox

fil

ComboBox

cbo

Line

lin

ListBox

lst

Shape

shp

Timer

tmr

OLE

ole

Frame

fra

Form

frm

Image

img

Menu

mnu


Say there is a TextBox control that shows the result, set the Name property to txtResult, a meaningful name. There is no need to edit the Name properties of all the controls in your project because naming all the controls (if there are so many) is time consuming. Name those controls using the prefixes which you use in the code. If it is convenient to use the default Name properties for some controls, there's no need to rename using the prefixes. 


In fine, naming a control using a three-letter prefix is a good habit but only then when the particular control is used in the code and this naming convention will certainly increase the readability of your code, which is a great advantage.


Remember, there is no hard and fast naming rules. This is just a suggestion from Microsoft. In fact, this is your personal preference, you may prefix the name of a control in whatever way you want.