2

I have a class cDept which has a UDT defined.

public type udtEmp
    Name as string
    Id as long 
end type

I have an array defined:

private m_Emps() as udtEmp

I want to expose the array through a property. I tried the following:

Public Property Get Employees() As udtEmp()
    Employees= m_Emps
End Property

So far everything compiles. Now I instantiate the class and try to access the property.

dim myUdt as udtEmp
dim oDept as cDept
set oDept = new cDept

myUdt = oDept.Employees(1) ' -- error

I get an error stating Wrong number of arguments or invalid property assignment.

What am I missing?

1
  • Did you really intend to return the whole array? If you are trying to access just one element at a time, take a look at @MarkL answer.
    – tcarvin
    Feb 25, 2016 at 13:37

1 Answer 1

4

(Not tested)
I think your property access is trying to use the '1' as an argument to the property (which has no arguments), thus the 'wrong number' error. Rather than trying to property get the array and then index access the array, will it work to have the property get (or a different one) return the desired array element?

Public Property Get Employees(ndx as long) As udtEmp
    Employees= m_Emps(ndx)
End Property

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.