Debugging Excel VBA返回行为异常,跳回
在完成if语句后,这种行为真的很奇怪 我在上面运行了调试器,下面是它的跳转方式:Debugging Excel VBA返回行为异常,跳回,debugging,vba,excel,Debugging,Vba,Excel,在完成if语句后,这种行为真的很奇怪 我在上面运行了调试器,下面是它的跳转方式: Private Function GetLastSameRow(ByVal row, initialValue) As Integer . . . If (nextCell.Value = initialValue) Then GetLastSameRow = GetLastSameRow(row + 1, initialValue) End If MsgBox ("
Private Function GetLastSameRow(ByVal row, initialValue) As Integer
.
.
.
If (nextCell.Value = initialValue) Then
GetLastSameRow = GetLastSameRow(row + 1, initialValue)
End If
MsgBox ("returning : " & row)
GetLastSameRow = row
End Function
因此,它基本上希望返回
correct
值,但如果返回End,则会立即返回correct-1
值。您编写了一个递归函数!如果使用调用堆栈,您将看到调试器将转到函数的另一个实例。问题在于:
GetLastSameRow=GetLastSameRow(行+1,初始值)
调用函数的另一个实例 您已经编写了一个递归函数!如果使用调用堆栈,您将看到调试器将转到函数的另一个实例。问题在于:
GetLastSameRow=GetLastSameRow(行+1,初始值)
调用函数的另一个实例 它是递归的这一事实不是问题?它是递归的这一事实不是问题?我一看到它就不相信自己知道这是正确的答案。我一看到它就不相信自己知道这是正确的答案
1. End If '
2. MsgBox ("returning : " & row) ' row value is 3
3. GetLastSameRow = row '
4. MsgBox ("returning : " & row) ' row value is 2 ????????
5. GetLastSameRow = row '