View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
deltaquattro deltaquattro is offline
external usenet poster
 
Posts: 65
Default How to write Property Let for the single elements of an array

Hi Bob,

so you're suggesting something like this? I omitted all the properties/
methods not directly related to the original question, so as to keep
the posted code shorter:

' Class Module
Option Explicit
Option Base 1

Private pYValues() As Double
Private ArraySize As Long

Private Sub Class_Initialize()
ArraySize = 1000
ReDim pYValues(ArraySize) As Double
End Sub

Public Property Let YValue(Index As Long, Value As Double)
If Index ArraySize Then
ArraySize = Index
ReDim pYValues(ArraySize)
End If
pYValues(Index) = Value
End Property


I'm a bit unsatisfied with the waste of memory: guess it can't be
helped, though. Thank you very much for your suggestion,

Best Regards

deltaquattro

On 16 Mar, 14:23, "Bob Phillips" wrote:
I haven't looked too hard at your code, but here is a thought.

When you initialise the class setup the array big, say 1000 elements. Use a
class variable to control the next index and just use this to allocate to
the next element. This way, the array will be 1,000 elements in size
internally to the class, but to any code using an instance of that class it
will look much smaller. When your internal index gets to 1000, bump it up
(Redim) by some order of magnitude. This way, you only redim once in a blue
moon.

--

HTH

Bob