VB 6 For Beginners: Naming Objects
September 1, 2009-
Importance of Naming Objects.
An object’s name is one of its most important properties because you literally refer to each object by its name whenever you want it to do something. Names are so important that every time you create a form or put a control on your form, Visual Basic automatically gives a name to it. If you create a form Visual Basic names it Form1, if you add a CommandButton, Visual Basic names it Command1; if you add a TextBox, it’s automatically named Text1.
However, naming objects like this will soon cause confusion. Imagine if you are going to create a calculator application that requires more than 10 command buttons. Visual Basic will name them Command1, Command2, Command3, and so on. This will make it difficult for you to remember the names. This is especially true if your project is using multiple forms.
Each time you create a form or control, Visual Basic allows you to change its name on the properties window.
Figure 1. The Name Property/ Attribute
Object Naming Conventions.
Naming convention of objects is easy.
-
The name should start with a short abbreviation (usually three letters) that identifies the type of object or control. This will make it easy for you to identify what type of object it is.
-
Then a short descriptive name which starts with an uppercase (capital) letter. This will make it easy to know the function of that object / control.
-
The name should not have any spaces or special characters like, *, /, `, etc…
Examples:
-
If the command button is used to close the program, then the appropriate name is cmdClose.
-
If a text box is used to ask for the last name of a person then the name should be txtLastName or txtLName. (Take note how each word is emphasized by the uppercased first leter).
Caution! If you copy and paste to create controls of the same type, Visual Basic will try to create a control array for the original and copied objects.
When you see the pop-up below, click No. Control Array is very useful if you already understand how to use it, otherwise it will cause some confusion. Control Array will be discussed in another session.
Previous Comments
All comments are moderated. Your comments will not appear here unless approved by the blog owner. Thank you.









sir. parang kulang mn?
Posted by jaja at September 2, 2009, 8:29 pm