Adding New Components to Your Project

Once you're ready to start coding, the first thing you'll need to do is add a component. For most of the examples in this book, you'll need to insert a module. To add a module to your project, select Insert ^ Module. If you have more than one workbook open, be sure you have the appropriate project selected in the Project Explorer first.


It is a good idea to name each component as you add it—especially forms and class modules— because chances are, other code you write will need to refer to these by name. If you change the name of a component later, any code that you've written that refers to the object by name will no longer function.

To name a component after you add it, select it in the Project Explorer (it will be selected for you by default right after you add it) and use the Properties window to change the value associated with the Name property. For modules, it is generally a good idea to give the module a name that indicates what kind of functionality the procedures in the module provide. If your module contains functionality to display an income statement, for example, you might want to name it IncomeStatement. The names that you use must begin with a letter and can't use spaces.

NOTE It used to be and, for some, still is the custom to use a convention that indicated what kind of component the object was/is. For example, modules were/are prefixed with something like "bas" (this is the file extension of Visual Basic files) such as baslncomeStatement. Igrew accustomed to this practice and, because old habits die hard, still practice it today (I'm on a 12-step program to quit, however). I must admit that I can't think of one benefit that this practice provides me. If you're in the habit of prefixing calls to procedures located in other modules using the form Your-OtherModuleName.SomeProcedure, then I suppose you may benefit marginally from knowing that YourOtherModuleName is a module and not a class module, form, or other object. I haven't seen many people use this form of referring to procedures in other modules, however.

NOTE Forms have traditionally been prefixed with frm such as frmLogin. Because forms are commonly referred to by name in other parts of your application, you may find this naming pattern beneficial.

0 0

Post a comment