Quick Find: Search for:
Total Visual CodeTools  

Microsoft Access 2007 Version
Is Shipping!


Supports Office/Access 2007, 2003, 2002, 2000, and Visual Basic 6.0!

Also available for:
Access 97


View all FMS products for Microsoft Access All Access Products

 CodeTools Info

PDF Fact Sheet (409K)

Product Guide

Take a Tour

Code Builders

Sample Code Cleanup

Sample Code Delivery

Unused Variable Analysis

Macro Recorder

Coding Standards

FAQs

Download Trial of Total Visual CodeTools for VB6 and VBA/Office/Access


Best Visual Basic Add-In
Rave Reviews

 Why CodeTools?

for Developers

for the Enterprise

Convince Your Boss

 More Info:

Check for Updates

License Terms

 

"Total Visual CodeTools is by far my favorite third-party product."
- Alison Balter, Author, Conference Speaker, Instructor

More Reviews
 

 

 

Code Cleanup: Before and After

Nothing is worse than inheriting someone else's code which uses a different indentation style, no naming convention, etc. Often, it's incredibly difficult to read which makes fixing problems or adding features more challenging than it should be. Fortunately, the Code Cleanup feature of Total Visual CodeTools lets you clean up existing VB6 and VBA code so that its more readable and improved. Whether its simply adding Option Explicit to modules that lack it so you can get a compiled state, or adding error handling to every procedure that lacks it, Total Visual CodeTools will help you enhance your application quickly and consistently.

Here are some of the Code Cleanup options:
  • Cleanup formatting styles
    • Standardize line indentations
    • Indent loops like If..End If, Do..Loop, etc.
    • Separate multiple variable declarations (Dim) on one line into individual lines
    • Convert single line IF statements to multiple lines with End If
    • Break up colon separated lines
    • Set number of blank lines between procs
    • Eliminate consecutive blank lines
    • Sort procedures alphabetically and/or by scope (Public vs. Private), etc.
  • Add Option Explicit to modules that lack it
  • Add module level comments with procedure list
  • Add procedure comments with parameter listing
  • Add error handling to procedures that lack it
  • Apply variable naming conventions
  • Remove line numbers


Code Cleanup Options

Code Cleanup can be applied to your current procedure, current module, a subset of modules, or everything in your project. Select the objects, set the options, then launch it. You can preview the changes before replacing your code.


Before Cleanup

Here's an example of code in module modUtilities before it's cleaned up. You'll notice the lack of consistency with indentations, spacing, variable naming, etc.

Function AddRows(CustId As Long, retval As Integer) As Boolean

Dim Northwind As DAO.Database
Dim Customers As DAO.Recordset
Dim LastName1, LastName2, LastName3 As String

  LastName1 = "Jones"
  LastName2 = "Smith"
   LastName3 = "Gates"

Set Northwind = DBEngine.Workspaces(0).OpenDatabase("c:\nwind.mdb")
  Set Customers = Northwind.OpenRecordset("customers")
  Customers.FindFirst ("CustomerID=" & CustId)

If Customers.Fields(0).Value = LastName1 Then AddRows = True



Select Case Customers.Fields(1).Value
Case 1: retval = 12
                Case 2: retval = 13
                 Case 3: retval = 14
   End Select

 Customers.Close
Northwind.Close
Set Northwind = Nothing

End Function


Function NullConverter(inValue As Variant) As Variant
If IsNull(inValue) Then NullConverter = "" Else NullConverter = inValue

End Function

After Cleanup

The text in yellow explains what changed:

Add your module comment structure with a complete procedure list:
' Module     : modUtilities
' Description:
' Procedures : AddRows(plngCustId As Long, pintRetval As Integer) As Boolean
'              NullConverter(pvarInValue As Variant) As Variant
' Modified   :
' 05/23 LC Cleaned with Total Visual CodeTools
' --------------------------------------------------

Add Option Explicit to each module that lacks it:
Option Explicit

Apply naming conventions to the procedure declaration with parameter prefix:
Function AddRows(plngCustId As Long, pintRetval As Integer) As Boolean

Add procedure comments with all parameters, the return value and dates:
  ' Comments:
  ' Params  : plngCustId 
  '           pintRetval 
  ' Returns : Boolean 
  ' Modified: 06/01 djh 
  '
  Add Error Handling Enabler:
  On Error GoTo PROC_ERR

  Apply naming conventions to variable names based on data type:
  Dim dbsNorthwind As DAO.Database
  Dim rstCustomers As DAO.Recordset
  Split multiple Dims in the same line to separate lines:
  Dim varLastName1
  Dim varLastName2
  Dim strLastName3 As String

  Standardize indentation and line spacing:
  varLastName1 = "Jones"
  varLastName2 = "Smith"
  strLastName3 = "Gates"

  Set dbsNorthwind = DBEngine.Workspaces(0).OpenDatabase("c:\nwind.mb")
  Set rstCustomers = dbsNorthwind.OpenRecordset("customers")
  rstCustomers.FindFirst ("CustomerID=" & plngCustId)
    Fix single-line If statements to add End If:
  If rstCustomers.Fields(0).Value = varLastName1 Then
    AddRows = True
  End If
  Eliminate extra blank lines:

  Fix colon-separated statements and standardized indentation:
  Select Case rstCustomers.Fields(1).Value
    Case 1
      pintRetval = 12
    Case 2
      pintRetval = 13
    Case 3
      pintRetval = 14
    End Select

  rstCustomers.Close
  dbsNorthwind.Close
  Set dbsNorthwind = Nothing

Add Error Handling Exit and Handler Points:

PROC_EXIT:
  Exit Function

PROC_ERR:
  MsgBox Err.Description
  Resume PROC_EXIT

End Function
Standardize to one line between procedures:

Function NullConverter(pvarInValue As Variant) As Variant
  ' Comments:
  ' Params  : pvarInValue
  ' Returns : Variant
  ' Modified: 06/01 djh

  On Error GoTo PROC_ERR
  Split single-line If statements into multiple lines:
  If IsNull(pvarInValue) Then 
    NullConverter = "" 
  Else 
    NullConverter = pvarInValue
  End If
  
PROC_EXIT:
  Exit Function

PROC_ERR:
  MsgBox Err.Description
  Resume PROC_EXIT

End Function
Questions  l   Web questions: Webmaster   l   Copyright © 2008 FMS, Inc.

Celebrating 21 Years of Software Excellence