首页 > 解决方案 > VBA抛出错误中的简单浮点运算

问题描述

我在 Excel VBA 模块中有以下代码:

Function f(a, b, c, d)
f = 1.95 * a * (b / c) ^ 0.06 * (d / c) ^ 0.06
End Function

Sub callf()
Debug.Print (f(-7, 10, 3.5, -6))
End Sub

当我运行 sub 时callf出现错误:

运行时错误“5”:无效的过程调用或参数

我不知道为什么会发生这种情况。我不是在这里做简单的浮点运算吗?有任何想法吗?

标签: excelvbafunctionfloating-point

解决方案


因为你正在提升-1.7权力0.06。结果一个复数。


推荐阅读