Unformatted text preview:

Code SpecificationsCS 405 - Fall 2011 Introduction to VBThese specifications are given as a way to make your code more readable, which makes the code easier to review and modify later. They are rules that most, but not all, programmers follow. In addition to learning the Visual Basic language, learning the style of the language will make it easier in the future to work with other people’s code, and for other people to work with yours.Comments: A) Header – should conform to the following arrangement: ‘ Form (file): frmDemo (frmdemo.vb) ‘ Name: John Doe ‘ Assignment: #1 ‘ Due Date: 11/11/11 ‘ Description: One or more lines describing what the form/module does B) Function – each function should have a descriptive comment at the top (this should include a description of any arguments you pass to the function) C) General – any significant/unusual code should be commented (above or along side)Spacing: A) Indentation – should be consistent - declarations and code within a function should be indented one level - code within a control structure block should be indented another level, etc. B) Lines should not be longer than a printout can handle. Use the _ continuation character to continue on the next line (and indent each continuation line). Historically, code has been written to fit 80 columns on a screen or printout. Don’t go over this limit by too much, or your code will be difficult to read. C) Put a blank line, followed by a separator line, at the top of each procedure. ‘-------------------------------------------------------------------------------------‘ This is a comment explaining what the procedure doesPrivate Sub btnQuit_Click() ‘ first line of actual procedure (next line indented) Dim intCounter As Integer ‘ and so onEnd Sub‘-------------------------------------------------------------------------------------‘ This is a comment explaining what the procedure doesPrivate Sub btnClear_Click() ‘ first line of actual procedure (next line indented) Dim strName As String ‘ and so onEnd Sub D) If you declare more than two or three variables at the top of a procedure, consider separating them from the remaining code with a blank line. E) Remove any empty event procedures (skeletons) from your code - these usually are the result of accidentally double-clicking on a given control in Design View, even though you don’t intend to write code for the associated event procedure.Naming: A) Objects/Controls – use standard three-character prefix, followed by descriptive name: txtZipCode ‘ for a textbox intended to accept a user’s zipcode btnQuit ‘ for a button that allows the user to quit the form lblLastName ‘ for a label intended to display a last name B) Variables – use three-character prefix, followed by descriptive name: Dim intCounter As Integer Dim strName As String Dim dblSubTotal As Double Dim decEarnings As Decimal The above declarations are for local (function-level) variables. If are variable is module-level, it should start with the letter “m”: Private mintCounter As Integer Private mstrName As String Private mdblSubTotal As Double Private mdecEarnings As Decimal C) Constants – use all upper case. Because VB (internally) treats constants differently than variables, the scope issue is not as critical regarding constants. I recommend you place all your constant declarations at the top of each module (just before your module-level variable declarations). Const MAX As Integer = 100 Const COMPANYNAME As String = “Joe’s Pizza” D) Routines (Sub Procedures and Functions) – use <verb><object> as appropriate: CalculatePay ‘ function that calculates pay CheckData ‘ function that checks the validity of data Note: Always place Option Strict On at the top of each


View Full Document

UNH CS 405 - Code Specifications

Documents in this Course
Load more
Download Code Specifications
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Code Specifications and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Code Specifications 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?