LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default How to write Property Let for the single elements of an array

Hi all,

thanks to Bob's and other people's suggestions, I'm now able to assign
to all elements of an array property in a class module. But what if I
need to assign to a *single* element? It looks like I have to Redim it
each time...
Example:

' Class Module
Option Explicit
Option Base 1

Private pYValues() As Double

' not sure if this Class_Initialize Sub makes sense: IMO it would
' in other languages, but maybe in VBA is redundant
Private Sub Class_Initialize()
ReDim pYValues(1) As Double
End Sub

Public Property Get YValues() As Double()
YValues = pYValues
End Property
Public Property Let YValues(Values() As Double)
pYValues = Values
End Property
Public Property Get YValue(Index As Long) As Double
YValues = pYValues(Index)
End Property
Public Property Let YValue(Index As Long, Value As Double)
' problem!!!
pYValues(Index) = Values
End Property

The problem is in Property Let YValue: if I add en element to the
array, I get a "subscript out of range" error. So I guess I should
write it like this:

Public Property Let YValue(Index As Long, Value As Double)
If UBound(pYValues) < Index Then Redim Preserve pYValues(Index)
pYValues(Index) = Values
End Property

but redimensioning the array each time I add a single element is
really slow! Maybe I should write a "Resize" method, something like:

Public Sub Resize(Nelements As Long)
Redim Preserve pYValues(Nelements)
End Sub

resize the array before adding each element, and then add. What do you
think? Any better ideas? Thanks in advance,

Best Regards

deltaquattro
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
elements in an array Chip Pearson Excel Programming 2 November 23rd 07 12:19 PM
elements in an array Alan Beban[_2_] Excel Programming 0 November 21st 07 08:21 PM
array elements count madeleine[_2_] Excel Programming 6 December 8th 06 03:36 AM
Reference Elements w/in an Array M Moore Excel Discussion (Misc queries) 2 October 16th 06 03:33 PM
Shifting Array Elements Trip[_3_] Excel Programming 6 July 30th 05 07:30 PM


All times are GMT +1. The time now is 02:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"