tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,926
- Office Version
- 365
- 2019
- Platform
- Windows
This code:
</code>
Rich (BB code):
<code style="color: rgb(0, 96, 0);">Option Explicit</code>
<code style="color: rgb(0, 96, 0);">Private pKey As Long</code>
<code style="color: rgb(0, 96, 0);">Private pName As String</code>
<code style="color: rgb(0, 96, 0);">Private pChildren As Collection</code>
<code style="color: rgb(0, 96, 0);">Public Property Get Key() As Long</code>
<code style="color: rgb(0, 96, 0);"> Key = pKey</code>
<code style="color: rgb(0, 96, 0);">End Property</code>
<code style="color: rgb(0, 96, 0);">Public Property Get Name() As String</code>
<code style="color: rgb(0, 96, 0);"> Name = pName</code>
<code style="color: rgb(0, 96, 0);">End Property</code>
<code style="color: rgb(0, 96, 0);">Public Property Get Children() As Collection</code>
<code style="color: rgb(0, 96, 0);"> Set Children = pChildren</code>
<code style="color: rgb(0, 96, 0);">End Property</code>
<code style="color: rgb(0, 96, 0);">Public Property Let Key(p As Long)</code>
<code style="color: rgb(0, 96, 0);"> pKey = p</code>
<code style="color: rgb(0, 96, 0);">End Property</code>
<code style="color: rgb(0, 96, 0);">Public Function Init(k As Long, sName As String) As cMyClass</code>
<code style="color: rgb(0, 96, 0);"> pKey = k</code>
<code style="color: rgb(0, 96, 0);"> pName = sName</code>
<code style="color: rgb(0, 96, 0);"> Set pChildren = New Collection</code>
<code style="color: rgb(0, 96, 0);"> Set Init = Me</code>
<code style="color: rgb(0, 96, 0);">End Function
</code><code style="color: rgb(0, 96, 0);">
<code style="color: rgb(0, 96, 0);">
is taken from here:
The author states:
My question is: why not just use:
Is it because Initialize always initialises at the start but he wants to initialise whenever he chooses?
Regardless,
Surely isn't VBA's Sub Class_Initialize() EXACTLY this?
Thanks
<strike>
</strike>
</code>
<strike></strike><strike></strike>is taken from here:
Rich (BB code):
http://ramblings.mcpher.com/Home/excelquirks/snippets/classes
The author states:
Rich (BB code):
"A method is a procedure that operates on a class, sometimes returning some value. Usually when you create a class you want to populate it with some initial values, and perhaps set up some kind of other structures. I generally create a method called "Init"to do that. Other languages have special methods called constructors that are called on the instantiation of a class. I kind of like the idea of initializing it when I want to. "
My question is: why not just use:
Rich (BB code):
Private Sub Class_Initialize()
End Sub
Is it because Initialize always initialises at the start but he wants to initialise whenever he chooses?
Regardless,
Rich (BB code):
"Other languages have special methods called constructors that are called on the instantiation of a class."
Surely isn't VBA's Sub Class_Initialize() EXACTLY this?
Thanks
<strike>
</strike>
</code>
Last edited: