 |
Search
IT Courses |
|
|
|
|
|
|
|
|
|
|
|
IT
dart News Letter
|
Get
ITdart.com weekly headlines before it's published on our site! Subscribe
and receive the articles delivered to your inbox!
|
|
|
Coding conventions for VB5/VB6
Here are some useful coding conventions for VB5. Most of them are also applicable to other versions of VB.
Define all variables explicitly. Checking the Require Variable Declaration option under Tools - Options - Editor enforces this. Define variable-length arrays explicitly. (Visual Basic will not enforce this.) Always specify the upper and lower bounds in an array definition. Define consta nts, and use them in place of numbers in the code. Always use the ByVal and ByRef keywords in parameter lists. Use ByVal where you have a choice. Always use the Private keyword on functions and subroutines that are not exported from a module. Define the types of all variables and function and subroutine parameters explicitly. For example, use Dim nBufSize As Integer instead of Dim nBufSize, and use Function nGetChars(nBufSize As Integer) As Integer instead of Function nGetChars(nBufSize). Do not use implicit type suffixes (such as ! and &) in variable definitions. In For loops, use Next instead of just Next. Object Naming Conventions
The base objects which are inserted on forms are automatically prefixed. If you have modified these base controls into your own ActiveX controls, you should also follow similar conventions.
Here are a few examples: Control Prefix Example 3d panel pnl pnlMain Check Box chk chkMarried TextBox txt txtName As these names are automatically suggested when you create a control on a form, it is easy to follow these. However when you create database objects, it is manually coded. Here is a list of suggested naming conventions for data objects:
Database object Prefix Container con Database db DBEngine dbe Field fld Group grp Index idx Parameter prm Query qry Recordset rec Relation rel Tabledef tbd Workspace wrk
These conventions may sound elementary and obvious. However, naming conventions are easier to list than follow. In practice, unless every developer is committed to the code quality, readability and maintainability, these conventions are very difficult to implement on a long-term basis.
Unfortunately, a lack of conventions does not produce any syntax errors. Therefore, it is necessary to have personal and QA control over appropriate usage of such coding conventions.
|
|
|