-
Couldn't load subscription status.
- Fork 315
Closed
Labels
feature-refactoringsrefactoring-extract-methodwork-itemUsed for features not implemented to document requirementsUsed for features not implemented to document requirements
Description
Starting with
Public Sub TestExtractMethod_Before_NoSpace()
Const someValue As String = "Fed in value: "
Dim someRange As Range
Set someRange = Selection
someRange.Value2 = "A value"
Dim someCounter As Long
Dim Cell As Range
For Each Cell In someRange
Cell = someValue & someCounter
someCounter = someCounter + 1
Next
End Sub
and selecting
Dim Cell As Range
For Each Cell In someRange
Cell = someValue & someCounter
someCounter = someCounter + 1
Next
produces what's below.
Public Sub TestExtractMethod_After_NoSpace()
Const someValue As String = "Fed in value: "
Dim someRange As Range
Set someRange = Selection
someRange.Value2 = "A value"
End Sub
NewMethod someValue, someRange
Private Sub NewMethod(ByRef someValue As String, ByRef someRange As Range)
Dim someCounter As Long
Dim Cell As Range
For Each Cell In someRange
Cell = someValue & someCounter
someCounter = someCounter + 1
Next
End Sub
When I run it on the code below (note the space after Next and End Sub) with the same selection Dim Cell as Range through `Next' I end up with proper syntax, excluding indentation issues.
Public Sub TestExtractMethod_Before_WithSpace()
Const someValue As String = "Fed in value: "
Dim someRange As Range
Set someRange = Selection
someRange.Value2 = "A value"
Dim someCounter As Long
Dim Cell As Range
For Each Cell In someRange
Cell = someValue & someCounter
someCounter = someCounter + 1
Next
End Sub
Results in
Public Sub TestExtractMethod_After_WithSpace()
Const someValue As String = "Fed in value: "
Dim someRange As Range
Set someRange = Selection
someRange.Value2 = "A value"
NewMethod someValue, someRange
End Sub
Private Sub NewMethod(ByRef someValue As String, ByRef someRange As Range)
Dim someCounter As Long
Dim Cell As Range
For Each Cell In someRange
Cell = someValue & someCounter
someCounter = someCounter + 1
Next
End Sub
If I had the code without a space between the declarations Extract Method would work sometimes and not at others. Sporadic at best and couldn't determine any pattern.
Dim someCounter As Long
Dim Cell As Range
Should
someValuebe passedByValsince in this case its value can't change?
Also saw that
NewMethodwas used even when one already existed. Should there be an increment number appended to the name? Kind of a fringe case...
Metadata
Metadata
Assignees
Labels
feature-refactoringsrefactoring-extract-methodwork-itemUsed for features not implemented to document requirementsUsed for features not implemented to document requirements