tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,926
- Office Version
- 365
- 2019
- Platform
- Windows
We know it's not possible to pass arguments in a class in VBA and here is an attempt to overcome it:
However, instead of the above, can someone tell me what is wrong with this approach?
Declare a global variable and assign anything in the Class_Initialize to it. For example:
This is in Class1:
and this is in Class2:
This is in a standard module:
Code:
https://stackoverflow.com/questions/15224113/pass-arguments-to-constructor-in-vba
However, instead of the above, can someone tell me what is wrong with this approach?
Declare a global variable and assign anything in the Class_Initialize to it. For example:
This is in Class1:
Code:
Option Explicit
Private Sub Class_Initialize()
Dim abc As String
abc = MySomeVariable.SomeVariable
End Sub
and this is in Class2:
Code:
Option Explicit
Private pSomeVariable As String
Public Property Get SomeVariable() As String
SomeVariable = pSomeVariable
End Property
Public Property Let SomeVariable(ByVal S As String)
pSomeVariable = S
End Property
This is in a standard module:
Code:
Option Explicit
Global MySomeVariable As Class2
Public Sub Test()
Set MySomeVariable = New Class2
MySomeVariable.SomeVariable = "Some string"
Dim NewClass As Class1
Set NewClass = New Class1
End Sub