VBA 函数语法

VBA function syntax

我正在使用以下等式编写函数:

  1. P = 10 ^ (A - B9 / ( T + C ))
  2. Z = C * Exp ( -k * t)

我正在使用以下语法:

答案 1:

Function P(a As Integer, b As Integer, c As Integer, t As Integer) As Integer
    P = (10 ^ a) / 10 ^ (b / (t + c))
End Function

答案 2:

Function Z(c As Integer, k As Integer, t As Integer) As Integer
    Z = c / Exp(-k * t)
End Function

答案并不准确。

请让我知道我缺少的地方。

方程式与原来的不同,你也应该post某些数字的预期结果,试试这个:

Function P(a As Integer, b As Integer, c As Integer, t As Integer) As Integer
    P = 10 ^ (a - b / (t + c))
End Function

Function Z(c As Integer, k As Integer, t As Integer) As Integer
    Z = c * Exp(-k * t)
End Function

此外,您还必须考虑保存 Integer 的最大值,即:32767 因此当该变量超过该值时程序将溢出,您可以阅读有关数据限制的更多信息 here