Wyo Visual Basic Coding Standards
Wyo Coding Standards Home Page | VB Home Page
Use the following styles and standards in your Visual Basic programs. You may lose points on any assignment if you fail to adhere to these guidelines.
Coding
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, etc. statements for readability.
Line up inline comments where possible.
Add blank lines above and below loops and If statements. Also, add a blank line below a section of code that contains variable declarations (i.e. Dim statements) and below the comments at the top of each method. Add a blank line between methods.
Make sure that you provide a meaningful Text property 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 objects 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.
Constant & variable declaration statements should always appear at the top of a method. Global variables & constants must be declared in a code module. But you should never use global variables anyway.
Include the following information in the general declarations
section of every form in a project and the standard code module:
| Programmer Name Project Name Class Period Date |
' John Doe ' Unit1Proj1 ' Period 1 ' 9/9/08 |
|
|
Documentation
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. Remember comments are the main form of internal documentation. They should be explanatory but not too verbose (wordy). They should help explain the purpose of the program or procedure in which they are used. They should also explain the purpose of variables within specific algorithms. Always use correct spelling, punctuation, and grammar within comments.
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 declarations must be one per line and aligned consistently.
Follow the InterCap method for naming variables (e.g. intTotalPrice), making sure that the proper prefix (in lowercase letters) is used to identify a variable's data type or a function's return type. Programs must be "self-documenting." A program is self-documenting if its variable names imply the purposes of the variables. Variable names should be whole words or phrases that make refer to the purpose they serve within the program or function. Constants must be named with all-capital letters and underscores to separate consecutive words except for the data type prefix. For example, a module-level constant that identifies the maximum number might be named mintMAX_NUMBER.
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 obvious.
Turning-In Programming Assignments
Delete unused methods (i.e. methods that have no statements in their body.) Highlight the code in the code window and click the Delete key. The code should not appear on the final code printout. If it does, try it again.
Never fix code or add statements with a pen or pencil. You MUST make any necessary corrections on the computer and reprint the program.