ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to handle dynamic Array properties in a class module? (https://www.excelbanter.com/excel-programming/440627-how-handle-dynamic-array-properties-class-module.html)

deltaquattro

How to handle dynamic Array properties in a class module?
 
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)





Bob Phillips[_4_]

How to handle dynamic Array properties in a class module?
 
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.


--

HTH

Bob

"deltaquattro" wrote in message
...
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)







deltaquattro

How to handle dynamic Array properties in a class module?
 
'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

On 15 Mar, 11:39, "Bob Phillips" wrote:
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.

--

HTH

Bob

"deltaquattro" wrote in message

...

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)




All times are GMT +1. The time now is 01:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com