Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

According to the RubberDuck refactoriings page, the definition of the Introduce Parameter refactoring is:

Introduce Parameter

Select a local variable to promote to a parameter. Call sites for the containing procedure will be updated with a TODO argument, which must then be specified for all call sites.

Refactorings · rubberduck-vba/Rubberduck Wiki · GitHub

I’m a little unsure based on the definition exactly what to expect, but let’s see if we can try it out. I’ll start with a local variable and see if I get a dialog or something.

Putting a variable at the global scope of the class didn’t do anything, so I did some more searching and found a blog article with a definition that is a little more descriptive.

Introduce Parameter/Field

Pretty much the antagonist of move closer to usage, this refactoring promotes a local variable to a parameter or a field, or a parameter to a field; if a new parameter is created, call sites will be updated with a “TODO” bogus argument that leaves the code uncompilable until an argument is supplied for the new parameter at all call sites.

introduce parameter – Rubberduck News (rubberduckvba.blog)

Ok, I have a better idea now. I’ll create a variable in a method scope and try the refactoring on that. We will start with this class module code:

HAL_BasicEncryption

Option Compare Database
Option Explicit

Implements IHAL_Encryption

Private Function IHAL_Encryption_decrypt(sEncryption As String, sKey As String) As String
    Debug.Print TestFunction()
End Function

Private Function IHAL_Encryption_encrypt(sInput As String, sKey As String) As String
    Debug.Print TestFunction()
End Function

Private Function TestFunction() As String
    Dim PassString As String     ' Do the Refactoring here
    Debug.Print PassString
End Function

And after doing the refactoring on Dim PassString As String we get:

Option Compare Database
Option Explicit

Implements IHAL_Encryption

Private Function IHAL_Encryption_decrypt(sEncryption As String, sKey As String) As String
    Debug.Print TestFunction()
End Function

Private Function IHAL_Encryption_encrypt(sInput As String, sKey As String) As String
    Debug.Print TestFunction()
End Function

Private Function TestFunction(ByVal PassString As String) As String
    ' Do the Refactoring here
    Debug.Print PassString
End Function

RubberDuck did not do the TODO comment addition it mentions in it’s documentation, but doing a Debug > Compile will quickly show us the function calls that are not using the new parameter. Let’s see what Introduce Field does instead. I’ll revert the code and we will see what that does.

Option Compare Database
Option Explicit

Implements IHAL_Encryption

Private PassString As String
Private Function IHAL_Encryption_decrypt(sEncryption As String, sKey As String) As String
    Debug.Print TestFunction()
End Function

Private Function IHAL_Encryption_encrypt(sInput As String, sKey As String) As String
    Debug.Print TestFunction()
End Function

Private Function TestFunction() As String
    ' Do the Refactoring here
    Debug.Print PassString
End Function

Introduce Parameter will move a variable local to a method into the method’s parameter list.

Introduce Field will move a variable local to a method into the global scope of the class.