Rubberduck
Rubberduck copied to clipboard
UserForm default instance is shown
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
-
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)