I am working on a project and have run into something that I don't understand. When assigning an array to a class member, the Let and Get names cannot be the same. If they are, I get the error:
Definitions of property procedures for the same property are inconsistent, or property procedure has an optional parameter, a ParamArray, or an invalid Set final parameter
Can anyone tell me if I'm just doing something wrong, or if this is just how it is. The code below generates the above message.
Test Code:
Sub loadServer()
Dim testServer As AvayaServer
Dim i As Long
Dim arr() As Variant
arr = Array("1", "2", "3", "4", "5")
Set testServer = New AvayaServer
testServer.Name = "This Sucks"
testServer.Skill = arr
MsgBox testServer.Skills(4)
MsgBox testServer.Name
End Sub
Class Code:
Private pName As String
Private pSkills() As String
Public Property Get Skills() As Variant
Skills = pSkills()
End Property
Public Property Let Skills(values() As Variant)
ReDim pSkills(UBound(values))
Dim i As Long
For i = LBound(values) To UBound(values)
pSkills(i) = values(i)
Next
End Property
values() As Varianttovalues As Variantvalues As Variantwill be a Variant which you later use to store an array,values() As Variantis an array of Variants. The Array function can only be assigned to the former. Also I assumetestServer.Skill(note no "s") is just a spelling mistake above. If it isn't then change your code and I suggest puttingOption Explicitat the top of your modules.testServer.Skillwas there only by partial intent. Originally, for the code to work that in conjunction withLet Skill(values() As Varianthad to be used. It really was an oversight in the post since I didn't correct all of the code. Thanks for catching that.