Displaying Unused Local Variables and Parameters

The Methods menu of the Class Browser or Primitive Types Browser enables you to audit the local variables in the current method, display those that are unused, and remove one unused local variable or all unused local variables in the method.

To audit and maintain local variables in the method displayed in the editor pane

  1. Select the Unused Local Variables command from the Methods menu. (This command is disabled if the method is uncompiled or in error.)

    If there are no unused variables, a message box displays There are no unused local variables.

    If there is one or more unused local variable in the method, the first unused local variable is highlighted in the editor pane and the Find Unused Variables dialog displays the name of the first unused local variable.

  2. To display the next unused variable, click the Find Next button. If there are no more in the current method, the dialog is closed and a message box displays There are no more unused local variables.

  3. To remove the displayed unused variable from the method source, click the Remove button.

    The logic then continues as though you had clicked the Find Next button.

  4. To remove all unused variables from the method source, click the Remove All button.

    The dialog is then closed and a message box lists the names of all variables that have been removed from the method.

  5. To close the Find Unused Variables dialog, click the Cancel button. (No previous remove actions are undone.)

Any changes made to the method can be undone and the method will be unsaved. (Pressing F8 saves and recompiles a changed method.)

The Schema menu in the Schema Browser enables you to audit the local variables that are unused in all methods in a schema or class.

To audit local variables and parameters in all methods or a class of the schema selected in the Schema Browser

  1. Select the Find Unused Local Variables/Parameters command from the Schema menu.

    The Find Unused Local Variables and Parameters dialog, shown in the following image, is then displayed.

  2. If you do not want to search for unused local variables and parameters in all methods in all schemas (the default value), perform one of the following actions in the Search Criteria group box.

  3. In the Reporting Options group box, uncheck the:

  4. In the Output Options group box, select the Print Preview option button if you want to preview the unused local variables and parameters report output.

    By default, the Methods List Browser option button is selected, indicating that the unused local variables and parameters are displayed in a Methods Browser, shown in the following image.

    To display the method source with the unused item visible in the editor pane below the list on the form, click on a method in the list. You can edit this method source.

  5. Click the Search button to initiate the search. Alternatively, click the Cancel button to abandon your selections.

When a scan is performed using the Find Unused Local Variables/Parameters command from the Schema menu and the located unused variables and parameters are displayed in the Unused Local Variables/Parameters form, double‑clicking a method entry in the list for an unused local variable entry results in all listed unused local variables being removed from the method source and the method is then recompiled. All of the unused local variable entries in the list for that method are removed from the list except for the last entry, so that you can view the method changes. You can also undo the changes, if required. (Multiple undo actions may be required.)

If there is no remaining text between the vars and begin statements, the vars section is removed. No comments are removed.

You can also remove unused local variables by selecting the Remove Unused Local Variables command in the Methods menu.

If you click the only remaining entry for a method again and there are no changes required, the entry is removed from the list.

The result of print preview search output to a print‑ready report contains the: