Microsoft Office 2000/Visual Basic Programmer's Guide |
At the application level, your code is contained in one or more standard modules or class modules and in modules behind forms, reports, or documents. You apply structure to your code at this level by organizing your code logically within these components in your application. Within any module, the procedures should have some relation to each other. For example, you could keep all data access code in a single module. Form, report, or document modules should contain only code that applies directly to the form, report, or document or to controls it contains. At the procedure level, applying a structure to the code means breaking up large procedures into smaller ones and using line breaks, white space, and indentation to organize and illustrate the logical structure of the code. Any general-purpose procedures called by code in these objects should be contained in a separate module. You should also add comments at the module level to provide information on the nature and purpose of the procedures contained in the module.
You should use these principles whether you are writing VBA code or script in an HTML page. You can think of an HTML page as being similar to a VBA application for the purposes of structuring your script. You can think of blocks of script within <SCRIPT> tags as being similar to VBA procedures contained in a module. The script and procedures used between <SCRIPT> tags should be related to other script within the same set of tags. Any general-purpose procedures called from the script in an HTML page should grouped together within their own pair of <SCRIPT> tags or kept in a scriptlet. For more information about creating and using scriptlets, see Chapter 12, "Using Web Technologies."