|
This is probably the most important of CodeShine's functions. Its purpose is to take the highlighted block of code and create a new Private Sub from it, ensuring in the process that:
| • | All local variables of the original routine used only in the code block and nowhere else in the routine are transferred to the code block. This includes the Dim statements for those variables, whether or not they have been highlighted. |
| • | Any variables declared within the highlighted area but not referenced in the code block will not have their declarations transferred. |
| • | All local variables and parameters of the original routine used in both the original routine and the code block will be passed to the new Sub as parameters (there are options and circumstances in which Extract Method will generate a Function rather than a Sub. |
CodeShine's implementation of Extract Method includes some important checks - it won't let you extract an If without the corresponding End If, or similar partial blocks, and it will warn you before extracting code containing custom error handlers, Exit Sub or Exit Function statements.
The Extract Method Screen
Example
The Proxy Variable
Tips
Generalized Extract Method ("Gen-Extract Method")
|