Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time error '6' overflow

Status
Not open for further replies.

ersatz

Programmer
Oct 29, 2002
114
US
Hi,
I use a function in MS Access form.
I declared all my variables like double
When I run my function, I retrieve this error: Run-time error '6' overflow.
If I click debug I find that:
dv =x/y and if I put the mouse over dv I see:
dv = -1.#INF
Can anybody help me, please?
Thanks in advance
 

Hi,
Thanks for your responce.
Y it's closed to zero but it's not zero.
X=-2.345678
y=9.513......E-314
I don't know what can I do.
Any idea?
 
Gotcha. The result of the division is so large it no longer fits within the floating-point type of your variable. You can either:
- prevent the error from happening, for example by checking if the value of y is dangerously close to 0 (e.g., if abs(y)<1e-300)
- trap the error when it occurs and take appropriate action, with an on error goto construction.
Which way to go depends on your needs and the nature of your application.
Rob
[flowerface]
 
These are my 2 functions:

Function cdf(x) As Double
Dim d As Double
Dim a As Double
Dim B As Double
Dim C As Double

d = 1 / (1 + 0.33267 * Abs(x))
a = 0.4361836
B = -0.1201676
C = 0.937298
cdf = 1 - 1 / sqr(2 * 3.1415926) * EXP(-0.5 * x ^ 2) * (a * d + B * d ^ 2 + C * d ^ 3)
If x < 0 Then cdf = 1 - cdf
End Function


Function ImpV(ByVal mkt1 As Double, mkt2 As Double, mkt3 As Double, _
mkt4 As Double, mkt5 As Double) As Double
Dim Vol As Double
Dim dv As Double
Dim d1 As Double
Dim d2 As Double
Dim pError As Double
Dim vega As Double
Dim err As Double

Vol = 0.9
err = 0.00001
dv = err + 1
While Abs(dv) > err
If mkt2 = 0 Then
Exit Function
End If
d1 = (Log(mkt4 / mkt2) + mkt5 + 0.5 * Vol ^ 2 * mkt3) / (Vol * sqr(mkt3))
d2 = d1 - Vol * sqr(mkt3)
pError = mkt4 * cdf(d1) - mkt2 * EXP(-mkt5 * mkt3) * cdf(d2) - mkt1
pError = pError
vega = mkt4 * sqr(mkt3 / 3.1415926 / 2) * EXP(-0.5 * d1 ^ 2)
If vega = 0 Then
Exit Function
End If

dv = pError / vega
Vol = Vol - dv
If Vol >= 300 Then
Vol = 300
End If
Wend
ImpV = Vol
End Function



Thanks again

 
I'm not sure if you're still asking a question, and if so, which question. Using my first approach above, you would replace your &quot;if vega=0&quot; construction above by

if abs(vega)<1e-300 then exit function

(note that your function value doesn't get set at all when this happens - not necessarily the behavior you want)
Rob
[flowerface]
 

You could also try to cast a variant to a decimal using the CDec function.

Good Luck

 
Thanks very much
With abs(vega)<1e-300 all it's ok now.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top