Coding Style Rules

It is important to write your code in a clear and organized fashion so other programmers can understand what you did and why you did it. Here are some rules you should follow whenever you develop an application in VBA:

  1. Use names for procedures and variables that make sense with respect to the problem.
  2. When declaring a procedure, always include its purpose as a comment.
  3. Definition names of variables and functions should use camel case Eg. LogBaseN rather than Log_Base_N or logbasen
  4. Don’t perform multiple tasks in a single line. As a result, no code line should span more than your screen width.
  5. Break long procedures into shorter, simpler procedures. No procedure should span more than ten to twenty lines.
  6. Avoid hard coding or embedding input or configuration data directly into the source code. For example, instead of saying x=10*y, define a new variable a=10 and say x=a*y.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.