PRG 140 Visual Basic Coding Standards
Use the following styles and standards in your Visual Basic programs. You may lose points on any assignment if you fail to adhere to any of these guidelines. Use the textbook as an example to properly documented code but if there is a difference between these standards and any of the textbook's examples, follow these guidelines.
Type blank spaces around operators of all kinds.
Example: Instead of intSum=intAmount+intSum
use intSum = intAmount + intSum
since it is much easier to read
Use consistent indentation, especially with regard to complex structures like if statements, loops, etc. Do not indent the lines in the general declarations section of a form or code module. Indent all lines inside If/Then/Else, With/End With, For/Next, Do/Loop, Select Case, Type/End Type, etc. structures for readability.
Make sure that you name each form and provide a Caption to each form.
Follow the Windows standards, especially in relation to color, size, and placement of controls. Also, use access keys that are considered standard in Windows software (e.g. x for Exit and s for Save). Do not give two controls the same access key.
Make sure that the focus is on the correct object when a form displays. The tab order must proceed correctly when the user presses the Tab key.
Line up inline comments when they appear to the right of executable code.
If a procedure contains several major steps or functional parts, there should be comments (called signpost comments) separating the function into each major part.
Variable declarations and descriptive inline comments must be one per line and aligned consistently where possible.
Statements which are continued on a second line must be indented significantly (more than the normal indentation). You may have to use the line continuation operator ([space]_ ). Make sure that long statements do not wrap around to the next line when printed.
Add blank lines above and below structures such as loops and multiple line if statements.
You must use the standard Visual Basic prefixes when naming objects:
Include the following information at the very top of the general
declarations section of every form in a project and the standard code module.
This is called a header.
' John Doe
Use a consistent format with regard to internal documentation. If you use complete sentences in inline comments, then do so throughout your program's code, otherwise use explanatory, understandable phrases.
Always include a variable dictionary to explain the purpose of each variable. That is, there should be an inline comment to the right of each variable declaration (Dim statement) and constant declaration (Const statement) that explains the purpose of the variable or constant. You can use phrases instead of complete sentences. Line up the inline comments vertically as much as possible.
Variable names (and other identifiers) must be self-documenting. That is, variable names should be whole words or phrases that make refer to the purpose they serve within the program or function. Follow the VB conventions with regard to prefixes for variables based on data type and scope. Follow the InterCap method and other naming conventions specified by our textbook for naming variables, constants, objects, and procedures. Use all uppercase letters in the names of constants, except for the prefix. For example, msngTAX_RATE would be an appropriate name of a module-level constant.
Annotate medium to complex algorithms and assignment statements
with inline comments. Do not necessarily assume that fellow programmers
(or instructors) will understand your logic. However, do not document the
If (intSum > 100) Then
lblOutput.Caption = "The sum is greater than 100."
If (intSum > 100) Then lblOutput.Caption = "The sum is greater than 100."
Turning-In Programming Assignments
Delete empty procedures.
Order the code on top of the form image for each form. Staple the pages together unless you use a three-ring folder or a "plastic sleeve" folder.
Never fix code or add statements with a pen or pencil. You MUST make any necessary corrections on the computer and reprint the program.
Local variable declaration (Dim) statements should always appear at the top of a procedure. Module-level and global variables must appear in the general declarations section of a form or module. Declare all variables with the most appropriate data types and level of scope.
Always use the Option Explicit statement in the general declarations section of every form and module. Blank lines should be placed around this statement and it should be placed after the header but before any module-level declarations.
Use perfect spelling and grammar throughout your code, especially where it is viewed by a user.
Name general function procedures with prefixes that indicate the return type of the function.