tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,926
- Office Version
- 365
- 2019
- Platform
- Windows
I have a variable, Var1, which is of type Class2.
Standard Module:
Class1
Class2
The code above works.
We use Let for "normal" variables and Set for object variables.
What I don't understand is this line:
Since Var1 is of type Var2, I expected to have to write:
Why don't I need to SET keyword here?
Is it because of this line at the top of Class1?
Thanks
Standard Module:
Code:
Option Explicit
Sub Test()
Dim a As Class1
Set a = New Class1
a.Var1.Var2 = 7678
End Sub
Class1
Code:
Option Explicit
Private pVar1 As New Class2
Public Property Get Var1() As Class2
Set Var1 = pVar1
End Property
Public Property Set Var1(ByVal vNewValue As Class2)
Set pVar1 = vNewValue
End Property
Private Sub Class_Initialize()
Var1.Var2 = 336
End Sub
Class2
Code:
Option Explicit
Private pVar2 As String
Public Property Get Var2() As String
Var2 = pVar2
End Property
Public Property Let Var2(ByVal vNewValue As String)
pVar2 = vNewValue
End Property
The code above works.
We use Let for "normal" variables and Set for object variables.
What I don't understand is this line:
Code:
Private Sub Class_Initialize()
Var1.Var2 = 336
End Sub
Since Var1 is of type Var2, I expected to have to write:
Code:
Private Sub Class_Initialize()
SET Var1.Var2 = 336
End Sub
Why don't I need to SET keyword here?
Is it because of this line at the top of Class1?
Code:
Private pVar1 As New Class2
Thanks
Last edited: