Rubberduck icon indicating copy to clipboard operation
Rubberduck copied to clipboard

UserForm default instance is shown

Open retailcoder opened this issue 2 years ago • 0 comments

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)

retailcoder avatar Feb 18 '22 23:02 retailcoder