PDA

View Full Version : [SOLVED:] Should I need a terminate initialisation subset as well?



Aussiebear
05-09-2023, 07:51 PM
I have the following code provided as an example of a Class. Apparently there needs to be four types (Groups) of subsets(Variables, Properties, Methods and Events). In the Events section we have a Class_Initialise(), and I was wondering if I should also have a Class_terminate() or does the Class lose its focus through some other method?

Shows the 4 parts of the Class Modules

' Member variables Group



Option Explicit

Private m_x As Long
Private m_y As Long


' Properties Group


Public Property Get x() As Long
x = m_x
End Property

Public Property Let x(newX As Long)
m_x = newX
End Property

Public Property Get y() As Long
y = m_y
End Property

Public Property Let y(newy As Long)
m_y = newy
End Property


' Methods(i.e. functions and subs)


Public Sub SetPointValue(ByVal x As Long, ByVal y As Long)
m_x = x
m_y = y
End Sub

Public Function Distance(p As clsPoint) As Double
Distance = Math.Sqr((m_x - p.x) ^ 2 + (m_y - p.y) ^ 2)
End Function

Public Sub ToImmediate(Optional ByVal text As String = "")
Debug.Print vbNewLine & text
Debug.Print "x is " & m_x
Debug.Print "y is " & m_y
End Sub


' Events i.e. subs triggered by an action



Private Sub Class_Initialize()
End Sub

Aflatoon
05-10-2023, 01:41 AM
You only need to use the Initialize or Terminate events if you need to run some code when the class instance is created/destroyed. Neither one actually creates/destroys the class instance - those are the events they respond to.

Aussiebear
05-10-2023, 03:55 AM
Thank you Aflatoon, I shall have to ponder this bit about Class modules a little more.