It is a good programming practice to follow certain style so that the code:
- is fully legible
- is easily followed and has logical structure
- contains general information such as name, date, software name and version, project details, etc.
- contains useful comments
- indented where needed
An example of the general details can be as follows:
' Name: John Smith
' Date: 01 FEB 2013
' Software: Visual Basic – 2010 Express
' Project: Total
' Object: frmTotal
' Version: 1
' Notes: This program is for calculation of sum of two numbers
' ------------------------------------------------------------------------------------------------------
In Visual Basic programming, the symbol ( ' ) is used for adding comments. Comments can be included in two ways, the first method as heading, secondly as a brief note by each line. Comments should be added freely in order to help tracing the objectives of the program. This becomes more important if it is needed to be referred back to the program after a certain period for further works or another programmer is required to carry out further development work.
' The following section is for Comments as heading
' defining two variables
' input by the user and the result
Dim X As Integer
Dim Y As Integer
Dim Z As Integer . . .
Z = X + Y ' calculate the sum of two numbers Comments next to a line . .
It is essential to use indentation wherever is required. The number of spaces used for indentation is up to the programmer. The size of the indentation should not be small in order to be able clearly see the section of the code indented, and not too large to avoid unnecessary scrolling to the left and right. As a guideline, four spaces is sufficient for indentation. The TAB key can also be used for indentation, but may not appear the same when printed. The other main areas are when IF blocks and LOOPS