Function VBA递归函数不';行不通
我想从这里编写此函数: 我已经写了以下内容,但它不起作用Function VBA递归函数不';行不通,function,vba,excel,Function,Vba,Excel,我想从这里编写此函数: 我已经写了以下内容,但它不起作用 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 + valu
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
函数值(b为整数,r为整数)
如果r=0,则
值=0
如果结束
如果b=0且r>0,则
值=r
如果结束
如果(b<0或r,这应该有效:
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
函数gameValue(b为整数,r为整数)
如果b<0或r0,则
gameValue=r
退出功能
如果结束
游戏价值=(b/(b+r))*(-1+游戏价值(b-1,r))+(r/(b+r))*(1+游戏价值(b,r-1))
端函数
请注意,我已将函数名从value
更改为gameValue
。原因是有一个名为value
的内置excel工作表函数