tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,759
- Office Version
- 365
- 2019
- Platform
- Windows
According to this article:
it states:
So I experimented by adding Me in a Property.
This is in Class1:
This is in a standard module:
The above displays a message box with the string "Some name", as expected.
However, if the Let Property was changed to:
the message box displays an empty string.
Stepping into the code, I noticed when I get to this line (in the original):
it jumps to here:
then the message box shows the correct string.
However, stepping through the second scenario, the code again hits the Get Property but immediately after, it goes to the Let Property before displaying the message box (and an empty string).
Why is that?
Thanks
Code:
https://renenyffenegger.ch/notes/development/languages/VBA/language/classes/index
it states:
Code:
' Apparently, the »me« keyword cannot be used ' in member subs and member functions …
So I experimented by adding Me in a Property.
This is in Class1:
Code:
Option Explicit
Private pName As String
Public Property Get Name() As String
Name = pName
End Property
Public Property Let Name(ByVal vNewValue As String)
pName = vNewValue
End Property
Private Sub Class_Initialize()
Name = "Some name"
End Sub
This is in a standard module:
Code:
Option Explicit
Sub Start()
Dim j As Class1
Set j = New Class1
MsgBox j.Name
End Sub
The above displays a message box with the string "Some name", as expected.
However, if the Let Property was changed to:
Code:
Public Property Get Name() As String
Me.Name = pName
End Property
the message box displays an empty string.
Stepping into the code, I noticed when I get to this line (in the original):
Code:
MsgBox j.Name
it jumps to here:
Code:
Public Property Get Name() As String
Name = pName
End Property
then the message box shows the correct string.
However, stepping through the second scenario, the code again hits the Get Property but immediately after, it goes to the Let Property before displaying the message box (and an empty string).
Why is that?
Thanks