using Access 2003
Pardon the subject line, but I don't have a better word for this
strange
behavior (or behavior I don't understand!!!)
I have a class module named DepreciationFac tor. One of the properties
is a follows
(irrelevant code omitted):
..
..
Dim datDisp as Date
Dim datPIS as Date 'This var is set in another property stmt and works
fine
Dim intDispPeriod as Integer
..
..
Property Let DispDate(value as Date)
DispDate = value
intDispPeriod = 1 + (CInt(DatePart( "YYYY", value)) -
CInt(DatePart(" YYYY", _
datPIS)))
Debug.Print intDispPeriod
End Property
Property Get DispDate() As Date
DispDate = datDisp
End Property
..
..
When I set the DispDate property from client code, I got an Out of
Stack memory
error. So I figured I had a recursive call somewhere. I put
breakpoints in
the class module and ran it again. When the code reached the first
line of the
property let statement for DispDate, it just ran it over and over
again. I can
move the yellow cursor off the DispDate = value line, and the code
will execute
the second line normally. But, when it reaches the Debug line, it
will execute
this line forever, apparently mimicing the behavior of the first line.
Does anyone see anything obviously wrong with the statement? Below is
a copy
of the entire class module for your reference. I'm not a professional
programmer, so be gentle.
Option Compare Database
Option Explicit
'Variables
Dim intLife As Integer 'Class
life
Dim intPeriod As Integer 'Calc
Period
Dim intConvention As Integer
'Convention
Dim dblFactor As Double
'Depreciation factor
Dim dblAccum As Double 'A/D
factor
Dim datPIS As Date 'PIS date
Dim datDisp As Date 'Disposal
date
Dim intYearOfCalcul ation As Integer 'Based on
period
Dim intDispPeriod As Integer 'Disposal
period
'Properties
Property Let Life(value As Integer)
intLife = value
End Property
Property Get Life() As Integer
Life = intLife
End Property
Property Let Period(value As Integer)
intPeriod = value
End Property
Property Get Period() As Integer
Period = intPeriod
End Property
Property Let Convention(valu e As Integer)
intConvention = value
End Property
Property Get Convention() As Integer
Convention = intConvention
End Property
Property Get DeprFactor(intO ption As Integer) As Double
DeprFactor = FactorPopulator (intOption)
End Property
Property Let PISDate(value As Date)
datPIS = value
If intPeriod <> 0 Then
intYearOfCalcul ation = CInt(DatePart(" YYYY", value)) + (intPeriod
- 1)
End If
End Property
Property Get PISDate() As Date
PISDate = datPIS
End Property
Property Let DispDate(value As Date)
DispDate = value
intDispPeriod = 1 + (CInt(DatePart( "YYYY", value)) -
CInt(DatePart(" YYYY", datPIS)))
Debug.Print intDispPeriod
End Property
Property Get DispDate() As Date
DispDate = datDisp
End Property
Property Get AccumulatedFact or(intOption As Integer) As Double
AccumulatedFact or = AccumPopulator( intOption)
End Property
'Methods
Private Function AccumPopulator( intDS As Integer) As Double
Dim db As DAO.Database
Dim rec As DAO.Recordset
Dim i As Integer
Set db = CurrentDb()
Set rec = db.OpenRecordse t(TableSelector (intDS))
Select Case intConvention
Case 1
With rec
.MoveLast
.MoveFirst
.Index = "fldClassLi fe"
.Seek "=", intLife
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFac tor", "Class life invalid."
End If
For i = 1 To intPeriod
If i = intDispPeriod Then
dblAccum = dblAccum + 0.5 * .Fields(i + 1)
Exit For
Else
dblAccum = dblAccum + .Fields(i + 1)
End If
Next
.Close
End With
Case 2
With rec
.MoveLast
.MoveFirst
.Index = "fldClassLi fe"
.Seek "=", CSng(DatePart(" m", datPIS))
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFac tor", "Mid-month convention failed."
End If
For i = 1 To intPeriod
If i = intDispPeriod Then
dblAccum = dblAccum + (CDbl((CInt(Dat ePart("MM",
datDisp)) + 0.5)) / 12) * .Fields(i + 1)
Exit For
Else
dblAccum = dblAccum + .Fields(i + 1)
End If
Next
.Close
End With
Case 3
rec.Close
End Select
AccumPopulator = dblAccum
End Function
Private Function FactorPopulator (intDS As Integer) As Double
Dim db As DAO.Database
Dim rec As DAO.Recordset
Set db = CurrentDb()
Set rec = db.OpenRecordse t(TableSelector (intDS))
Select Case intConvention
Case 1
With rec
.MoveLast
.MoveFirst
.Index = "fldClassLi fe"
.Seek "=", intLife
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFac tor", "Class life invalid."
End If
dblFactor = .Fields(intPeri od + 1)
.Close
End With
Case 2
With rec
.MoveLast
.MoveFirst
.Index = "fldClassLi fe"
.Seek "=", CSng(DatePart(" m", datPIS))
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFac tor", "Mid-month convention failed."
End If
dblFactor = .Fields(intPeri od + 1)
.Close
End With
Case 3
rec.Close
End Select
FactorPopulator = dblFactor
End Function
Private Function TableSelector(B yVal intSystem) As String
Dim strPrefix As String
Dim strRate As String
Dim strConv As String
strPrefix = "t_"
Select Case intSystem
Case DeprSystem.ADS
strRate = "100"
Case DeprSystem.GDS
strRate = "200"
Case Else
Err.Raise 10001, "DerpFactor Property of DepreciationFac tor",
"Invalid depreciation system."
End Select
Select Case intConvention
Case 1
strConv = "_HY"
Case 2
strConv = "_MM"
Case 3
strConv = "_MQ"
Case Else
Err.Raise 10000, "DeprFactor property of DepreciationFac tor",
"Invalid convention"
End Select
TableSelector = strPrefix & strRate & strConv
End Function
Private Sub Class_Initializ e()
intLife = 5
intPeriod = 1
intConvention = 1
dblFactor = 0
dblAccum = 0
End Sub
Pardon the subject line, but I don't have a better word for this
strange
behavior (or behavior I don't understand!!!)
I have a class module named DepreciationFac tor. One of the properties
is a follows
(irrelevant code omitted):
..
..
Dim datDisp as Date
Dim datPIS as Date 'This var is set in another property stmt and works
fine
Dim intDispPeriod as Integer
..
..
Property Let DispDate(value as Date)
DispDate = value
intDispPeriod = 1 + (CInt(DatePart( "YYYY", value)) -
CInt(DatePart(" YYYY", _
datPIS)))
Debug.Print intDispPeriod
End Property
Property Get DispDate() As Date
DispDate = datDisp
End Property
..
..
When I set the DispDate property from client code, I got an Out of
Stack memory
error. So I figured I had a recursive call somewhere. I put
breakpoints in
the class module and ran it again. When the code reached the first
line of the
property let statement for DispDate, it just ran it over and over
again. I can
move the yellow cursor off the DispDate = value line, and the code
will execute
the second line normally. But, when it reaches the Debug line, it
will execute
this line forever, apparently mimicing the behavior of the first line.
Does anyone see anything obviously wrong with the statement? Below is
a copy
of the entire class module for your reference. I'm not a professional
programmer, so be gentle.
Option Compare Database
Option Explicit
'Variables
Dim intLife As Integer 'Class
life
Dim intPeriod As Integer 'Calc
Period
Dim intConvention As Integer
'Convention
Dim dblFactor As Double
'Depreciation factor
Dim dblAccum As Double 'A/D
factor
Dim datPIS As Date 'PIS date
Dim datDisp As Date 'Disposal
date
Dim intYearOfCalcul ation As Integer 'Based on
period
Dim intDispPeriod As Integer 'Disposal
period
'Properties
Property Let Life(value As Integer)
intLife = value
End Property
Property Get Life() As Integer
Life = intLife
End Property
Property Let Period(value As Integer)
intPeriod = value
End Property
Property Get Period() As Integer
Period = intPeriod
End Property
Property Let Convention(valu e As Integer)
intConvention = value
End Property
Property Get Convention() As Integer
Convention = intConvention
End Property
Property Get DeprFactor(intO ption As Integer) As Double
DeprFactor = FactorPopulator (intOption)
End Property
Property Let PISDate(value As Date)
datPIS = value
If intPeriod <> 0 Then
intYearOfCalcul ation = CInt(DatePart(" YYYY", value)) + (intPeriod
- 1)
End If
End Property
Property Get PISDate() As Date
PISDate = datPIS
End Property
Property Let DispDate(value As Date)
DispDate = value
intDispPeriod = 1 + (CInt(DatePart( "YYYY", value)) -
CInt(DatePart(" YYYY", datPIS)))
Debug.Print intDispPeriod
End Property
Property Get DispDate() As Date
DispDate = datDisp
End Property
Property Get AccumulatedFact or(intOption As Integer) As Double
AccumulatedFact or = AccumPopulator( intOption)
End Property
'Methods
Private Function AccumPopulator( intDS As Integer) As Double
Dim db As DAO.Database
Dim rec As DAO.Recordset
Dim i As Integer
Set db = CurrentDb()
Set rec = db.OpenRecordse t(TableSelector (intDS))
Select Case intConvention
Case 1
With rec
.MoveLast
.MoveFirst
.Index = "fldClassLi fe"
.Seek "=", intLife
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFac tor", "Class life invalid."
End If
For i = 1 To intPeriod
If i = intDispPeriod Then
dblAccum = dblAccum + 0.5 * .Fields(i + 1)
Exit For
Else
dblAccum = dblAccum + .Fields(i + 1)
End If
Next
.Close
End With
Case 2
With rec
.MoveLast
.MoveFirst
.Index = "fldClassLi fe"
.Seek "=", CSng(DatePart(" m", datPIS))
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFac tor", "Mid-month convention failed."
End If
For i = 1 To intPeriod
If i = intDispPeriod Then
dblAccum = dblAccum + (CDbl((CInt(Dat ePart("MM",
datDisp)) + 0.5)) / 12) * .Fields(i + 1)
Exit For
Else
dblAccum = dblAccum + .Fields(i + 1)
End If
Next
.Close
End With
Case 3
rec.Close
End Select
AccumPopulator = dblAccum
End Function
Private Function FactorPopulator (intDS As Integer) As Double
Dim db As DAO.Database
Dim rec As DAO.Recordset
Set db = CurrentDb()
Set rec = db.OpenRecordse t(TableSelector (intDS))
Select Case intConvention
Case 1
With rec
.MoveLast
.MoveFirst
.Index = "fldClassLi fe"
.Seek "=", intLife
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFac tor", "Class life invalid."
End If
dblFactor = .Fields(intPeri od + 1)
.Close
End With
Case 2
With rec
.MoveLast
.MoveFirst
.Index = "fldClassLi fe"
.Seek "=", CSng(DatePart(" m", datPIS))
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFac tor", "Mid-month convention failed."
End If
dblFactor = .Fields(intPeri od + 1)
.Close
End With
Case 3
rec.Close
End Select
FactorPopulator = dblFactor
End Function
Private Function TableSelector(B yVal intSystem) As String
Dim strPrefix As String
Dim strRate As String
Dim strConv As String
strPrefix = "t_"
Select Case intSystem
Case DeprSystem.ADS
strRate = "100"
Case DeprSystem.GDS
strRate = "200"
Case Else
Err.Raise 10001, "DerpFactor Property of DepreciationFac tor",
"Invalid depreciation system."
End Select
Select Case intConvention
Case 1
strConv = "_HY"
Case 2
strConv = "_MM"
Case 3
strConv = "_MQ"
Case Else
Err.Raise 10000, "DeprFactor property of DepreciationFac tor",
"Invalid convention"
End Select
TableSelector = strPrefix & strRate & strConv
End Function
Private Sub Class_Initializ e()
intLife = 5
intPeriod = 1
intConvention = 1
dblFactor = 0
dblAccum = 0
End Sub
Comment