Tutorial For VB Development
Tutorial For VB Development
How to Use
Project Analyzer v10
Save the forests! If you print this document, print 2 pages per sheet,
on both sides of the paper. Or just read on the screen.
1 Introduction
Aivosto Project Analyzer is a professional source code optimization and documentation software tool
for Visual Basic developers. This tutorial leads you into the world of advanced code analysis. It assumes
knowledge of the Visual Basic language, but no knowledge of code analysis.
Project Analyzer v10 works with code written with Visual Basic versions 3.0, 4.0, 5.0, 6.0, VB.NET
2002, 2003, 2005, 2008, 2010, 2012 and 2013. It also works with the VB.NET code in ASP.NET
projects. Analysis of Office VBA projects is possible with VBA Plug.
Getting more help. This is a tutorial, not a comprehensive manual. Project Analyzer supports more
features than what is described in this document. The help file project.chm is the comprehensive
documentation and manual. The help is also available online at http://www.aivosto.com/project/help
Project Analyzer comes with free technical support, so feel free to ask!
VBA Plug
VBA Plug enables Project Analyzer to read Office VBA code. It retrieves VBA code from Office files
and exports it in a format that Project Analyzer can read. VBA Plug is compatible with all editions of
Project Analyzer. It requires a separate purchase.
2 Getting started
First a short note on the terminology. We use the term classic VB to refer to Visual Basic versions from
3.0 to 6.0. With VB.NET we mean all the supported versions of Visual Basic .NET. In most cases,
Office VBA is like Visual Basic 6.0.
A project means a single program or library (.vbproj, .vbp or .mak project). Occasionally we also use it
in a more general sense to cover the code currently being analyzed, be it from one or several projects. A
solution and a project group mean a number of related projects (.sln and .vbg files).
In this dialog you can select the files to analyze. If you are running a free demo version, you can select a
maximum of 10 source files at a time.
Notice that the analyses selected in the top right corner require the Enterprise Edition. They are also
enabled in the demo and Standard/Pro Edition when you select a maximum of 10 source files to analyze.
When youre done with the options, click Analyze to begin. The analysis consists of two phases. You
can see the progress in the main window.
1. Input. There are two ways to select the VBA input source:
A. Read Office file. Click the button
to pick the Office file to analyze. By default, VBA Plug
retrieves the VBA code in this file only. If you select Include all referenced VBA projects, it will also
retrieve any other VBA code referenced by the file. This is useful in a multi-document system where a
VBA project may call other documents or templates.
B. Connect to running application. In this approach, you open the Office file in the appropriate Office
application first. After doing this, return to VBA Plug and select the running application in the list.
2. Output directory. After selecting the input source, define the output directory into which VBA Plug
will export the retrieved VBA code. The output directory must be an empty directory. You may leave
this undefined, in which case VBA Plug will automatically create a directory for you. The automatically
created directory will appear under the Windows Temp directory by default. You may also define an
alternative location via the File menu.
Now that youve defined the input and output settings, click Export & Analyze. VBA Plug will connect
to Office, retrieve all VBA code and export it into files. The log text will tell you exactly what happens.
If the export was successful, VBA Plug runs Project Analyzer to open the newly exported project(s).
The process will continue as described in the previous chapter Starting an analysis.
Press the Export button if you only want to export the code without running Project Analyzer.
Hypertext view
The hypertext code panel appears in the top-right corner. Project Analyzer highlights and hyperlinks the
code for you to surf in. Use the mouse to left-click and right-click the highlighted words and icons:
Left-click a link. You are taken to the declaration of the clicked variable, function, enum, class etc.
Right-click a link. A popup menu shows up offering a way to view the declaration of the selected item,
locate references to it, print, export and copy selected code, toggle the display of line numbers etc.
Left-click a problem icon (in the left margin). The problem view at the bottom shows the problem(s) on
the line.
Right-click a problem icon. A popup menu opens up listing the problem(s) on the line.
Project tree
The tree view on the left shows the structure of your project. It includes each disk file with the
module(s) and procedures in it. Left-click the items to move around in your project. Right-click the
items for a variety of options and commands.
For image files and files containing several images (.frx files), there is a special command. Double-click
the file to view its contents.
Details panel
The bottom of the window is reserved for code review results and detailed information.
On the Problems tab you will see a list of problems found by automated code review. You can configure
the types of problems Project Analyzer finds by clicking the
into the details of code review later.
On the other tabs you will see details on the selected disk file, module and procedure, respectively.
These tabs also let you learn file dependencies and procedure call trees in an interactive way.
Legend
Project Analyzer uses various symbols and
icons to illustrate your project (image on the
right). In addition, there are some symbols
related to problems found in the code.
Overstrike indicates dead code.
A red line over an icon indicates unused,
dead code.
A violet X indicates exposed code with
deadness status unknown. No use was found for
that code. The code is exposed, however. This
means it is visible to other projects, which may
use it. Because of this, Project Analyzer could
not tell for sure if the code is really dead or not.
It is up to you to decide. To be sure, run multiproject analysis to analyze all possible projects
which could use the code. If the code still shows
up as exposed, you may delete it since it is not
used by any of your projects.
These problem icons indicate a
problem found in code review. Left-click and
right-click the icon for more information.
Display report (default option). The report shows up on a Project Analyzer window. Here you
can print the report, save it to a file or copy to the clipboard.
Print report. This option prints your report without showing any preview.
HTML report. View the report in your web browser. Publish reports online.
RTF report. Open the report in a word processor, such as Microsoft Word or WordPad.
PDF report. View the report with Adobe Acrobat Reader. Publish reports online. Print reports.
Text report. Produce plain-text reports for uses where the other formats are not viable.
CSV report. Export column format reports to a spreadsheet application such as Microsoft Excel.
Not suitable for reports that are not in a column format.
MHT report. The report goes into a single-file web archive for viewing with Microsoft Internet
Explorer. This format is suitable for saving a Project Printer generated project web site (see
page 26) as a single file.
Tip: Right-click in the problem list to learn more about the problems and to produce reports.
Problem categories
Project Analyzer divides problems into the following categories:
1. Optimization issues have a negative effect on the size and execution speed of your program. By
fixing these problems you get a smaller program that runs faster without losing any functionality at all.
2. Style suggestions deal with the way the source code is written. While the end users dont care about
the style of your source code, consistent style is what makes a good program less prone to errors, easier
to maintain and faster to develop further. Style is a matter of proper coding standards. Naming standards
are a part of Style (see Project NameCheck on page 23).
3. Logic flaws are oddities in the control and data flows of your program: questionable coding, erratic
behavior, hidden flaws and problems that are waiting to emerge later. These problems can cause your
program to fail or to produce bad results, or they can represent optimization opportunities. Take time to
carefully examine any found logic problems.
4. Functionality problems affect the actual behavior of your program at run-time. These are the
problems that the end users will notice, sooner or later. Why not be ahead of them and fix the issues
before anyone sends you a bug report?
5. VB.NET compatibility problems appear in classic VB projects. They represent incompatibility issues
that appear when you try to migrate your code to Visual Basic .NET. These problems are available only
in the Enterprise Edition.
6. Internal problems indicate problematic conditions in the analysis. A file may be missing, for
example.
Problem filters
Project Analyzer supports hundreds of code review rules ranging from critical issues to less important
suggestions. Fortunately, you are not required to follow Project Analyzer on everything. After all, we
developers will never agree on what the best programming standards are. You can pick the subset of
code review rules that suits your style best. You may be interested in just optimization issues, for
example. Or you may think that an occasional GoTo is not such a problem. This is where you use
problem filters.
A problem filter enables you to select and configure the subset of code audit rules that you are going to
follow. You can create several filters for different purposes: quick check filters for the development
phase and strict filters for a final polish. You can build a filter from scratch or base it on an existing
filter.
Project Analyzer comes with a set of predefined filters. They are described in the following table.
<Default>
<Dead code>
Report dead and semi-dead code. Ignore dead but exposed code.
This filter reports only certainly dead code.
Report dead and semi-dead code. Include dead but exposed code.
This filter reports all dead code, including dead but exposed code,
which could be in use by external projects.
<Flaw finder>
<Functionality>
<Logic>
Report logic flaws: oddities in the control and data flows of your
program.
<Optimizations>
<Project NameCheck>
Report all problems. This filter may not be very practical since it is
likely to show a very high number of problems.
<Style>
<VB.NET Compatibility>
Report all issues that should be fixed before loading the project in
VB.NET. Requires Enterprise Edition.
Press the
Problem options button to select another filter and configure your own. In fact, you should
configure your own filter. We all have a different coding style, and not all code review rules are suitable
for every developer.
Once youve configured your filter, you can share it with your colleagues. Thats especially useful to
enforce programming standards among teams. To save a filter to a file, use the Export button. Send the
filter file to another Project Analyzer user. To load the filter in Project Analyzer, use the Import button.
We will now go into the basics of the various code review rules available in Project Analyzer. Since this
is a tutorial, we will not list all the available rules here. See the help file for Code review rules for a
comprehensive list with details.
Completely dead code is not required for the program to compile. Since its not used for any purpose, it
can be removed.
Semi-dead code is required at compile-time, but not when the program runs. As an example, semi-dead
code may be required by dead parts only, making it effectively useless at run-time. Alternatively, code
can be in partial use, such as a variable being read but not written to. Semi-dead code is often a sign of a
flaw, or a missing or deleted implementation. Even when its not an error, semi-dead code should be
deleted to keep the code easier to maintain.
Exposed dead code appears unused, but it could be called from an external program. Before deleting
exposed dead code, be sure to analyze all possible external programs together in a multi-project
analysis.
10
may want to remove it. If its a #Const, removal will have no effect on the program. If the constant is
defined in project settings, there is a theoretical possibility that the constant might come back to life.
This could happen if a file referencing the constant was later added to the program.
Dead line labels and numbers. Line labels and line numbers are an obsolete syntax feature of Visual
Basic. They are used for error handling and as the target of a GoTo or GoSub jump, statements which
are best avoided. A line label (or number) that is not being used by any of these statements is dead.
Remove it to ensure it does not distract any developer in the future.
Dead classes are ones that are not used at all. You can remove them.
Dead interfaces. You can remove .NET Interface definition that is not used.
Dead structures. You can remove a .NET Structure that is not used.
Dead modules can be removed in their entirety. Nothing the module contains is in use.
Unused files. These are files that no other files refer to in the source code. They may be classes that are
never instantiated, forms that are never shown, or standard modules whose procedures are no longer
needed. Check to see if you really need these files and remove them from your project. Its a good idea
to move the file to a backup location in case you need to take it back to use later.
11
problem does not apply to VB3 where return values must be used at all times. See also Return value
discarded.
Return value discarded. The return value is ignored at a call to a function. Although it is not necessary
to actually use the return value of a Function, simply ignoring it could indicate a problem in the callers
logic. Review the call to determine if the return value can be ignored safely. This problem does not
apply to VB3 where return values must be used at all times. See also the issue Dead return value.
Semi-dead variables
Semi-dead code is something that is in partial use. In most cases, it is not in proper use, really.
To be in full use, a variable should be both written and read. A read-only or written-only variable is in
partial use only.
Variable written, not read. A variable is given a value but the value is never read by the program. The
variable is either useless or there is a flaw in the program. Review the write locations. Check the code to
determine if its a flaw or if the variable is simply a leftover from an earlier version. Remove the
variable and the write statements if you are sure the variable is useless. Before removal, determine if the
write statements contain any procedure calls that must execute. Removing these calls could make the
program behave erroneously.
Variable read, not written. A variable is never written to, even though its value is read by the program.
The value is always zero, empty or Nothing, depending on the data type. Review the code to see if the
missing write is a flaw in the program or if it is intentional. The write statement(s) may have been
deleted by accident or the developer forgot to add them in the first place. In this case one or more writes
should be added. On the other hand, the write(s) may have been removed on purpose, in which case the
variable now works as a constant. Consider removing the variable altogether or declaring it as a
constant. The use of a constant prevents unexpected changes later in the life-cycle of the program. You
can also save a little memory as constants dont require run-time data storage. This review rule is
especially important for object variables, because the variable will always contain the value Nothing.
This can cause an Object variable not set error at the location the object is referenced. A special case is
denoted as No real value given, cleared/allocated only. For an object variable this means the variable is
set to Nothing but it never contains a live object. Alternatively, an array is allocated but nothing is stored
in it. The array is consuming memory for no purpose.
In addition for a variable being read and written, the read and write statements should actually execute
too. If not, we may be facing faulty code.
Variable users all dead. A variable seems to be in use, but it is not. The user procedures never execute
because they are all dead. As a result, the variable is completely unused and useless at run-time. If you
remove all the user procedures, this variable will stay as a leftover unless you delete it. Use this rule to
hunt for related pieces of dead code that you can remove at the same time. Right-click the variable name
and select References to see the dead users. If the variable seems useful, some features may be missing
from your program. Consider bringing the variable back to life by calling the dead users.
Variable readers all dead. A variable is being read and written. The reads never execute because the
reader procedures are all dead. One or more writes do execute, but it is to no benefit. This is either a
problem in your program or a good place for optimization. Check to see if not reading the variable
indicates a logical fault. It could indicate missing or removed functionality. You may need to bring the
dead readers back to life by calling them, or add new read statements in the live part of your code. If
there does not seem to be a fault, consider dropping the writes. Your code possibly does some
unnecessary work in getting the right value to the variable. Remove the unnecessary parts to optimize
your code.
Variable writers all dead. A variable is being read and written. The writes never execute because the
writer procedures are all dead. One or more reads do execute, though, indicating a flaw in the program.
The value read is always zero, empty or Nothing, depending on the data type. Review the code to see if
this is causes an error at run-time. Determine whether one of the dead writer procedures should be called
to bring the variable back to full life, or whether you should add a new write statement to give the
variable a real value. This type of flawed dead code is really hard to catch without Project Analyzer.
The problem is especially nasty for object variables, because the object will always be Nothing. This can
cause an Object variable not set error when the variable is referenced.
Variable not read, writers all dead. A variable is practically unused and useless. It is never read.
Write statements do exist, but they never execute because the writer procedures are all dead. The
variable looks like a leftover from previous functionality. There is no point writing values to the variable
12
any more, since there are no reads from it. Consider deleting the dead writers along with the variable.
Removing useless parts helps maintenance.
Variable not written, readers all dead. A variable is practically unused and useless. It is never
assigned a value. Read statements do exist, but they never execute because the reader procedures are all
dead. The variable looks like a leftover from previous functionality. The dead readers may contain a
hidden bug (dead bug, so to say). The readers may perform in an unexpected way since the variable
never gets any useful value other than zero, empty or Nothing. Taking the readers back to use can bring
the bug to life. Consider deleting the readers along with the variable. Removing questionable, useless
parts helps maintenance.
What has been said about variables above also applies to fields in user-defined types.
13
analysis is to open a .vbg or a .sln file. You can also select multiple project files to analyze. Read the
help file for in-depth instructions on how to do a multi-project analysis.
Multi-project analysis is recommended for the following project types: project groups (.vbg), solutions
(.sln), ActiveX ocx/dll/exe projects, OLE server projects, and .NET class and component library
projects.
14
There is a catch in classic VB. In the following example, x is really a Variant. Thats very difficult to
notice without Project Analyzer!
Dim x, y As Integer
Dim x As Integer, y As Integer
As you can see, the data type declaration is not explicit. x will be Integer since you initialize it with an
Integer value. But can you tell the data type of y? No, you cant. Its the same as the return data type of
Function GetValue. Type inference sounds like a great productivity feature, but it actually contains a
hidden caveat. Developers stop thinking. As another caveat, a future change to the return data type
GetValue() will propagate to y, possibly even further in the code. To ensure maximum quality, you
should always declare the data type and not rely on Option Infer On.
Functions missing type declaration. Like variables, functions and properties require a type definition
for their return value. If you dont define the type, a function returns a Variant/Object value. Example:
Function Calculate(ByVal Value As Single)
Function Calculate(ByVal Value As Single) As Single
In VB.NET you can use Option Strict On to require a type definition for all variables and functions. In
classic VB there is no way to require that, so you need to run Project Analyzer.
Object variable declared As New. In classic VB, declaring an object variable As New creates an autoinstantiating variable. Each time you read the contents of the variable, VB first checks if the variable
already holds an object, and creates one if not. This adds overhead, thus slowing your program down.
To achieve better performance, remove the word New from the declaration, and instantiate your variable
(Set x = New Class) before it is used. It makes sense to test with If x Is Nothing Then before accessing
the variable, to avoid the run-time error Object variable not set. VB.NET treats As New variables
differently. VB.NET only instantiates the object once, which means there is no performance hit.
Consider short-circuited logic. In the expression (x And y) and a similar one, (x Or y), both
operands (x, y) are evaluated regardless of the value of x. Short-circuiting means rewriting this so that
when x=False in (x And y), y is not evaluated. The same goes for x=True in (x Or y). This saves
CPU cycles, especially if y is a complex expression or involves a function call.
In classic VB, consider splitting an If ..And.. condition as two nested If statements like this:
If x And y Then DoIt
If x Then
If y Then
DoIt
End If
End If
Short-circuiting If ..Or.. yields more complex code. It may be useful where hard optimization is
required.
If x Or y Then DoIt
If x Then
flag = True
ElseIf y Then
flag = True
Else
flag = False
End If
If flag Then
DoIt
End If
In VB.NET, consider replacing And with AndAlso, and Or with OrElse. Read the VB.NET help for
differences between And/AndAlso and Or/OrElse.
15
Short-circuiting involves a risk, because it changes the logic. If the second operand (y) calls a function,
the call is no longer guaranteed to execute. Depending on what the function does, this may lead to your
code not executing something important that should run at this point.
String handling. Project Analyzer supports a set of string optimization rules. They are designed for
string-intensive programs whose performance is limited by the performance VBs string functions. To
learn more about this specific area, read the help file and visit our web site for extensive articles on
string optimization.
Declaration style
Option Explicit Off. If you dont use Option Explicit, or you have set it Off, youve got to learn to set it
On now. In classic VB, you need to write Option Explicit at the beginning of each file. In VB.NET
you either write Option Explicit On or select the respective option in project options. This makes
Visual Basic require variable declaration.
Always declaring your variables is good programming practice and widely recommended by VB
experts. Explicit variable declarations make your code more readable and to require less RAM. They
may also make your program run faster, especially if you use a lot of objects in your code. How come?
Thats because you give all your variables a proper data type, the best type suitable for the job.
Here is yet another reason why you should use Option Explicit. It forces you think about the correct data
type when youre writing the Dim statements, functions and properties. Increased thinking leads to
increased quality, right?
Option Strict missing. A file does not define Option Strict On. In VB.NET, Option Strict On
enforces type-safe code by allowing only widening data type conversions. It also disables late binding.
You can set it as a project-level option or for each file. Disallowing late binding helps you avoid
unnecessary run-time errors and add performance. Besides, analyzing your projects with Project
Analyzer becomes more accurate when all calls are early bound.
Scope declaration missing. Always give your procedures, variables etc. a scope. VBs default scope
rules are somewhat complicated. They may lead to a scope that is either too wide or too limiting.
Consider this syntax:
Sub Calc()
Can this be called from outside its own module? Can you immediately tell if Calc( ) is Public or Private?
Many of us cant. So, why not write one of the following:
Private
Friend
Public
Protected
Protected
Sub Calc()
Sub Calc()
Sub Calc()
Sub Calc()
' VB.NET only
Friend Sub Calc() ' VB.NET only
A Private thing cannot be called from other modules. A Public thing is part of the interface of the
module and can be accessed from outside. In library projects, Public things may even be called from
other projects. Its important to declare a proper scope to keep your code modular.
Friend, Protected or Protected Friend might also come into question in object-oriented programming. In
Friend access, the declaration is available inside the project, but not exposed to any outside projects.
16
The distinction between Public and Friend is important if youre writing a library project that exposes a
public interface to other libraries or programs. In standard executable programs, Public actually works
as if it was Friend, because standard executables dont publish anything for other programs to call.
Protected scope, available in VB.NET, is like Private but it gets inherited to any descendant classes.
Protected Friend is a combination of Protected and Friend, it gets inherited and its also available in the
declaring project.
Excess scope. A part of your program has a scope thats too wide. Even if you could, you dont actually
use this part up to the scope. Check to see if you should declare the part with a more restricted scope. It
is good programming practice to use as limited a scope as possible to prevent other parts of the program
from calling and modifying parts that they shouldnt have anything to do with. Note that its especially
important to encapsulate excess scope class variables as properties. Variables defined in classes should
be made inaccessible to other parts of the system. Read/write access should only be through properties
(or methods). This protects your data from being modified the wrong way. Encapsulation also lets you
keep certain data read-only. Just leave out the Property Set/Let part or make it Private. As an additional
benefit of encapsulation, you can later change the way you store your data without affecting other parts
of the system.
ByRef/ByVal missing. Incorrect or loose parameter declaration is a potential source of hard-to-find
bugs. Always use ByRef or ByVal when declaring your procedure parameters and your code gets more
robust.
What exactly do these ByVal and ByRef things mean?
ByVal tells VB to pass a parameter by value. That is, the value of a variable is passed from the caller to
the callee. The actual variable is not being passed. This makes your code safe. Whatever value you write
to the parameter in the callee, the changes wont propagate back to the caller.
ByRef tells VB to pass a parameter by reference. This means that not only the value, but also a reference
to the actual variable is being passed. When you change the value of the parameter, the change is
reflected in the caller too! This may lead to errors that are really hard to notice. Example:
Sub DoThings(ByRef Text As String)
Text = "Hello, world!"
End Sub
Sub Main()
Dim Text As String
Text = "Hello, fellow!"
Sub Main()
Dim Text As String
Text = "Hello, fellow!"
DoThings(Text)
MsgBox(Text) ' Hello, world!
End Sub
DoThings(Text)
MsgBox(Text) ' Hello, fellow!
End Sub
The default in VB versions up to 6.0 is ByRef. Thats the unsafe one! If you dont choose between
ByVal and ByRef, you always get ByRef, the riskier option. Thats why its important to write the words
explicitly.
Fortunately, VB.NET fixed this problem. In VB.NET the default is ByVal.
It should be noted here that there are good uses for ByRef. One case is an out parameter that returns a
value back to the caller. This is usually best avoided, but sometimes it is required. Another case is to
obtain maximum speed. The copying of ByVal parameter values takes time, and if you call the
procedure thousands of times, it might pay off to use ByRef. That depends on the parameter data types,
and you should experiment with it if you need to squeeze out more speed. If you do a lot of string
processing, the use of ByRef string parameters instead of ByVal may give your program a real
performance boost. In addition, sometimes VB just demands ByRef. At those times VB will tell you
about that. Project Analyzer knows about the obligatory ByRef cases and wont issue any unnecessary
warnings about them.
17
performance. One should use real Subs and Functions instead of GoSub. Besides, GoSub is outdated
and it isnt supported by VB.NET.
Exit statement found (Exit For|Do|While etc.). Use of the Exit statement indicates unstructured
program flow, much the same way as the GoTo statement. An Exit statement causes an immediate jump
out of a programming structure such as a loop. In purely structured programming style Exit statements
should not be used. Well-placed Exit statements are not considered harmful by many programmers,
though.
Exit Sub|Function|Property found. An Exit Sub|Function|Property statement causes an immediate
jump out of a procedure. It potentially makes the procedure have several exit points. Procedures should
have only one exit point at the end. There is a case where VB requires a premature Exit. This is when
you need to quit a procedure immediately before an On Error GoTo xxx type error hander. Project
Analyzer allows this use.
Return statement found. A Return statement causes an immediate jump out of a procedure in
VB.NET. It potentially makes the procedure have several exit points. Procedures should have only one
exit point at the end. There is a case where VB requires a premature Return. This is when you need to
quit a procedure immediately before an On Error GoTo xxx type error hander. Another case where
Return must be used is in an Operator (VB 2005 and later). Project Analyzer allows these uses. This rule
is available for VB.NET.
Multiple Return statements found. A procedure contains multiple Return statements. There should be
exactly one exit point in a procedure. Multiple exits make the procedure harder to understand. The
requirement for multiple exits may indicate too complex a procedure, in which case it should be split.
Rewrite the procedure to contain a maximum of one Return statement. This rule applies to VB.NET.
Note that this rule does not count Exit Function statements. The rule Exit Sub|Function|Property
statement found detects them.
While. The While..Wend or While..End While loop is outdated. Do...Loop provides a more structured
and flexible way to perform looping. In VB 3-6, the syntax to avoid is While..Wend. In VB.NET, it is
While..End While.
Call is not a necessary statement to call a procedure. Leave it out.
IIf / Switch / Choose. These functions are considered bad programming style because of functionality,
optimization and readability issues. All conditions and branches of IIf / Switch / Choose are always
executed resulting in longer execution time and possible unwanted side-effects. Switch and Choose may
return an unwanted Null. Use Select Case or If..End If instead.
Single-line If..Then statement. An If..Then(..Else) construct is on a single line. To make your program
more readable, split the construct to multiple lines.
Multiple statements on one line. There is more than one statement on a single line, separated with a
colon ( : ). To make your program more readable, write only one statement on one line.
On Error. The use of On Error for exception handling is outdated in VB.NET projects. It is better to
use the Try..Catch block for error handling. On Error Resume Next also deteriorates the performance of
.NET execution. Use Try..End Try without the Catch block to achieve a similar effect without the
performance hit.
Global found, use Public. Early versions of VB didnt have the Public keyword. In VB 4.0, Public and
Private were introduced for defining the scope of things. Nowadays it is suggested that you use Public
instead of Global. They are synonymous words, so no harm is done. Starting with VB 2005, the Global
keyword has a new meaning. Its best not to use Global to declare Public variables any more.
Enum style
Project Analyzer lets you enforce consistent standards for Enums. You can set one or more of the
following requirements: all Enums should define a zero constant; all constants should be explicitly set as
a name=value pair, not relying on VB to calculate the value; each constant should have a different
value; Enum constants should be used in place of the numeric value; and each constant should actually
be utilized. In addition, each Select Case block should have a Case for every constant (see the next
section for this rule).
Enum has implicit member value(s). One or more members of an Enum do not have an explicitly
declared value. The values might change if new members are added. This potentially affects code where
the old values are used instead of the Enum member names.
18
Enum missing zero value. An Enum should define a constant with the value of zero. The default value
of an uninitialized Enum variable is zero. Explicitly defining a zero Enum constant makes the
uninitialized value valid. You can name the zero constant with a descriptive name such as None or
Empty or Error.
Enum with duplicate value. Two or more constants in an Enum define the same value. Check to see if
this is by accident. Declaring the same value several times may be intended. On the other hand, an error
may have caused the duplicate definition. Check to see if you can join the multiple constants into one to
prevent problems understanding the Enum later.
Enum constant expected. An enumeration constant is expected on this line. An Enum datatype is
assigned a value not belonging to that Enum. One should only store Enum values, not integers or other
datatypes. Otherwise you easily end up with a value outside to the Enum. An Enum should fully define
and document its acceptable values. Using an undefined value is undocumented programming, really, or
even an indication of erroneous logic. A programming style that uses magic integers interchangeably
with Enum constants is prone to maintenance errors. If the Enum values are later changed, the respective
magic integers are easily left unchanged, which leads to new errors.
Path analysis
To detect logic problems Project Analyzer runs path analysis. It follows the execution flow through
branches, loops and jumps to determine which lines will actually execute at run-time. It checks out when
variables are read and when they are written to. As to loops, Project Analyzer evaluates whether a loop
executes zero, one or more times and if its an eternal loop.
Unreachable code found. A block of code is dead because it is not reachable. It will never execute.
Unreachable code means impossible branches, loops that dont run, unused error handlers (On Error
style) and labeled blocks that are not being jumped into. Code that immediately follows an unconditional
jump (such as a Return or Exit statement) can also be unreachable. Unreachable code cannot run at all. It
is a programming error: bad logic or the remains of old code that should have been deleted. Determine
whether you should remove the unreachable block or if it should rather be brought back to life.
Unreachable code should not be exist. If it is necessary to leave it for later use, consider commenting it
out or putting it in a #If..#End If block to exclude it from compilation and to make it explicit it may be
19
required later. This rule is good for detecting On Error style error handlers that are not in use. It can
also detect broken loops that dont loop (last statement never reached). It can even detect code that was
removed by writing Exit Sub above it.
Variable read before written. A local variable is being read before a write instruction ever executes.
At this point the variable will always contain its default value (zero or empty string). This is most
probably a mistake. The preceding write instruction may have been deleted or the execution flow
wrongly modified. It could also indicate a superfluous variable or the use of an incorrect variable. This
rule ignores error handlers, as the run-time triggering of an error handler is difficult to determine by
code analysis.
Variable read before written (along some path). A local variable is being read before a write
instruction is guaranteed to have executed. Thus, when the variable is read, it may have a proper value,
but it could also contain its default value potentially due to a mistake. Depending on the case this may
be problematic or not.
Note: The difference between Variable read before written and Variable read before written (along
some path) is that the former is a stricter variant. The latter triggers when a read before write is even a
remote possibility. The former triggers only when a read always happens before a write.
Object read before written. A local object variable is being accessed, but its value is always Nothing
at this point. A run-time error is likely (null pointer reference, object variable not set). This warning
appears where an object variable cannot be set by a preceding instruction.
Object read before written (along some path). A local object variable is being accessed, but its value
may be Nothing. A run-time error may occur at this point (null pointer reference, object variable not
set). This warning appears when some path may have left an object variable unset. To avoid a run-time
error verify that the variable will actually contain an object at this point.
Tip: To improve the accuracy of these read before written rules, enable analysis of library files
(Enterprise Edition required).
Assigned value (or object) not used. A local variable is assigned a value that is not actually used after
the assignment. It is either overwritten or not used at all. Review the code to see if it is a programming
error or if you can optimize by deleting the write statement. Make sure you are not removing any
required function calls at this point, calls that have useful side effects.
Parameter value not used. The value passed to a procedure parameter is not actually used. The value is
overwritten or execution never flows into a read instruction. Review the code to see if it is an error.
This rule is related to the Dead parameter rule. A Dead parameter is one that is not used at all.
Parameter value not used means the parameter name is indeed in use, but not the value passed to it.
Passed value not used. A parameter is being passed in a procedure call, but the receiving procedure
does not actually use the value. Is the logic still all right? It may be possible to optimize by leaving out
the parameter or by passing a dummy constant instead of a calculated value. This rule excludes out
parameters, which are used to return a value.
Loop runs forever. An eternal loop was found. Once the loop is entered, there is no exit or all exits are
unreachable. The program could jam here.
Loop runs only once. A loop starts but it doesnt execute another round. Is it a flaw? Should it run
several times or can you just remove this useless loop? Related rule: A loop that runs zero times is
reported as Unreachable code.
Cyclic recursion found. Cyclic recursion happens when A calls B, which calls C, which eventually
calls A again. Recursion through two or more procedures is difficult to understand and get to work
correctly. There is also a risk of endless recursion. Cyclic recursion is also known as indirect recursion.
The opposite is direct recursion, a procedure calling itself repeatedly. Direct recursion is not as
problematic as cyclic recursion. Consider replacing cyclic recursion with either a non-recursive
technique or direct recursion. Restricting recursion to a single procedure is easier to manage. To prevent
endless recursion, you can add a safety counter that breaks the execution if it goes too deep. To fully
understand a large recursive cycle, get the Recursion diagram in Enterprise Diagrams. Note: This rule
triggers based on static analysis. Due to run-time conditions and checks, the actual execution path might
not be recursive.
20
General functionality
Error handler missing. A procedure has no error handler. Your program may crash if a run-time error
occurs in this procedure.
Delayed error handler. A procedure uses delayed error handling. By delayed error handling we mean
the use of On Error Resume Next or a Try block without Catch. Run-time errors are handled in the
procedure(s) that call this one. This may be completely as you planned, or you may have forgotten to
add an error handler (On Error GoTo, or Catch in a Try..End Try block).
You can ignore the error handling issues in small procedures. For example, you may consider that
procedures with just 1 or 2 lines are unlikely to cause crashes. While we dont recommend this
approach, Project Analyzer allows you to set a minimum limit on the procedure size requiring proper
error handling.
21
Consider using VB Watch, a tool that adds advanced error handlers to your code. VB Watch works
with Visual Basic 6.0. It adds error handling automatically. Once an error hits, the end user has an
option to ignore the error and/or send you a detailed error report. VB Watch is available through
www.aivosto.com.
Events not handled. An object variable is declared WithEvents. However, none of the events are
handled. Why did you declare it as WithEvents in the first place?
Hard-coded path found. A string that looks like a hard-coded path name exists in your program. File
access through hard-coded paths will fail if the directory structure changes. The code seems to assume a
certain directory structure at run-time. It is more flexible to operate with path names relative to the
installation directory, for example. Where hard-coded paths are really desired, it is best to define the
necessary paths with global constants or in a resource file to allow for easier maintenance.
Verify accuracy. A floating point constant may be imprecise. This rule searches the code for decimal
numbers that look like common constants, such as pi or e. The rule verifies the accuracy of such
constants. A flag is triggered where fewer than all available digits are used. The rule also flags values
that are somewhat incorrect. This rule is good for verifying scientific programs. It supports hundreds of
mathematical, physical and chemical constants. You can add your own constants as well. To customize
the list of constants see the file constant.txt in your Project Analyzer directory.
22
will ignore problems in them. You do it by writing special comments in your code. These are called
comment directives. A sample directive looks like this:
'$PROBHIDE DEAD
Sub MySub()
The directives dont affect Visual Basic in any way, but they tell Project Analyzer how to behave. See
topic Comment directives in the help file for the exact syntax.
Running Auto-fix
Analyze a project and start Auto-fix in the Enterprise menu. A dialog box appears. Auto-fix will
generate a copy of your project and work on it, without touching the original files in any way. Select a
new, empty directory for the cleaned project. For your safety, the cleaned files will be put into this
directory, regardless of which sub-directory they were originally in. This makes sure that you never need
to fear overwriting any of your code.
There are two categories of coding problems: auto-fixable and those requiring a manual fix.
Auto-fixable problems
This group of problems is handled automatically. Auto-fixable problems include dead code, simple
optimizations, procedure, variable and constant declarations and missing events. A comprehensive list of
auto-fixable problems can be found in the help file in topic Auto-fix problem list. Your options are:
Fix & comment. This option makes Auto-fix repair all auto-fixable problems and add a comment next to
the modified code. The comment will bear a prefix such as '! or 'HACK: for you to notice it. This option
handles dead code by commenting it out. You can define a special dead code comment, such as '+ or
anything you prefer to remind you the code has been commented out because it was dead.
Fix quietly. This option repairs all auto-fixable problems, but it adds no comment. Dead code is simply
deleted without a trace.
Treat as manual fix. Selecting this option disables all automatic fixes. Auto-fixable problems will be
treated the same way as manual fix problems. Use this option to comment your code with problem
information so that you can open up Visual Basic, review the problems and fix your code manually.
23
Auto-fix tips
After running Auto-fix, there is a chance that your newly generated clean project might not compile or
run. This might be due to live code being removed or an incorrect fix being applied.
Because of this, you should start by auto-fixing a limited number of problems at a time. Select a limited
number of files to process in one run. Define a problem filter that selects just dead procedures, for
example. Use the Fix & comment option to comment out the dead code. Try to compile. If it wont
compile, you can always restore the required procedure by removing the comments.
You can overcome the occasional limitations of the analysis by writing special comments in the code.
For example, the comment '$ PROBHIDE DEAD will hide the dead code problem for the selected piece of
code. This feature is called Comment directives. You can find the details in the help file.
Auto-fix is not recommended for partially analyzed projects. Correct detection of certain problems, such
as dead code, requires that a project has been completely analyzed.
24
Scope: The scope where the name is available. It can be global, procedure-level, etc. A typical
scope prefix is g or glb for global, and m for module-level.
Type: The type of a variable, function or control. Typical type prefixes include cmd for
CommandButton, int for Integer and E for Enums.
When you combine Scope and Type with <base>, you get 10 possible combinations. They are here
shown for the variable containing an age.
Combination
Scope+Type+ <base>
Type+Scope+ <base>
<base> +Scope+Type
<base> +Type+Scope
Scope+ <base> +Type
Type+ <base> +Scope
Scope+ <base>
<base> +Scope
Type+ <base>
<base> +Type
Example
giAge
igAge
Age_glb%
Age_int_glb
gAge%
iAge_glb
gAge
Age_glb
iAge
Age%
Declaration
Public giAge as Integer
Public igAge as Integer
Public Age_glb%
Public Age_int_glb as Integer
Public Age%
Public iAge_glb as Integer
Public gAge As clsPersonAge
Public Age_glb As clsPersonAge
Public iAge As Integer
Public Age%
Some of the combination may not actually look very useful, at least not for a global integer. Your job is
to decide which combination(s) you wish to use.
To learn more about the various configuration options read the help file topic Project NameCheck
standard configuration.
25
File list: plain listing, with details, with file sizes and dates
Files and projects: which file belongs to which project
Module list: sorted listing of modules, modules classified into groups
Namespaces list: VB.NET Namespace hierarchy
Procedure list: plain listing, with details, sorted alphabetically
Variable list, Constant list
Types, Enums and Aliases report
Dictionary report: all names sorted alphabetically plus statistics on names
The cross-reference information, calling and called procedures, is useful when you need to see which
procedures work together.
Comment manual is an enhanced version of listing procedures with comments. This is an option in the
Project Printer feature (see page 26).
In the Report|Lists sub-menu, select Variable list. The Variable list shows the global and
module-level variables in your program.
26
The Constant list in the same menu puts out all constants, whether global or local, grouped by
data type. You also get a listing of compiler constants in this report.
In the View menu, open the Variables, constants and parameters window. This window lets you
list, filter and sort the variables, constants and parameters and then get a report of them.
In the View menu, open the Constants and Enums window. This window lets you list and report
all available constants and enumeration constants. You can also perform analyses on them,
search for duplicated constants, for example.
27
28
one procedure or a group of procedures. If you take it for a group of procedures, you simply get a list of
everything that the group needs. This is useful if you want to copy certain routines from a project to
another.
Cross-reference reports
There are several reference based reports in the Report|Cross-references sub-menu.
The Cross-reference report is a master report that lists all calls/called by relationships between
procedures. In addition, it lists where variables are being read from and written to, and where constants,
Enums and Types are being references.
The Procedure references report lists procedures with their call sites. For each procedure it lists the
lines that call it.
The Variable references and Constant references reports are similar to the Procedure references report.
They list the lines accessing each variable and constant.
You can also view reference lists by selecting References in the View menu. In addition, you can rightclick any programming object in the hypertext view of the main window. In the popup menu click
References to view references to any particular programming object, such as a variable, constant,
function and so on.
29
5 Diagramming
Project Analyzer provides two features to document the structure of a program in a graphical way.
Project Graph is for interactive graphing and navigation. Enterprise Diagrams makes comprehensive
documentation.
30
Form show tree. This graph type describes the order in which forms show other forms by calling
Form.Show (or Form.ShowDialog in VB.NET). Form1 shows Form2 if it either calls Form2.Show, or
the procedure call trees starting at Form1 contain a call to Form2.Show. Form1 may also show Form2 if
Form1 contains a UserControl that shows Form2. This graph does not include self-showing forms. A
self-showing form is one that displays itself in its constructor or event such as Form_Load. The showing
of forms by setting their Visible property to True is not included in this graph.
Project dependencies. This graph will appear in a multi-project analysis to show dependencies between
several projects. If the system is big and the dependencies are complex, the Enterprise Diagrams feature
provides a better view into the dependencies.
Because the graphs easily get huge, the size of a graph is automatically limited to max 6 levels forwards
and max 6 levels backwards. You can get more levels by right-clicking a node and selecting Expand. On
complex systems you may find out that even 2 levels is too much. In this case, you need to take more
than one picture. Open the Options menu for some settings to keep the graph size smaller.
To print the graph call tree, use the Print button. This prints a page with the graph that is currently
shown on the screen. To include the picture in your documentation, press Ctrl+C to copy to the
clipboard and paste the resulting picture in your word processor. You can also save the graph as an
image file.
Diagram types
The diagram types in Enterprise Diagrams are roughly similar to those in Project Graph, but Enterprise
Diagrams also provides some additional diagrams not present in Project Graph.
File dependencies. This diagram shows file requires/is required by information. AB means file A
requires file B to compile or run. A red double-headed arrow indicates mutually dependent files, which
should be avoided if possible. File dependency diagrams also come in the following variants:
File dependencies, circular groups boxed. This file dependency diagram emphasizes circular file
dependency groups. Consider removing the circular dependencies to reach better reusability.
File dependencies, circular groups collapsed. Save space by collapsing circular dependency groups.
The groups are frequently very complex inside, making them hard to visualize. This option hides the
circular dependencies in effort to make the diagram easier to read. To see the hidden links inside the
groups, get the circular groups boxed diagram for each group.
Inherits and Implements. This option builds a full class hierarchy diagram with interfaces. Not all
projects use inheritance or interfaces. Therefore, the diagram may consist of separated classes only. For
classic VB projects the diagram displays only Implements since there is no Inherits available.
Control flow. This diagram shows how procedure execution traverses between modules. It is the
equivalent of a procedure call diagram taken to the module level. The procedure-level detail has been
left out and the modules remain. This is a higher-level view into a procedure call diagram. By leaving
out cluttered details you get a high-level understanding of the call dependencies.
31
Data flow. This diagram shows all data flows between modules. Data flows via variable read/write,
procedure parameters and function return values. It is typical that data flows in both directions between
2 modules as the modules pass data via parameters and return values.
Variable data flow. This diagram shows data flows between modules via variable read/write. The
difference to the Data flow diagram is that procedure calls and return values are not taken into account.
Thus, this diagram considers only direct variable based data transfer.
Variable access. This diagram shows direct variable access between modules. The only difference to
the Variable data flow diagram is the direction of the read access. This diagram is useful for reviewing
access to global variables and data structures. Direct variable access is often considered bad. Instead of
direct variable access, one should access data via properties or functions. This diagram reveals the direct
variable access that could be rewritten.
Instantiate. This diagram shows where classes are being instantiated.
Data declarations. This diagram shows where classes, structures, interfaces and forms are being used as
data types.
Form.Show order. This diagram type describes the order in which forms show other forms by calling
Form.Show (or Form.ShowDialog in VB.NET). Form1 shows Form2 if it either calls Form2.Show, or
the procedure call trees starting at Form1 contain a call to Form2.Show. Form1 may also show Form2 if
Form1 contains a UserControl that shows Form2. This graph does not include self-showing forms. A
self-showing form is one that displays itself in its constructor or event such as Form_Load. Showing
forms by setting their Visible property to True is not included in this graph.
Procedure calls. The procedure call diagrams display all calls between the selected procedures. The
diagram comes in three variants:
Project dependencies. This diagram shows dependencies between several projects. It is useful with a
multi-project analysis.
File belongs to project. This option lets you view which files belong to which project in a multi-project
analysis. Remember to select the project file(s) into the diagram, otherwise there are no links.
32
Cohesion. The Cohesion diagram displays the procedures of a module and also the variables they use in
that same module. The diagram helps you understand the procedure-to-procedure and procedure-tovariable relationships within a single module.
Recursion. The Recursion diagram helps find indirect recursion. Indirect recursion means that
procedure A calls another procedure, which ultimately calls A again. While recursion is a perfectly valid
program design, unintentional or ill-defined recursion can lead to an infinite loop, stack overflow or
slow performance. Note: Recursion diagrams do not consider direct recursion where a procedure calls
itself.
You create Enterprise Diagrams by adding items in the Diagram items list, in the middle of the dialog.
When youve done with your selection, press the View button and a diagram shows up. You can also
Save to a file, Print the diagram or export to Microsoft Visio. For Visio export to work you need Visio
installed on the same computer as Project Analyzer. The out the help file for the supported Visio
versions.
It is often impractical to visualize a large program in a single diagram. If the diagram is too complex, it
may be impossible to create, read or print. Therefore, dont just drag all available items into the diagram
and expect it to work like magic. Add some key items first, such as the main form or a central class.
Select these items in the Diagram items list. Now you can find connected items via the Find links
feature on the right. Select the number of link levels you wish to find and press From to find incoming
links, To to find outgoing links and Both to find both From and To links. Then drag the items
found to the middle.
To remove unnecessary content from the diagram, press the Clean unconnected button. This will
remove unlinked nodes from the graph, but keep all linked ones. Unlinked items frequently resemble
something uninteresting, such as a function that is not in use by the code in question.
You can also use the Join selected button. This will make a complex chart simpler by joining the
selected items and hiding any links between them. You can use Join selected to group things together.
As an example, you can group related forms to visualize connections between form groups instead of
individual forms.
33
Multi-project analysis is essential for many web systems, mixed language systems and any other systems
consisting of several projects. It is capable of analyzing hundreds of projects in one run. Without multiproject analysis you are limited to analyzing one project at a time.
You start a multi-project analysis simply by choosing a .vbg or .sln file to analyze. You can also add
new projects to the analysis by pressing the Add project(s) button in the dialog that pops up when you
have selected the project to analyze.
34
with a built-in API database. This lets it show the declaration format of a large number of Windows API
functions.
35
Fewer errors. If the same code is repeated at several locations, changes and fixes at one location
dont get propagated to the other locations.
Smaller executable size.
You can eliminate repeated code snippets by turning them into procedures. If entire procedures are
repeated, you can usually delete the duplicate(s) and keep just one of them.
Sometimes you can find flaws with duplicated code analysis. Code is repeated where different code
should actually have been used. Two different routines may inadvertently contain the same code.
Compatibility issues
A typical compatibility issue cannot be resolved by a computer. Human attention is required. Therefore,
you need to get prepared for manual work. The available types listed in the below table.
Feature not upgradable
36
You probably get a long list of compatibility issues. It is advisable to first use a problem filter that
selects the most critical issues. Pay special attention to those problems that are classified as Feature not
upgradable, Fix required before upgrade or Fix recommended before upgrade. These classes are
indicated with either a red or a yellow problem icon.
You can get a summary of the upgrade work by generating a VB.NET Compatibility Report. You can
find this report in the Enterprise menu. This report tells you if the project is upgradable to VB.NET. It
also estimates the size of the upgrade work. Selection of the problem filter (in Problem Options) does
not affect this report.
Project Analyzer Enterprise Edition does not check for all incompatibilities between VB6 and VB.NET.
It provides a limited set of compatibility checks. When you upgrade to VB.NET, you are likely to find
more incompatibilities. See the VB.NET documentation for more help on migration issues.
6.6 Macros
Feature requires Enterprise Edition.
Have Project Analyzer work for you while you sleep or drink coffee! If you need to do the same
analyses and again and again, try the macro feature. The macros are simple plaintext .pam files that
instruct Project Analyzer to open projects, analyze them and perform some operations such as reporting
and auto-fix. Macros run unattended, so you can even run them from the command line or from a batch
file.
Macros are described in detail in the help file. Notice that the use of macros always requires the
Enterprise Edition they are not available in the demo or the Standard/Pro Editions regardless of how
few files you analyze.
37
Project Metrics Viewer displays metrics statistics and charts. This way you get deep knowledge of your
system.
38
Project date
DAYS
Days passed
LINES
Physical lines
Physical source lines, including code, comments, empty comments and empty lines. This metric is
what you would see with a simple text editor or line count program.
LLINES
Logical lines
Logical source lines, including code, comments, empty comments and empty lines. One logical
line may be split on several physical lines by a line continuation character. LLINES=LLOC +
LLOC' + LLOW
LLOC
Code lines count. One logical line may be split on several physical lines by a line continuation
character.
LLOC'
Comment lines count. All full-line comments count, even if empty. End-of-codeline comments not
included. One logical line may be split on several physical lines by a line continuation character.
LLOW
Logical lines of whitespace. This is mostly equal to physical lines of whitespace, that is lines that
have no other content than spaces, tabs and the line continuation character.
LLOC%
Code percentage
LLOC'%
Comment percentage
LLOW%
Whitespace percentage
MCOMM
Meaningful comments
MCOMM%
Comment density
kB
Project size
Project size in kilobytes. Includes all source files included in the analysis, excluding referenced
files.
DATEF
STMT
Number of statements
STMTd
Declarative statements
Number of declarative statements, which are: procedure headers, variable and constant
declarations, all statements outside procedures.
STMTx
Executable statements
STMTc
Control statements
Number of control statements. A control statement is an executable statement that can alter the
order in which statements are executed.
STMTnc
Non-control statements
Number of non-control statements, which are executable statements that are neither control nor
declarative statements. STMTnc=STMTx-STMTc
XQT
Executability
Executability measures the amount of executable statements. It equals the number of executable
statements divided by the number of all statements. XQT=STMTx/STMT
CTRL
Control density
Control density measures the amount of control statements. It equals the number of control
statements divided by the number of all executable statements. CTRL=STMTc/STMTx
SDENS
Statement density
FILES
Number of files
PROCS
Number of procedures
Number of procedures, including subs, functions, property blocks, API declarations and events.
VARS
Number of variables
CONSTS
Number of consts
UDTS
Number of user-defined types Number of user-defined types, that is, Type and/or Structure blocks.
ENUMS
Number of Enums
ENUMCS
VARSgm
VARSloc
Local variables
FORMS
Number of forms
MDLS
Number of standard modules Number of standard modules: .bas files and Module blocks.
dPROCS
dVARS
dCONSTS
dLINES
Dead lines
dUDTS
Number of dead user-defined Number of unused user-defined types, that is, Type and/or Structure blocks.
types
dENUMS
dENUMCS
DEAD
Deadness index
LEN
Length of names
Average length of names defined in VB files, including everything in LENV, LENC and LENP,
plus Types, Enums, Type fields, Enum constants, controls, classes, structures and modules.
39
LENV
Average length of names of variables, arrays and parameters defined in VB files, excluding
parameters in event handlers and implementing procedures.
LENC
LENP
Average length of procedure names defined in VB files, excluding event handlers and
implementing procedures. Each property is counted only once. This metric may differ from the
other LENP, which is defined for a slightly different set of procedures.
UNIQ
Number of unique names divided by the total number of names. All the names in LEN are
counted.
ENUMSZ
ENUMR
Enum ratio
DECDENS
Decision density
Indicates the density of decision statements in the code. Calculated as sum of procedural
cyclomatic complexity divided by logical lines of code. DECDENS=Sum(CC)/LLOC
TCC
Total cyclomatic complexity Total cyclomatic complexity equals the total number of decisions + 1. TCC=Sum(CC)Count(CC)+1
SYSC
System complexity
Sum of SYSC over all procedures. Measures the total complexity of a project. SYSC=Sum(SYSC)
over all procedures
RSYSC
CALLS
Number of procedure call statements, including calls to subs, functions and declares, accesses to
properties and the raising of events. Implicit calls (such as Form_Load) are not counted.
CALLDENS
Call density
maxDCALLT
The depth of the largest call tree in the system: number of levels in the tree.
maxDCALLT=Max(DCALLT)
maxSCALLT
The size of the largest call tree in the system: number of distinct procedures in the tree.
maxSCALLT=Max(SCALLT)
RB
Reuse benefit
Reuse benefit RB is the extent to which you reuse your procedures. A procedure that is being
called at several locations is said to be reused. A procedure that is called just once or not at all is
not reused. RB measures the overall amount of reuse in the entire system.
Rc
Reuse of constants
The average number of times you reuse your constants and enum constants. Rc=uses/count - 1
CLS
Number of classes
ROOTS
LEAFS
INTERFS
Number of Interface
definitions
maxDIT
Maximum depth of
inheritance tree
CLSa
CLSc
Number of concrete classes defined in project. A concrete class is one that is not abstract (see
CLSa). CLSc=CLS-CLSa
Reuse ratio
Reuse ratio for classes. A class is reused if it has descendants. U=(CLS - LEAFS) / CLS
Specialization ratio
Specialization ratio for classes. A class is specialized if it inherits from a parent class. In a project
without superclasses, S is undefined. S=subclasses/superclasses
MIF
The sum of inherited methods divided by the total number of methods in a project.
AIF
The sum of inherited variables divided by the total number of variables in a project.
MHF
AHF
Measures how class attributes (variables) are hidden from other classes.
PF
Polymorphism factor
Percentage of actual polymorphic definitions of all possible polymorphic definitions. Also known
as POF.
CF
Coupling factor
Measures the actual couplings among classes in relation to the maximum number of possible
couplings. Also known as COF.
OHEF
Operation hiding
effectiveness factor
AHEF
Attribute hiding effectiveness Classes that do access attributes / Classes that can access attributes.
factor
IIF
The relative amount of internal inheritance. Internal inheritance happens when a class inherits
another class in the same system (not an external class).
PPF
Parametric polymorphism
factor
TREADS
TWRITES
TRW
DATADENS
40
Amount of data flow via global and module-level variables versus procedure parameters and
function return values. IOg%=Sum(IOg) / Sum(IOg+IOp)
LINES
Physical lines
Physical source lines, including code, comments, empty comments and empty lines. This metric is
what you would see with a simple text editor or line count program.
LLINES
Logical lines
Logical source lines, including code, comments, empty comments and empty lines. One logical
line may be split on several physical lines by a line continuation character. LLINES=LLOC +
LLOC' + LLOW
LLOC
Code lines count. One logical line may be split on several physical lines by a line continuation
character.
LLOC'
Comment lines count. All full-line comments count, even if empty. End-of-codeline comments not
included. One logical line may be split on several physical lines by a line continuation character.
LLOW
Logical lines of whitespace. This is mostly equal to physical lines of whitespace, that is lines that
have no other content than spaces, tabs and the line continuation character.
LLOC%
Code percentage
LLOC'%
Comment percentage
LLOW%
Whitespace percentage
MCOMM
Meaningful comments
MCOMM%
Comment density
kB
File size
DATEF
File date
File date.
PROCS
Number of procedures
Number of procedures, including subs, functions, property blocks, API declarations and events.
VARS
Number of variables
CONSTS
Number of consts
SFIN
Structural fan-in
SFOUT
Structural fan-out
STMT
Number of statements
STMTd
Declarative statements
Number of declarative statements, which are: procedure headers, variable and constant
declarations, all statements outside procedures.
STMTx
Executable statements
STMTc
Control statements
Number of control statements. A control statement is an executable statement that can alter the
order in which statements are executed.
STMTnc
Non-control statements
Number of non-control statements, which are executable statements that are neither control nor
declarative statements. STMTnc=STMTx-STMTc
XQT
Executability
Executability measures the amount of executable statements. It equals the number of executable
statements divided by the number of all statements. XQT=STMTx/STMT
CTRL
Control density
Control density measures the amount of control statements. It equals the number of control
statements divided by the number of all executable statements. CTRL=STMTc/STMTx
File metrics
Class metrics
WMC
Weighted Methods Per Class Number of subs, functions and property procedures in class.
DIT
NOC
Number of Children
CBO
Number of classes to which a class is coupled. Coupling is defined as method call or variable
access.
RFC
Number of methods that can potentially be executed in response to a message received a class.
Counts only the first level of the call tree.
RFC'
Number of methods that can potentially be executed in response to a message received a class.
Counts the full call tree.
LCOM1
Lack of Cohesion of Methods A zero value indicates a cohesive class. A positive value indicates a class that should be split.
(1)
Also known as LCOM. Defined by Chidamber & Kemerer.
LCOM2
Lack of Cohesion of Methods The percentage of methods that do not access a specific attribute averaged over all attributes in the
(2)
class.
LCOM3
Lack of Cohesion of Methods Also known as LCOM*. Defined by Henderson-Sellers. Values of 1 and greater are considered
(3)
extreme lack of cohesion.
LCOM4
Lack of Cohesion of Methods Defined by Hitz & Montazeri. Value 1 indicates a good, cohesive class. Values 2 and greater are
(4)
considered bad (lack of cohesion). Such a class should be split. LCOM4 is more suitable for VB
than the other LCOMx variants.
TCCi
TCCi is 'TCC with inheritance'. TCC tells the connection density of the methods in a class. TCC
varies from 0 (totally non-cohesive) to 1 (maximally cohesive).
41
LCCi
LCCi is 'LCC with inheritance'. LCC describes the connectedness of the methods in a class.
LCC<1 indicates a non-cohesive class. LCC=1 indicates a cohesive class.
TCCl
Tight Class Cohesion (local) TCCl is 'TCC without inheritance'. TCC tells the connection density of the methods in a class.
TCC varies from 0 (totally non-cohesive) to 1 (maximally cohesive).
LCCl
Loose Class Cohesion (local) LCCl is 'LCC without inheritance'. LCC describes the connectedness of the methods in a class.
LCC<1 indicates a non-cohesive class. LCC=1 indicates a cohesive class.
MPC
Message-Passing Coupling
Number of procedure calls going outside of a class. Each call is counted once, whether it's early
bound, late bound or polymorphic.
LINES
Physical lines
Physical source lines, including code, comments, empty comments and empty lines. This metric is
what you would see with a simple text editor or line count program.
LLINES
Logical lines
Logical source lines, including code, comments, empty comments and empty lines. One logical
line may be split on several physical lines by a line continuation character. LLINES=LLOC +
LLOC' + LLOW
LLOC
Code lines count. One logical line may be split on several physical lines by a line continuation
character.
LLOC'
Comment lines count. All full-line comments count, even if empty. End-of-codeline comments not
included. One logical line may be split on several physical lines by a line continuation character.
LLOW
Logical lines of whitespace. This is mostly equal to physical lines of whitespace, that is lines that
have no other content than spaces, tabs and the line continuation character.
STMT
Number of statements
STMTd
Declarative statements
Number of declarative statements, which are: procedure headers, variable and constant
declarations, all statements outside procedures.
STMTx
Executable statements
STMTc
Control statements
Number of control statements. A control statement is an executable statement that can alter the
order in which statements are executed.
STMTnc
Non-control statements
Number of non-control statements, which are executable statements that are neither control nor
declarative statements. STMTnc=STMTx-STMTc
XQT
Executability
Executability measures the amount of executable statements. It equals the number of executable
statements divided by the number of all statements. XQT=STMTx/STMT
CTRL
Control density
Control density measures the amount of control statements. It equals the number of control
statements divided by the number of all executable statements. CTRL=STMTc/STMTx
IMPL
Implemented interfaces
WMCnp
WMCi
VARS
VARSnp
Non-private variables
VARSi
Variables defined+inherited
EVENTS
Events
Events defined by class. This metric counts the event definitions, not event handlers.
CTORS
Constructors
CSZ
Class size
CIS
Size of class interface measured by number of non-private methods and variables. CIS=WMCnp +
VARSnp
TCC
Total cyclomatic complexity Total cyclomatic complexity equals the total number of decisions + 1. TCC=Sum(CC)Count(CC)+1
Procedure metrics
LINES
Physical lines
Physical source lines, including code, comments, empty comments and empty lines. This metric is
what you would see with a simple text editor or line count program.
LLINES
Logical lines
Logical source lines, including code, comments, empty comments and empty lines. One logical
line may be split on several physical lines by a line continuation character. LLINES=LLOC +
LLOC' + LLOW
LLOC
Code lines count. One logical line may be split on several physical lines by a line continuation
character.
LLOC'
Comment lines count. All full-line comments count, even if empty. End-of-codeline comments not
included. One logical line may be split on several physical lines by a line continuation character.
LLOW
Logical lines of whitespace. This is mostly equal to physical lines of whitespace, that is lines that
have no other content than spaces, tabs and the line continuation character.
MCOMM
Meaningful comments
LLOCt
Logical lines of code in call tree. The number of lines that may potentially execute in a call to this
procedure. Includes all procedures that may execute.
PARAMS
Procedure parameters
VARSloc
Local variables
42
STMT
Number of statements
STMTd
Declarative statements
Number of declarative statements, which are: procedure headers, variable and constant
declarations, all statements outside procedures.
STMTx
Executable statements
STMTc
Control statements
Number of control statements. A control statement is an executable statement that can alter the
order in which statements are executed.
STMTnc
Non-control statements
Number of non-control statements, which are executable statements that are neither control nor
declarative statements. STMTnc=STMTx-STMTc
XQT
Executability
Executability measures the amount of executable statements. It equals the number of executable
statements divided by the number of all statements. XQT=STMTx/STMT
CTRL
Control density
Control density measures the amount of control statements. It equals the number of control
statements divided by the number of all executable statements. CTRL=STMTc/STMTx
IOg
Global I/O
IOp
Parameter I/O
Number of parameters used or returned by a procedure. The function return value counts as one
parameter (output parameter).
IOvars
Total number of input and output variables for a procedure, including parameters and function
return value. IOvars=IOg+IOp
IFIN
Informational fan-in
IFOUT
Informational fan-out
IFIO
IC1
Informational complexity
CC
Cyclomatic complexity
McCabe cyclomatic complexity equals the number of execution paths through a procedure. Also
known as V(C).
CC2
CC2 equals the regular CC metric but each Boolean operator within a branching statement causes
complexity to increase by one. Also called Extended cyclomatic complexity (ECC).
CC3
Cyclomatic complexity
without Cases
CC3 equals the regular CC metric, but each Select Case block is counted as one branch, not as
multiple branches.
DCOND
DLOOP
Depth of looping
DCALLT
Maximum number of nested procedure calls from a procedure. Recursive calls are not counted.
SCALLT
Number of distinct procedures in the call tree of a procedure, not counting the procedure itself.
SC
Structural complexity
Measures the external complexity of a procedure. Equals the number of other procedures called
squared. Defined by Card & Agresti, also known as S(i). Used to calculate SYSC. SC=SFOUT^2
DC
Data complexity
SYSC
System complexity
Composite measure of complexity inside procedures and between them. Defined by Card &
Agresti, also known as C(i), or design complexity. SYSC=SC+DC
LENP
SFIN
Structural fan-in
SFOUT
Structural fan-out
READS
WRITES
Writes to variable
RW
Number of reads and writes. A single instruction may count both as a read and as a write.
RW=READS+WRITES
FLOWS
Data flows
VARUSR
Variable users
LENVgm
Variable metrics
43
7 Other features
The basic features of Project Analyzer are related to analysis, optimization, documentation and
measurement as described in the preceding chapters. This is not all there is. Read on to find out more.
44
exposed reads (and writes). When there are no live reads from a variable, it is possibly useless.
Alternatively, there is a problem that prevents the read instructions from executing. When there are no
live writes to a variable, it is possibly always zero or empty. This may indicate a problem where
something prevents the write instructions from executing.
View FRX files. Classic VB stores form and control properties in files with the .frx extension. There are
also some other extensions serving the same purpose, such as .ctx, .pgx and .dox, but here we refer to
them collectively as the FRX files. You can view the contents of a FRX file by double-clicking it within
Project Analyzer. You can even save graphics to individual files if you want to reuse a picture that you
dont have available as a disk file.
View graphics files. You can double-click most graphics files, including .bmp, .gif and .jpg, to view the
picture. This is particularly useful with ASP.NET web projects that include graphics as a part of their
web content.
http://www.aivosto.com/project/help
Programming articles
http://www.aivosto.com/resources.html