VBArecursion函数不起作用

我想从这里写这个函数: https : //math.stackexchange.com/questions/721494/what-is-the-value-of-this-game

我写了下面的内容,但是不起作用。

Function value(b As Integer, r As Integer) If r = 0 Then value = 0 End If If b = 0 And r > 0 Then value = r End If If (b < 0 Or r <= 0) Then value = 0 End If value(b, r) = (b / (b + r)) * (-1 + value(b - 1, r)) + (r / (b + r)) * (1 + value(b, r-1 )) End Function 

有人可以解释为什么它不工作,我很新的VBA和编程。

这应该工作:

 Function gameValue(b As Integer, r As Integer) If b < 0 Or r <= 0 Then gameValue = 0 Exit Function End If If b = 0 And r > 0 Then gameValue = r Exit Function End If gameValue = (b / (b + r)) * (-1 + gameValue(b - 1, r)) + (r / (b + r)) * (1 + gameValue(b, r - 1)) End Function 

请注意,我已将函数名称从value更改为gameValue 。 原因是因为内置了名为VALUE excel工作表函数