Skip to content

UserForm default instance is shown #5946

@retailcoder

Description

@retailcoder

What
Flag instances of SomeForm.Show, where the instance being shown is the default instance of the form.

Why
Instance state stored in a form's default instance is often a source of bugs and/or unexpected behavior. By showing an instance that was specifically created to be shown in a particular context, code is more robust and better adheres to OOP principles.

Example
This code should trigger the inspection:

Public Sub DoSomething()
    UserForm1.Show
End Sub

QuickFixes

  1. Create and use new instance

    Example code, after quickfix is applied:

    Public Sub DoSomething()
        With New UserForm1
            .Show
        End With
    End Sub

Resources
Each inspection needs a number of resource strings - please provide a suggestion here:

  • InspectionNames: userFormDefaultInstanceShown
  • InspectionInfo: Instance state stored in a form's default instance is often a source of bugs and/or unexpected behavior. Avoiding to show the default instance ensures the form's state remains in the local scope showing that form.
  • InspectionResults: '{0}' is showing the default instance of '{1}' (0: expression; 1: form name)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature requests, or enhancements to existing features. Ideas. Anything within the project's scope.feature-inspectionsup-for-grabsUse this label in conjunction with a difficulty level label, e.g. difficulty-02-ducky

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions