By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,092 Members | 1,650 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,092 IT Pros & Developers. It's quick & easy.

LONG POST: Class Module Property Let Statement "Hangs"

P: n/a
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 DepreciationFactor. 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 intYearOfCalculation 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(value As Integer)
intConvention = value
End Property

Property Get Convention() As Integer
Convention = intConvention
End Property

Property Get DeprFactor(intOption As Integer) As Double
DeprFactor = FactorPopulator(intOption)
End Property

Property Let PISDate(value As Date)
datPIS = value
If intPeriod <> 0 Then
intYearOfCalculation = 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 AccumulatedFactor(intOption As Integer) As Double
AccumulatedFactor = 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.OpenRecordset(TableSelector(intDS))
Select Case intConvention
Case 1
With rec
.MoveLast
.MoveFirst
.Index = "fldClassLife"
.Seek "=", intLife
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFactor", "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 = "fldClassLife"
.Seek "=", CSng(DatePart("m", datPIS))
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFactor", "Mid-month convention failed."
End If
For i = 1 To intPeriod
If i = intDispPeriod Then
dblAccum = dblAccum + (CDbl((CInt(DatePart("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.OpenRecordset(TableSelector(intDS))
Select Case intConvention
Case 1
With rec
.MoveLast
.MoveFirst
.Index = "fldClassLife"
.Seek "=", intLife
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFactor", "Class life invalid."
End If
dblFactor = .Fields(intPeriod + 1)
.Close
End With
Case 2
With rec
.MoveLast
.MoveFirst
.Index = "fldClassLife"
.Seek "=", CSng(DatePart("m", datPIS))
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFactor", "Mid-month convention failed."
End If
dblFactor = .Fields(intPeriod + 1)
.Close
End With
Case 3
rec.Close
End Select
FactorPopulator = dblFactor
End Function

Private Function TableSelector(ByVal 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 DepreciationFactor",
"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 DepreciationFactor",
"Invalid convention"
End Select
TableSelector = strPrefix & strRate & strConv
End Function

Private Sub Class_Initialize()
intLife = 5
intPeriod = 1
intConvention = 1
dblFactor = 0
dblAccum = 0
End Sub
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
rkc

"Johnny M" <jm*******@gmail.com> wrote in message
news:55************************@posting.google.com ...
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 DepreciationFactor. 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.


You have a typo in Property Let DispDate and probably have been staring
at it so long that you don't see it.

First line of procedure:
DispDate = value should read datDisp = value.


Nov 13 '05 #2

P: n/a
Please ignore this post. I saw the error right after I sent it in.

My apologies.
Nov 13 '05 #3

P: n/a
> Property Let DispDate(value as Date)
DispDate = value
Yes, that will hang.
That second line is wrong :~)

Dim datDisp as date.

Property Let DispDate(vDate as date)
datDisp = vdate
end

Property Get DispDate() as date
DispDate = datDisp
end

(david)
"Johnny M" <jm*******@gmail.com> wrote in message
news:55************************@posting.google.com ... 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 DepreciationFactor. 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 intYearOfCalculation 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(value As Integer)
intConvention = value
End Property

Property Get Convention() As Integer
Convention = intConvention
End Property

Property Get DeprFactor(intOption As Integer) As Double
DeprFactor = FactorPopulator(intOption)
End Property

Property Let PISDate(value As Date)
datPIS = value
If intPeriod <> 0 Then
intYearOfCalculation = 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 AccumulatedFactor(intOption As Integer) As Double
AccumulatedFactor = 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.OpenRecordset(TableSelector(intDS))
Select Case intConvention
Case 1
With rec
.MoveLast
.MoveFirst
.Index = "fldClassLife"
.Seek "=", intLife
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFactor", "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 = "fldClassLife"
.Seek "=", CSng(DatePart("m", datPIS))
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFactor", "Mid-month convention failed."
End If
For i = 1 To intPeriod
If i = intDispPeriod Then
dblAccum = dblAccum + (CDbl((CInt(DatePart("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.OpenRecordset(TableSelector(intDS))
Select Case intConvention
Case 1
With rec
.MoveLast
.MoveFirst
.Index = "fldClassLife"
.Seek "=", intLife
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFactor", "Class life invalid."
End If
dblFactor = .Fields(intPeriod + 1)
.Close
End With
Case 2
With rec
.MoveLast
.MoveFirst
.Index = "fldClassLife"
.Seek "=", CSng(DatePart("m", datPIS))
If .NoMatch Then
Err.Raise 10002, "DeprFactor property of
DepreciationFactor", "Mid-month convention failed."
End If
dblFactor = .Fields(intPeriod + 1)
.Close
End With
Case 3
rec.Close
End Select
FactorPopulator = dblFactor
End Function

Private Function TableSelector(ByVal 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 DepreciationFactor",
"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 DepreciationFactor",
"Invalid convention"
End Select
TableSelector = strPrefix & strRate & strConv
End Function

Private Sub Class_Initialize()
intLife = 5
intPeriod = 1
intConvention = 1
dblFactor = 0
dblAccum = 0
End Sub

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.