Enterprise Edition only
Problem auto-fix can automatically fix the problems listed below. Problems that are not in the list require a manual fix. Auto-fix also helps you with the manual fixes by creating specially formatted comments in the code.
You can select which problems you wish to auto-fix, which ones you wish to fix manually, and which ones you wish to ignore. See Auto-fix options.
Dead procedure/declaration/event. A procedure, Declare or Event statement is not used. Auto-fix removes it. To delete dead code, use the Fix quietly option. To comment out dead code, choose the Fix & comment option.
Procedure callers all dead (called by dead only). A procedure, Declare or Event statement is effectively dead, but it is still called by other dead procedures. Removed in the manner described above.
Event not raised. An event does not fire. Automatic removal is not done. Auto-fix creates a comment for you to consider whether this event needs to be fired or deleted.
Dead variable/constant. A variable or constant is not used. Auto-fix removes or comments out dead variables and constants, as above.
Variable read, not written; Variable written, not read; Variable users all dead; and other related rules. Automatic removal not possible when a variable is in partial use. Auto-fix creates a comment for manual treatment.
Dead Enum/Type/Structure. Auto-fix creates a comment for manual removal.
Dead Type field/Enum constant. Auto-fix creates a comment for manual removal.
Unused file. Auto-fix creates a comment for manual removal of file.
Dollar would increase performance. Adding $ at the end of a function would increase the speed of execution. Certain functions, like Left, Mid and Right return a Variant that contains a String. The corresponding functions Left$, Mid$ and Right$ return a String. Using the String version makes your program run faster. This rule applies to VB 4-6 code. In VB.NET, there is no performance difference. Auto-fix adds the $ in your VB 4-6 projects.
Warning: VB 4-6 database applications often use the $-less functions for Null propagation. The $ versions don't support Null propagation and will cause a run-time error if given a Null parameter. If you suspect that Null parameter might be given to these functions, use manual fix.
Literal "" found. The string literal "" is present in your code. If the statement is an assignment, use vbNullString instead of "". vbNullString is a special constant, available in VB4 and later, that saves memory, speeds up the assignment and later processing of the value. Auto-fix replaces "" with vbNullString in classic VB.
In VB.NET an automated fix is not available. vbNullString is equal to Nothing, which can cause a run-time error in VB.NET if members of the string are accessed using object-oriented syntax. This is why it's safer to stick with "". You can write the change manually when you are sure a run-time error is not going to be triggered.
Note: If the literal "" is used in comparison ( = "" or < > "" ), manual fix is required. The fastest way is to use Len( ) = 0 and Len( ) <> 0 to test for an empty and a non-empty string, respectively. In VB 4-6, use the LenB function instead of Len for the same purpose with extra performance. In VB3 and VB.NET, use the Len function.
Variable/function missing type declaration. A function has no return type definition, or a variable has no type definition. Auto-fix makes the type declaration explicit. By default, the type is Variant in VB 4-6 and Object in VB.NET. If you have used the DefType statement, another type may be added. Warning: Variant/Object is not an optimal data type in most cases. It is slower, uses more memory, and leads to late binding when accessing procedures or other members of an object. You may wish to use manual fix for this problem type, and write in the correct type by yourself.
Trailing comment found. An endline comment has been found after code. Comments should be written as the only thing on a line (full-line comments). As the space to the right of a line is limited, endline comments tend to be cryptic. There simply isn't enough space to write a good comment. It's better to write a descriptive full-line comment, on one or more lines, before the appropriate block of code. Auto-fix will move trailing comments immediately above the code. Existing indentation level will be preserved. The following example shows how auto-fix changes a trailing comment to a full-line comment:
Code ' Comment
' Comment Code
Tip: Use the Fix quietly auto-fix setting to avoid an extra comment about each processed comment.
Line too long. A line of code is longer than allowed. A typical limit is 80 characters per line, but you can also use higher limits such as 90 or 100. Long lines are hard to read and understand. Overly long lines don't fit in the view of your development environment and you need to scroll. Auto-fix splits long lines to fit the line length you have selected. Auto-fix splits long code lines using the line continuation character (_). It turns long comments into multiple comments. When a long line contains a trailing comment, auto-fix proceeds as described above under the Trailing comment found rule, then splits the comment and the code line separately. Auto-fix preserves your commentation style. It is aware of
Rem style comments and also
''' style documentation comments.
Tips: Use the Fix quietly auto-fix setting to avoid an extra comment about each split line. Select a reasonable maximum line length. Trying to force deeply indented 200-character lines into 80 characters will make your code harder to read, not easier. Auto-fix is best at splitting occasional long lines such as procedure headers or some complex expressions. If your code requires a complete reformat, try Aivosto VB Friend.
Note: Running auto-fix does not guarantee all lines will be shorter that the selected maximum. Some lines will be left long if they cannot be reasonably split. Auto-fix mostly splits at spaces. If the line has few spaces, it is hard to provide a good split.
Option Explicit Off. Option Explicit is not set for a file, or it is deliberately set Off. You should always use Option Explicit. It makes VB require explicit variable declaration. This way you avoid using unnecessary implicit Variants (classic VB) or Objects (VB.NET). Even better, you get rid of some nasty errors caused by typing errors and variables with similar names.
Option Explicit or
Option Explicit On in all files where it is missing. However, this alone will not deal with all the issues.
When you load the project into VB, you will find many undeclared variables which you will have to declare manually before your program compiles.
This particular auto-fix is available only when you select both auto-fix and the manual alert ($) option, as you're likely to run into alerts from the VB compiler.
In VB6, you may use Aivosto VB Friend (not included with Project Analyzer). This add-in has an assistant to quickly add missing variable declarations.
Option Strict missing. Option Strict is Off for a VB.NET file. There is no Option Strict statement in the file and Option Strict is Off in project settings. Auto-fix adds
Option Strict On to all files where it is missing. When you load the project into VB.NET, it will most probably complain about implicit type conversions and missing data types. You will have to check these lines before your program compiles. This particular auto-fix is available only when you select both auto-fix and the manual alert ($) option, as you're likely to run into alerts from the VB compiler.
Function with type character. A function is declared ending in one of the old-style $#%!&@ characters. Auto-fix replaces the type character with an As Type declaration. Only the function declarations are auto-fixed — function calls are not modified. The calls will continue to work normally.
Variable/parameter with type character. A variable or procedure parameter is declared ending in one of the old-style $#%!&@ characters. Auto-fix replaces the type character with an As Type declaration. Only the variable declarations are auto-fixed — any references to the variables or parameters are not modified. They will continue to work normally.
Scope declaration missing. A part of your program does not have a defined scope. Instead, it is using a default scope as given by VB. VB's default rules are somewhat complicated and may lead to excess or too narrow a scope. With a narrow scope, you can encapsulate functionality and data. With a large scope, you give access to this part of your program from other parts. Determine which scope is appropriate and declare it explicitly. The current default scope is given. Auto-fix adds explicit scope declaration according to VB's default rules.
Exception: If a declaration has both "Excess scope" and "Scope declaration missing", auto-fix will create a comment for manual treatment. In this case, consider which scope is the best one and add it manually.
Excess scope. A part of your program is accessible from other modules. However, other modules don't use it. Check to see if you should declare the part as Private instead of Public. It is good programming practice to use as tight a scope as possible to prevent other parts of the program calling and modifying parts that they shouldn't have anything to do with. Auto-fix creates a comment with instructions on what to change and where to move the declaration, if required.
Encapsulate non-private variable as property. Variables that aren't declared as Private should be avoided in classes. Read/Write access to a class's member variables should only be allowed via properties. Make the variable Private and add a property to read/write the contents. Auto-fix renames the variable, turns it to Private and makes a set of Property Get/Set/Let declarations to access the variable's contents.
Warning Passed ByRef. Encapsulated Property will not receive changes back from ByRef. In classic VB, passing a variable ByRef may change the value of the variable. Passing a Property ByRef will not change the value, however. This can lead to errors that are hard to debug. When you encapsulate a variable as a property, make sure the logic still functions with ByRef calls. Project Analyzer detects ByRef passing and shows the warning text for the problem. This is not an issue with VB.NET because VB.NET uses copy-in/copy-out semantics for Properties passed ByRef, so variables and encapsulated properties work the same.
Automatic encapsulation works for most variables but not all. First of all, it is dependent on the underlying data type and is enabled only if it is known to be a scalar type or an object type. Automatic encapsulation doesn't work for arrays or variables used as a For index variable. It doesn't work for variables passed ByRef either. In these cases you will need to manually encapsulate the data or leave the code unchanged.
ReDim without Dim. A ReDim statement allocates a local array without a prior Dim declaration. It is equivalent to using undeclared local variables without Option Explicit. An exceptional statement in classic VB, ReDim is not controlled by Option Explicit. Auto-fix adds the missing Dim statement immediately above ReDim. If the ReDim statement has an
As Datatype part, the Dim statement will have it too. If the datatype is missing, auto-fix does not add any. Adding it is up to you. This feature is available for VB 4-6.
Global found, use Public. Use of the Global keyword is outdated in classic VB. VB.NET no longer supports Global but requires Public. Auto-fix replaces Global with Public in VB 4-6 projects.
Multiple statements on line. There are more than one statement on a single line, separated with a colon ( : ). To make your program more readable, auto-fix splits the statements to separate lines.
Single-line If..Then statement found. An If..Then(..Else) construct is on a single line. To make your program more readable, auto-fix splits the construct to multiple lines and adds indentation.
To fine-tune indentation according to your own standards, use the add-in Aivosto VB Friend (available for VB6, not included with Project Analyzer).
Call statement found. The Call statement is no longer needed. Auto-fix removes it.
NameCheck. A name fails Project NameCheck. Auto-fix creates a comment and suggests a new name.
Error handler missing. A procedure has no error handler. Your program may crash if a run-time error occurs in this procedure. You can ignore this problem in procedures with less than or equal to x lines of code. Write x in the "Ignore when" textbox in Problem Options. Sub/Function and End Sub/Function lines are counted as code, making an empty procedure or property block have 2 lines. Leave the box empty if you don't wish to have a limit. Auto-fix creates a comment in procedures requiring an error handler. Consider using Aivosto VB Watch, a tool that ensures proper error handling.
Delayed error handler. A procedure uses delayed error handling (On Error Resume Next, Try 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 this problem in procedures with less than or equal to x lines of code. Write x in the "Ignore when" textbox in Problem Options. Sub and End Sub lines are counted as code, making an empty procedure or property block have 2 lines. Leave the box empty for no limit. Auto-fix creates a comment in procedures requiring an error handler. Consider using Aivosto VB Watch, a tool that ensures proper error handling.
Case branch(es) missing for Enum. A Select Case statement branches off an Enum value, but it does not contain a Case for every Enum constant. This may indicate missing logic, possibly due to an Enum constant added later. Auto-fix adds a comment about the missing cases. Uncomment it to quickly add the missing branches.
Case Else missing. A Select Case block is missing its Case Else branch. An unexpected input value can go unhandled. This rule lets you prevent bugs from causing havoc beforehand. Auto-fix adds a comment about the missing Case Else. Uncomment it and write the required logic.
Resizable Form missing Form_Resize. The Form_Resize event is missing from a Form that users can resize at run-time. Your application may look odd if you don't respond to Resize events. Auto-fix inserts an empty Form_Resize event and creates a comment, so you remember to implement it. This feature is available for VB 4-6.
Error event missing. Every Data control should have the Error event implemented. If you don't do it, Visual Basic only displays a simple error message. Auto-fix inserts an empty Error event and creates a comment, so you remember to implement it. This feature is available for VB 4-6.
Click event missing. A CommandButton or menu item does not do anything when clicked. Auto-fix inserts an empty Click event and creates a comment, so you remember to implement it. This feature is available for VB 4-6.
Timer event missing. A Timer does not fire an event at defined intervals. Auto-fix inserts an empty Timer event and creates a comment, so you remember to implement it. This feature is available for VB 4-6.
All other problems are handled as a manual fix by adding a comment.
All detected problems
©Aivosto Oy - Project Analyzer Help Contents