AFPathfinder
Well-known Member
- Joined
- Apr 8, 2012
- Messages
- 533
- Office Version
- 365
- 2016
- Platform
- Windows
I'm trying to learn object classes in VBA and having a hard time trying to apply the knowledge; looking for a spot check.
This is working as I intended, but I don't think I'm doing the property "CrossesFY" the right way. Here's the clsCEDOrder class:
Here's the test sub:
I feel like this basically bypasses the
Again, it's testing fine. I just want to know if I need to think about this differently before I go and class my world.
Should
This is working as I intended, but I don't think I'm doing the property "CrossesFY" the right way. Here's the clsCEDOrder class:
VBA Code:
Option Explicit
'CLASS MODULE - clsCEDOrder
'Member variables
Private m_FY As Integer
Private m_Length As Integer
Private m_CrossFY As Boolean
Private m_ProcDate As Date
'Properties
Property Get TDYLength() As Integer
TDYLength = m_Length
End Property
Property Let TDYLength(ByVal intLen As Integer)
m_Length = intLen
End Property
Property Get CrossesFY() As Boolean
FYCrossCheck
CrossesFY = m_CrossFY
End Property
Private Property Let CrossesFY(ByVal blnXFY As Boolean)
m_CrossFY = blnXFY
End Property
Property Get ProceedDate() As Date
ProceedDate = m_ProcDate
End Property
Property Let ProceedDate(ByVal dtProc As Date)
m_ProcDate = dtProc
End Property
'Methods
Private Sub FYCrossCheck()
'Sets m-CrossFY bool value if a fiscal year change occurs between start and stop dates.
Dim intStartFY As Integer
Dim intStopFY As Integer
'If either proceed date or TDY length is blank or if the two values aren't recognized, set false and exit.
If m_ProcDate = 0 Or m_Length = 0 Or IsDate(m_ProcDate) = False Or IsNumeric(m_Length) = False Then
m_CrossFY = False
Exit Sub
End If
'ID the start and stop fiscal year values.
intStartFY = FY(DateValue(m_ProcDate))
intStopFY = FY(DateValue(m_ProcDate) + m_Length)
'Compare and let result.
If intStartFY <> intStopFY Then
m_CrossFY = True
Else
m_CrossFY = False
End If
End Sub
Private Function FY(Optional ByVal dt As Date) As Long
'Returns the 4 character FY value of a given date.
'Set default value if no date was given.
If dt = 0 Then
dt = Date
End If
'Set FY to the month of the provided date.
Select Case Month(dt)
Case 10 To 12
FY = Year(dt) + 1
Case Else
FY = Year(dt)
End Select
End Function
Here's the test sub:
VBA Code:
Option Explicit
Sub CEDOrder_Test()
Dim ord As clsCEDOrder
Set ord = New clsCEDOrder
ord.ProceedDate = "4/20/2024"
ord.TDYLength = 183
Debug.Print ord.CrossesFY
End Sub
I feel like this basically bypasses the
Private Property Let CrossesFY(ByVal blnXFY As Boolean)
which leads me to think I'm not doing it right.Again, it's testing fine. I just want to know if I need to think about this differently before I go and class my world.
Should
CrossesFY
even be a property? Maybe just a public function? Taking all feedback!
Last edited: