How to handle dynamic Array properties in a class module?

D

deltaquattro

Hi all,

following Chip's suggestion to convert all my UDT to classes, I got
into a stumbling block: how to deal with a dynamic array property?
Suppose I have

Private pYValues() As Double

The Property Get should be trivial:

Public Property Get YValues() As Double()
YValues = pYValues
End Property

But how about the Property Let? I should handle the case of
unallocated and allocated array, but I cannot test allocation of a
dynamic array with Is Nothing. How can I get out of this? Thanks,

Best Regards

deltaquattro (Sergio Rossi)
 
B

Bob Phillips

You can handle it like so

========= Class Module
Private penalise() As Double

Public Property Get YValues() As Double()
YValues = pYValues
End Property

Public Property Let YValues(Values() As Double)
pYValues = Values
End Property

========= Standard Module
Dim cls As Class1
Dim ary() As Double

Set cls = New Class1

ReDim ary(1 To 3)
ary(1) = 1
ary(2) = 2
ary(3) = 3
cls.YValues = ary

ary = cls.YValues
MsgBox ary(2)

But as you can see, you effectively define and build the array in the
calling procedure.
 
D

deltaquattro

'K, thanks! It was simpler than I thought. I've coded that and, as
soon as I fix the other bugs in my code (see my new post :), I will
let you know how it work.

Best Regards

Sergio Rossi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top