Functionality problems

Code review rules

Functionality problems concern the users of your software. This is where it really pays off to scan your application with Project Analyzer's problem detection feature. When you fix these issues before finishing your project the users will find your program working better than what it would've been without the fixes.

Most of the functionality problems are related to user interface issues, error trapping and event handling.

General functionality

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. NO_ERROR_HANDLER

Delayed error handling. 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. DELAYED_ERROR_HANDLING

Consider using Aivosto VB Watch, a tool that ensures proper error handling.

Stop/End statement found. Your program ends here. Check if you really want to end your program like this. It may be completely as you planned, though, and if you think everything is OK, leave it as is. END, STOP

Events not handled. An object variable is declared WithEvents. However, none of the events are handled. NO_EVENTS

RaiseEvent fails via constructor. Event handlers cannot catch an Event that fires during object construction. That is, RaiseEvent has no effect in Sub New or one of the procedures called by Sub New. As an exception, you can raise a Shared Event from a Sub New. A Shared Event is not tied to a specific instance, and raising it through an instance constructor works. As an exception to the exception, Shared Sub New cannot raise a Shared Event. Tip: Handling a Shared Event is not possible with the WithEvents keyword. Use the AddHandler statement. RAISEEVENT_CTOR

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. This rule catches strings starting with "A:\" to "Z:\". It also reports relative paths in declaring a DLL procedure. In addition, the rule reports relative path names found with the following classic VB file access statements: Open, Name, Kill, Shell, ChDir, MkDir and RmDir. These statements may indicate the assumed 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. PATH

Assignment to self. An assignment statement seems to set the value of a variable or property to itself without modification. Example: x = x. This is most probably an error. The assignment is either unnecessary or it is incorrect and should be fixed. ASSIGNMENT_TO_SELF

Verify accuracy. A floating point constant may be imprecise. If the value suggested by Project Analyzer is for the same purpose as the value in the code, determine which version is more appropriate. 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 (+/- 0.1 %). Use of imprecise constants may produce incorrect results or subtle errors in calculations. Carefully consider the given accurate value. Keep in mind that changing the number may change the results as well, so you must verify your code actually works correctly with the new value. Sometimes there are several alternative values for a constant. Care must be taken to choose the correct alternative for the application in question. This rule may produce false alarms when two different constants have close values. Make sure you only change your code when you are sure the new value is correct. This feature is good for verifying scientific programs. It supports hundreds of mathematical, physical and chemical constants. Constants include ones used in physics, such as parsek, Avogadro constant, electron mass, and conversion factors such as kilometres per mile and grams per pound. The rule works with floating point values from 5 to 15 significant digits. It assumes the Double datatype. To customize the list of constants see file constant.txt in your Project Analyzer directory. ACCURACY

DLL procedures

Procedure not found in library. A procedure is declared, the library exists on your system, but there is no such a procedure in the file. You have declared a non-existing procedure or the library file you have is not the required version. If you execute this procedure call on this machine, you will most probably get a run-time error. However, the code may still work on another computer with the correct library version available. This rule requires DLL analysis enabled. Enterprise Edition only. NOT_IN_LIB

Declare contains ordinal number. Declare a Function or Sub with its name, not its number. If the numbering is later changed in the DLL, your program will fail. Only when the function has no name can you use the ordinal number. This problem is triggered when a Declare statement refers to function such as "#1". The problem is ignored if DLL analysis is on and the target DLL procedure has no name. ORDINAL

User Interface issues (VB 3-6)

Form missing Icon. A Form doesn't have an icon that is required. A default icon, generated by VB, will be shown. This problem is available for VB 3-6. NO_ICON

Form missing HelpContextID. Your program uses context-sensitive help (F1), but a Form was found that has no HelpContextID set. This problem is available for VB 3-6. NO_HELPCONTEXTID

Default button missing. A dialog box has CommandButtons but none of them is marked Default. When the user hits Enter, none of the buttons handle it as a Click event. This problem is available for VB 3-6. BUTTONS

Cancel button missing. A dialog box has CommandButtons but none of them is marked Cancel. When the user hits Esc, none of the buttons handle it as a Click event. This problem is available for VB 3-6. BUTTONS

Hotkey conflict. Two or more controls or menu items share a hotkey. For example, there are options &Save and &Search in the same menu. This problem is available for VB 3-6. HOTKEY_CONFLICT, HOTKEYS

Hotkey missing. A control or menu item is missing a hotkey. Checked controls: CommandButton, CheckBox, OptionButton, Frame, Menu. This problem is available for VB 3-6. NO_HOTKEY, HOTKEYS

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. This problem is available for VB 3-6. NO_RESIZE

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. It is also important to use an error handler inside the Error event, because if a new error occurs, the Error event fires again. This problem is available for VB 3-6. NO_ERROR

Click event missing. A CommandButton or menu item does not do anything when clicked. This problem is available for VB 3-6. NO_CLICK

Timer event missing. A Timer does not fire an event at defined intervals. This problem is available for VB 3-6. NO_TIMER

Timer interval below 55 ms. The interrupt interval of a Timer control is shorter than 55 ms. Shorter intervals are not supported by VB. This problem is available for VB 3-6. TIMER_INTERVAL

Possibly twisted tab order. The tab order of some controls on a form looks questionable. Take a look at the TabIndex properties of the mentioned controls. The best way to do this is to open the form in VB, select the first control and press the Tab key repeatedly. Generally, the focus should move either right or down. Labels with an access key (& in the caption) should precede the control next to them. A container control should precede any child controls placed within it. A back jump is allowed to move the focus from the bottom of the form to the top-left corner. If the form's RightToLeft property is True, Project Analyzer uses a mirrored rule to require moves either left or down. The twisted tab order detection rules are not foolproof. In some cases, a twisted-looking tab order might be all right. Forms that hide, show or move their controls at run-time are exceptional in that their design-time layout is different from the run-time layout. In that case, this rule may produce a false warning and you should ignore it. This problem is available for VB 3-6. TABORDER

Comment directive

The comment directive parameter for the rules on this page is FUNC.

See also

Problem detection
Code review rules

©Aivosto Oy - Project Analyzer Help Contents