Summary

You cannot avoid declaration in a Visual Basic application. It appears each time you add a control to a form, when you call a procedure, or when you use a variable. Proper use of declaration keeps your source code readable and consistent. This chapter included the following key topics:

  • Name variables using the Hungarian naming conventions, employing the scope and tag values listed in this chapter. When defining new Hungarian tags, avoid conflicts with existing combinations. Use the appropriate Public, Private, or Dim keyword to declare each variable. Always use an As clause for all variable declarations. Use Hungarian tags in VBScript as if you were using the appropriate As clause after each variable declaration.

  • Constants appear in all upper case with underscore characters between each significant word. Never declare a constant within a procedure; all constant definitions appear within the Declarations section of a module, using the Public or Private keyword. Use an As clause, or a type declaration character, for clarity.

  • User-defined types use an initial capital, mixed-case tag name, always ending with "Type." The elements of the type use standard local Hungarian names.

  • Enumerated data types use an initial capital, mixed-case tag name, always ending with "Enum." The elements are mixed case with an initial lower-case leader, a two-to-five character abbreviation of the data type.

  • Line labels use an initial capital, mixed-case name, with no underscore characters. Always place line labels on a line of their own.

  • Procedures appear in mixed case with an initial capital and no underscores. All arguments and return values require As clauses. Begin the declaration with the appropriate Public, Private, or Friend keyword, but never include the Static keyword.

  • Declare statements generally follow the naming rules for procedures, but for large, multi-programming-language projects, it may be best to follow the rules of the original DLL author.

  • User interface elements employ local Hungarian names.

  • Menu item names use a "cascading" form of Hungarian naming, where each menu item name is prefixed with the name of its parent menu.

  • Reuse module-level and local variable, procedure, constant, and line label names where functionality is similar. Remove unused code and objects. These steps will keep the Project Name Table small.

  • Avoid negative names for variables, constants, procedures, and other similar elements. That is, do not put the words "Not" or "No," or similar words in the element names.

  • There are exceptions to the naming guidelines for traditional variable, constant, user-defined type, declare, and procedure names, and for property-like class variables.

  • Do not use the DefType keywords. Always use Option Explicit as the first noncomment line of each module, page, or file in your source code. Never use Option Base. Rather, specify lower and upper bounds for all array declarations. Use Option Compare, Option Private Module, and compiler directives as needed.

  • Use type declaration characters with literals for data type coercion.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.79.63