Let property of VBA class modules - is it possible to have multiple arguments?
class, excel, oop, properties, vba
Solution
As per your comment if you would prefer to encapsulate this logic then you can use something similar to the below.
Below includes the sub and function. The function returns a Person object:
Public Sub testing()
Dim t As Person
Set t = PersonData("John", "Smith")
End Sub
Public Function PersonData(firstName As String, lastName As String) As Person
Dim p As New Person
p.firstName = firstName
p.lastName = lastName
Set PersonData = p
End Function
Person Class:
Dim pFirstName As String, pLastName As String
Public Property Let FirstName(FirstName As String)
pFirstName = FirstName
End Property
Public Property Get FirstName() As String
FirstName = pFirstName
End Property
Public Property Let LastName(LastName As String)
pLastName = LastName
End Property
Public Property Get LastName() As String
LastName = pLastName
End Property
Problem
My understanding of using the Let property in a class module so far is that you set it up in the class modules like this: ``` Dim pName as String Public Property Let Name(Value As String) pName = Value End Property ``` And then you after you've created an object of this class you can set this property like so: ``` MyObject.Name = "Larry" ``` Question: Is it possible to somehow enter multiple arguments into a class property? For instance: ``` Dim pFirstName as String, pLastName as String Public Property Let Name(FirstName As String, LastName As String) pFirstName = FirstName pLastName = LastName End Property ``` How would you then go about setting this property outside the class? ``` MyObject.Name = ?? ``` Or is this just plain not possible to do?