Introduce Explaining Variable

Top  Previous  Next

This takes any highlighted expression and assigns it to a variable. It:

Creates a Dim statement for the new variable
Follows the Dim with an assignment statement of the form

       <newVariableName> = <selected expression>

Replaces the selection with the new variable name

 

There are two main scenarios where this refactoring is useful:

When you're trying to decode a complex expression - for example, in an If .... Then statement - into something intelligible
When an expression that you need to re-use has a side effect or excessive performance hit, and you only want to call it once.

 

Example