Inspection Details
MoveFieldCloserToUsage
- Summary
- Locates module-level fields that can be moved to a smaller scope.
- Reasoning
- Module-level variables that are only used in a single procedure can often be declared in that procedure's scope.
Declaring variables closer to where they are used generally makes the code easier to follow.
- The following code example(s) would trigger this inspection:
-
Option Explicit
Private foo As Long
Public Sub DoSomething()
foo = 42
Debug.Print foo
End Sub
- The following code example(s) would not trigger this inspection:
-
Option Explicit
Public Sub DoSomething()
Dim foo As Long
foo = 42
Debug.Print foo
End Sub
Back to List