我正在完成一本书中的练习。我得到了任务 - 编写自己的除法函数,而不使用运算符 (/) 和 (*)。我的实现如下。
Public counter As Long
Public Function myDivide() As Long
Dim a As Long,b As Long
counter = 1
a = Cells(1,activeCell.Column).Value
b = Cells(2,activeCell.Column).Value
divide a,b
myDivide = counter
End Function
Private Function divide(ByRef a As Long,ByRef b As Long) As Long
If a > b Then
If a - b <> 0 Then
counter = counter + 1
divide a - b,b
End If
End If
End Function
执行结果,当将“=myDivide()”函数放置到屏幕截图第3行的每个单元格时
我的问题:为什么“F3”单元格返回错误#VALUE? 据我所知,Long 可以包含到 2147483647 的数字,并且它大于 10 000 000。我所有的变量都是 Long。可能是,一些堆栈限制? 谢谢!