VBA溢出错误,类型为double,Excel [英] VBA Overflow error with type double, Excel

查看:209
本文介绍了VBA溢出错误,类型为double,Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道溢出错误非常好,所以我很失落。



在VBA中编写我正在调用一个VBA函数,它是一个来自dll的C ++函数的包装(我无法访问内部的)。 VBA / C ++函数返回一个double。它是使用数值方法的衍生品估值。



昨天一段时间(但现在可能已经消失),当尝试将函数返回给声明为double的变量时,我得到溢出错误。 但是在错误停止时,我可以看到分配给double的正确值,在本地窗口(8.17 ...)中。而当我将函数返回赋值给一个变体时,我得到相同的值,没有错误,变体类型为Variant / Double。



任何想法在这里可能发生什么?我完全迷失了提前感谢任何想法。 R



编辑:我尝试的另一件事是将CDbl应用于将其分配给变体后的函数返回。这里是一些伪代码,只是为了澄清我的案例:

  Dim db as Double,va as Variant 

db = DerivativeValue(a,b,c ...)

这给了溢出但db在本地窗口中具有正确的值,对错误。

  va = DerivativeValue(a,b,c ...)
pre>

没有错误,相同的值。 va是类型Variant / Double

  va = CDbl(DerivativeValue(a,b,c ...))

现在再次溢出在这种情况下,我忘记了在本地人窗口中做了什么,但可能与情况1相同。

解决方案

我的猜测是该函数返回一个看起来像一个double但不是double的值。



变体旨在获取任何类型的值,分配将执行转换。我想知道一个变体的作业是否有效,因为它可以将返回的值转换为双倍。



如果您尝试以下操作,会发生什么:

  va = DerivativeValue(a,b,c ...)
db = va
pre>

如果这样工作,它将让您继续开发,而无需等待发现该功能实际返回。



额外点。 double是64位浮点数。如果您有FPU,则可能返回一个80位浮点数。


I don't know the overflow error very well, so I'm pretty at a loss here.

Writing in VBA I'm calling a VBA function, which is a wrapper of a C++ function from a dll (which I have no access to the innards of). The VBA/C++ function returns a double. It is a derivative valuation using numerical methods.

For a time yesterday (but it may have gone away now) I was getting the overflow error when trying assign the function return to a variable declared as double. But on the error halt, I could see the correct value assigned to the double, in the locals window (8.17...). And when I instead assign the function return to a variant, I get the same value with no error, the variant being type Variant/Double.

Any idea what could be going on here? I'm completely lost. Thanks in advance for any ideas. R

Edit: One more thing I tried was applying CDbl to the function return when assigning it to the variant. Here's some pseudo code, just to clarify my cases:

Dim db as Double, va as Variant

db = DerivativeValue(a, b, c...) 

This gives the overflow, but db has the correct value in the locals window, on the error.

va = DerivativeValue(a, b, c...)

No error, same value. va is type Variant/Double

va = CDbl(DerivativeValue(a, b, c...))

Now overflow again. I forgot what va did in the Locals window in this case, but likely it's the same as case 1.

解决方案

My guess is that the function is returning a value that looks like a double but is not.

Variants are designed to take any type of value and the assignment will perform conversions. I wonder if the assignment to a variant works because it can convert the returned value to a double.

What happens if you try the following:

va = DerivativeValue(a,b,c...)
db = va

If this works, it will let you continue development without waiting to discover what the function is actually returning.

Extra point. A double is a 64 bit floating point number. If you have a FPU, it might be returning an 80 bit floating point number.

这篇关于VBA溢出错误,类型为double,Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆