Home
Username:
Password:
Microsoft Visual Basic 2005 Tutorials

Saving & Executing Projects / Naming Rules & Conventions

Subtitles of the Movie

In this movie we will discuss the naming rules for controls and some suggestions to make the process a lot easier. First, the names that you create for the controls must begin with a letter. They have to be all one word, that is no spaces embedded within the name themselves. you also need to avoid special symbols, one special symbol that is permittable is the underscore. You also will want to use Camel Casing. Camel Casing is not a requirement of the Visual Basic language but it is an industry standard that you should get used to using. You see on the screen some examples of Camel Casing, for example messageLabel. The word is spelled in all lower case with the exception of the first l in label. Another example is exitButton, all lower case capital B button is the only exception and so forth. We'll now take a look at some examples of controls being renamed within the Visual Basic environment. I've created a little program here a real form that simple shows some controls with some sample names. Whenever you place a control on the form by default it is given a name, for example, a button, the first button that is on a form is by default called Button 1. You can always determine that by looking in the properties window. The properties window can be sorted alphabetically or by category. I prefer to use the alphabetical list. Above the beginning of the alphabetical list is the name property. And there you will see Button 1, that is the default name for the control. Now, when you're creating applications you will want to create meaningful and descriptive names for your controls so that when you reference these in code they will have an automatic meaning. For example if a button's job is to calculate, you might want to call it Calculate Button. So to rename this Button 1 Calculate Button I simply go to the name property and overtop Button 1 simply type in Camel Casing format calculateButton, no spaces, all one word. Once that's done, the button on the form has been renamed to Calculate Button. Again, you can confirm this by clicking on the button and then looking at the name property. Likewise, for a check box, its default name is Check Box 1. If I wanted to rename a check box for example, maybe the user is supposed to check the check box if they're a new user then I might call it New User Check Box, so again, in Camel Casing I simply type newUserCheckbox. Now notice in all these examples that the name of the control is also embedded as part of the name of the control itself. For example, a check box has the word check box in the name, for example the label has the name label. If a label's purpose is to display the results of a calculation for example an appropriate name might be Display Results Label. A text box might be referred to as First Name Text Box. Again, the word text box is embedded as part of the name so that when you reference this in code you know immediately first what is the purpose of the control and also what type of control is it, that is is it a text box? Is it a label? What have you? And the last example given here is the items Combo Box. We'll talk later about combo boxes but a Combo Box is, allows you to keep a list so if you had a list of items you might call it Items Combo Box. Again, all these examples use Camel Casing, all one word, not spaces. It is important when you're designing your applications to create meaningful and specific names for your controls. In the long run it will make your programs easier to read, easier to work with, and easier to modify. One final comment about controls, if a control is never going to be referenced in code then it's okay to use the default name as its name. But if a control is going to be referenced in code in any way it is always best to create a new name for that control so that anyone reading the code knows exactly what that control is and what it is referencing.

Tutorial Information

Course: Microsoft Visual Basic 2005
Author: Arthur Lee
SKU: 33940
ISBN: 1-935320-10-6
Release Date: 2008-11-19
Duration: 7.5 hrs / 97 lessons
Work Files: Yes
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available