tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,926
- Office Version
- 365
- 2019
- Platform
- Windows
This code is taken from here:
I can't get it to work.
My understanding is as follows:
This goes into a standard module:
This goes in a class, Employee:
This goes into another class, Factory:
When I compile, I get an error message:
and it points to this line:
What is wrong?
Thanks
Code:
https://newbedev.com/pass-arguments-to-constructor-in-vba
I can't get it to work.
My understanding is as follows:
This goes into a standard module:
Code:
Sub Test
Dim a As Employee
Set a = Factory.CreateEmployee("Excel", 100)
End Sub
This goes in a class, Employee:
Code:
Private m_name As String
Private m_age As Integer
Public Sub InitiateProperties(name As String, age As Integer)
m_name = name
m_age = age
End Sub
This goes into another class, Factory:
Code:
Public Function CreateEmployee(name As String, age As Integer) As Employee
Set CreateEmployee = New Employee
CreateEmployee.InitiateProperties name:=name, age:=age
End Function
When I compile, I get an error message:
Code:
Variable not found
and it points to this line:
Code:
Set a = Factory.CreateEmployee("Excel", 10)
What is wrong?
Thanks