Vedant
07-03-2008, 12:34 AM
Hello! This is my first time in this forum. I have tried to post but little bit confused please excuse me if this is posted double.
I am getting a Run-Time error '6': overflow in the following code of VBA code which is for MS Access 2003 / VB 6.0 and I have put ** in the line where error comes i.e.
For i = 1 To n - 1
*** dblF1(i) = Round(dblC(i) / dblIC(i), 5)
' Run-Time error '6': overflow
Next i
Might be dblIC(i) value is zero. Is that may be reason for this error?
As code is developed by my one of my senior and he has left the job. I really need someone help who can tell me what is the reason of error and how can I fix it? Your early reply will be appreciable.
Thanks a lot
Vedant
Public Sub CompletionFactorsFASTNew()
Dim curTotalClaim As Currency
Dim datCurrentDate As Date
Dim dblI As Double
Dim dblK As Double
Dim dblIC(1 To 100) As Double
Dim dblM(1 To 100) As Double
Dim dblG(1 To 100) As Double
Dim dblC(1 To 100) As Double
Dim dblF(1 To 100) As Double
Dim dblF1(1 To 100) As Double
Dim dblP(1 To 100, 1 To 100) As Double
Dim datTemp As Date
Dim i As Long
Dim j As Long
Dim k As Long
Dim l As Long
Dim dblTop As Double
Dim dblBottom As Double
Dim n As Long
Dim datDate As Date
Dim datMaxDate As Date
Dim dblTemp As Double
Set rstClaim = New adodb.Recordset
Set rstClaim.ActiveConnection = CurrentProject.Connection
Set rstcf = New adodb.Recordset
Set rstcf.ActiveConnection = CurrentProject.Connection
Set rstCaseChar = New adodb.Recordset
Set rstCaseChar.ActiveConnection = CurrentProject.Connection
n = 36
rstcf.CursorType = adOpenDynamic
rstcf.LockType = adLockOptimistic
rstcf.Source = "[CF Claim History]"
rstcf.Open
If Not rstcf.EOF Then
rstcf.MoveFirst
While Not rstcf.EOF
rstcf.Delete
rstcf.Update
rstcf.MoveNext
Wend
End If
For i = 1 To 100
dblC(i) = 0
dblM(i) = 0
dblG(i) = 0
For j = 1 To 100
dblP(i, j) = 0
Next j
Next i
rstClaim.CursorType = adOpenDynamic
rstClaim.LockType = adLockOptimistic
rstClaim.Source = "[qIncurredPaidClaims]"
rstClaim.Open
rstClaim.MoveFirst
datMaxDate = 0
While Not (rstClaim.EOF)
datIncurreddate = DateSerial(Year(rstClaim![IncurredDate]), _
Month(rstClaim![IncurredDate]), 1)
datMaxDate = max(datMaxDate, datIncurreddate)
rstClaim.MoveNext
Wend
rstClaim.MoveFirst
datDate = 0
While Not (rstClaim.EOF)
datPaidDate = DateSerial(Year(rstClaim![PaidDate]), _
Month(rstClaim![PaidDate]), 1)
datIncurreddate = DateSerial(Year(rstClaim![IncurredDate]), _
Month(rstClaim![IncurredDate]), 1)
dblK = DateDiff("m", datIncurreddate, datMaxDate) + 1
If dblK < 1 Then dblK = 1
If dblK > n Then dblK = n
datDate = max(datDate, datIncurreddate)
curClaim = CDbl(rstClaim![Paid])
dblI = DateDiff("m", datIncurreddate, datPaidDate) + 1
If dblI < 1 Then dblI = 1
If dblI > 100 Then dblI = 100
dblC(dblK) = dblC(dblK) + curClaim
dblP(dblI, dblK) = dblP(dblI, dblK) + curClaim
rstClaim.MoveNext
Wend
rstCaseChar.CursorType = adOpenDynamic
rstCaseChar.LockType = adLockOptimistic
rstCaseChar.Source = "[qEnrollmentbyReportMonth]"
rstCaseChar.Open
rstCaseChar.MoveFirst
While Not rstCaseChar.EOF
j = DateDiff("m", rstCaseChar![ReportDate], datMaxDate) + 1
dblM(j) = rstCaseChar![Members]
rstCaseChar.MoveNext
Wend
rstCaseChar.Close
rstClaim.Close
For lngL = 1 To 12
For lngT = 1 To 12
For i = 1 To 100
If i < n Then
dblF(i) = 0
dblF1(i) = 0
Else
dblF(i) = 1
dblF1(i) = 1
End If
Next i
For k = 1 To n - 1
dblTop = 0
dblBottom = 0
For j = 1 To lngT
dblTemp = 0
For i = 1 To n - k + 1
dblTemp = dblTemp + dblP(i, n + j - k + lngL)
If i < n - k + 1 Then dblTop = dblTop + dblP(i, n + j - k + lngL)
Next i
dblBottom = dblBottom + dblTemp / dblF(n + j - k)
Next j
If dblBottom <> 0 Then
dblF(n - k) = dblTop / dblBottom
Else
dblF(n - k) = 1
End If
Next k
For k = n To 100
dblIC(k) = dblC(k)
Next k
For k = 1 To n - 1
dblG(n - k) = 0
dblTop = 0
dblBottom = 0
For j = 1 To 12
dblTop = dblTop + dblIC(n - k + j)
dblBottom = dblBottom + dblM(n - k + j)
Next j
If dblBottom <> 0 Then dblG(n - k) = dblTop / dblBottom
dblIC(n - k) = dblC(n - k) + (1 - dblF(n - k)) * dblM(n - k) * dblG(n - k)
Next k
For i = 1 To n - 1
*** dblF1(i) = Round(dblC(i) / dblIC(i), 5) ' Run-Time error '6': overflow
Next i
For i = n To 100
dblF1(i) = 1
Next i
For i = 1 To 100
dblF(i) = Round(dblF(i), 5)
If i > 12 Then dblF(i) = 1
datTemp = DateSerial(Year(DateAdd("m", 1 - 1 * i, datDate)), _
Month(DateAdd("m", 1 - 1 * i, datDate)), 1)
rstcf.AddNew
rstcf.Fields![Duration] = i
rstcf.Fields![cf] = dblF(i)
rstcf.Fields![lag] = 1 - dblF(i)
rstcf.Fields![IncurredDate] = datTemp
rstcf.Fields![dataDate] = datMaxDate
rstcf.Fields![Description] = "L = " & Format(lngL, "00") & _
" T = " & Format(lngT, "00")
rstcf.Fields![crm] = dblF1(i)
Debug.Print i, dblF(i), datTemp, datMaxDate, "L = " & _
Format(lngL, "00") & " T = " & Format(lngT, "00") & dblF1(i)
rstcf.Update
Next i
Next lngT
Next lngL
rstcf.Close
End Sub
Public Function max(datDate1, datDate2) As Date
max = datDate1
If max < datDate2 Then max = datDate2
End Function
Public Function Min(datDate1, datDate2) As Date
Min = datDate1
If Min > datDate2 Then Min = datDate2
End Function
I am getting a Run-Time error '6': overflow in the following code of VBA code which is for MS Access 2003 / VB 6.0 and I have put ** in the line where error comes i.e.
For i = 1 To n - 1
*** dblF1(i) = Round(dblC(i) / dblIC(i), 5)
' Run-Time error '6': overflow
Next i
Might be dblIC(i) value is zero. Is that may be reason for this error?
As code is developed by my one of my senior and he has left the job. I really need someone help who can tell me what is the reason of error and how can I fix it? Your early reply will be appreciable.
Thanks a lot
Vedant
Public Sub CompletionFactorsFASTNew()
Dim curTotalClaim As Currency
Dim datCurrentDate As Date
Dim dblI As Double
Dim dblK As Double
Dim dblIC(1 To 100) As Double
Dim dblM(1 To 100) As Double
Dim dblG(1 To 100) As Double
Dim dblC(1 To 100) As Double
Dim dblF(1 To 100) As Double
Dim dblF1(1 To 100) As Double
Dim dblP(1 To 100, 1 To 100) As Double
Dim datTemp As Date
Dim i As Long
Dim j As Long
Dim k As Long
Dim l As Long
Dim dblTop As Double
Dim dblBottom As Double
Dim n As Long
Dim datDate As Date
Dim datMaxDate As Date
Dim dblTemp As Double
Set rstClaim = New adodb.Recordset
Set rstClaim.ActiveConnection = CurrentProject.Connection
Set rstcf = New adodb.Recordset
Set rstcf.ActiveConnection = CurrentProject.Connection
Set rstCaseChar = New adodb.Recordset
Set rstCaseChar.ActiveConnection = CurrentProject.Connection
n = 36
rstcf.CursorType = adOpenDynamic
rstcf.LockType = adLockOptimistic
rstcf.Source = "[CF Claim History]"
rstcf.Open
If Not rstcf.EOF Then
rstcf.MoveFirst
While Not rstcf.EOF
rstcf.Delete
rstcf.Update
rstcf.MoveNext
Wend
End If
For i = 1 To 100
dblC(i) = 0
dblM(i) = 0
dblG(i) = 0
For j = 1 To 100
dblP(i, j) = 0
Next j
Next i
rstClaim.CursorType = adOpenDynamic
rstClaim.LockType = adLockOptimistic
rstClaim.Source = "[qIncurredPaidClaims]"
rstClaim.Open
rstClaim.MoveFirst
datMaxDate = 0
While Not (rstClaim.EOF)
datIncurreddate = DateSerial(Year(rstClaim![IncurredDate]), _
Month(rstClaim![IncurredDate]), 1)
datMaxDate = max(datMaxDate, datIncurreddate)
rstClaim.MoveNext
Wend
rstClaim.MoveFirst
datDate = 0
While Not (rstClaim.EOF)
datPaidDate = DateSerial(Year(rstClaim![PaidDate]), _
Month(rstClaim![PaidDate]), 1)
datIncurreddate = DateSerial(Year(rstClaim![IncurredDate]), _
Month(rstClaim![IncurredDate]), 1)
dblK = DateDiff("m", datIncurreddate, datMaxDate) + 1
If dblK < 1 Then dblK = 1
If dblK > n Then dblK = n
datDate = max(datDate, datIncurreddate)
curClaim = CDbl(rstClaim![Paid])
dblI = DateDiff("m", datIncurreddate, datPaidDate) + 1
If dblI < 1 Then dblI = 1
If dblI > 100 Then dblI = 100
dblC(dblK) = dblC(dblK) + curClaim
dblP(dblI, dblK) = dblP(dblI, dblK) + curClaim
rstClaim.MoveNext
Wend
rstCaseChar.CursorType = adOpenDynamic
rstCaseChar.LockType = adLockOptimistic
rstCaseChar.Source = "[qEnrollmentbyReportMonth]"
rstCaseChar.Open
rstCaseChar.MoveFirst
While Not rstCaseChar.EOF
j = DateDiff("m", rstCaseChar![ReportDate], datMaxDate) + 1
dblM(j) = rstCaseChar![Members]
rstCaseChar.MoveNext
Wend
rstCaseChar.Close
rstClaim.Close
For lngL = 1 To 12
For lngT = 1 To 12
For i = 1 To 100
If i < n Then
dblF(i) = 0
dblF1(i) = 0
Else
dblF(i) = 1
dblF1(i) = 1
End If
Next i
For k = 1 To n - 1
dblTop = 0
dblBottom = 0
For j = 1 To lngT
dblTemp = 0
For i = 1 To n - k + 1
dblTemp = dblTemp + dblP(i, n + j - k + lngL)
If i < n - k + 1 Then dblTop = dblTop + dblP(i, n + j - k + lngL)
Next i
dblBottom = dblBottom + dblTemp / dblF(n + j - k)
Next j
If dblBottom <> 0 Then
dblF(n - k) = dblTop / dblBottom
Else
dblF(n - k) = 1
End If
Next k
For k = n To 100
dblIC(k) = dblC(k)
Next k
For k = 1 To n - 1
dblG(n - k) = 0
dblTop = 0
dblBottom = 0
For j = 1 To 12
dblTop = dblTop + dblIC(n - k + j)
dblBottom = dblBottom + dblM(n - k + j)
Next j
If dblBottom <> 0 Then dblG(n - k) = dblTop / dblBottom
dblIC(n - k) = dblC(n - k) + (1 - dblF(n - k)) * dblM(n - k) * dblG(n - k)
Next k
For i = 1 To n - 1
*** dblF1(i) = Round(dblC(i) / dblIC(i), 5) ' Run-Time error '6': overflow
Next i
For i = n To 100
dblF1(i) = 1
Next i
For i = 1 To 100
dblF(i) = Round(dblF(i), 5)
If i > 12 Then dblF(i) = 1
datTemp = DateSerial(Year(DateAdd("m", 1 - 1 * i, datDate)), _
Month(DateAdd("m", 1 - 1 * i, datDate)), 1)
rstcf.AddNew
rstcf.Fields![Duration] = i
rstcf.Fields![cf] = dblF(i)
rstcf.Fields![lag] = 1 - dblF(i)
rstcf.Fields![IncurredDate] = datTemp
rstcf.Fields![dataDate] = datMaxDate
rstcf.Fields![Description] = "L = " & Format(lngL, "00") & _
" T = " & Format(lngT, "00")
rstcf.Fields![crm] = dblF1(i)
Debug.Print i, dblF(i), datTemp, datMaxDate, "L = " & _
Format(lngL, "00") & " T = " & Format(lngT, "00") & dblF1(i)
rstcf.Update
Next i
Next lngT
Next lngL
rstcf.Close
End Sub
Public Function max(datDate1, datDate2) As Date
max = datDate1
If max < datDate2 Then max = datDate2
End Function
Public Function Min(datDate1, datDate2) As Date
Min = datDate1
If Min > datDate2 Then Min = datDate2
End Function