Excel vba array as class member error

I am working on a project and come across something that I do not understand. When assigning an array to a class member, the names Letand Getcannot be the same. If they are, I get an error message:

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 someone tell me that I'm just doing something wrong, or if 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
+4
source share
1 answer

Change values() As Variantto values As Variant:

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)          'Fixed here
ReDim pSkills(UBound(values))
Dim i As Long
For i = LBound(values) To UBound(values)
    pSkills(i) = values(i)
Next
End Property

Explanation:

values As Variant Variant, . values() As Variant - Variant, Array; a Array .

+1

Source: https://habr.com/ru/post/1546335/


All Articles