Hi Alan,
you are welcome :-)
> Would you mind expanding on and, if possible, quantifying what you
> mean by 'expensive'?
I mean expensive in use of resources. A simple example for quatifying:
<sample>
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private lBeginTime As Long
Private lStopTime As Long
Const CNTS As Long = 999999
Sub test1()
Dim i&
Dim cnt&
Dim arr() As String
lBeginTime = GetTickCount
For i = 0 To CNTS
If i Mod 2 = 0 Then
ReDim Preserve arr(cnt)
arr(cnt) = "test"
cnt = cnt + 1
End If
Next
Debug.Print (GetTickCount - lBeginTime) / 1000
End Sub
Sub test2()
Dim i&
Dim cnt&
Dim arr() As String
lBeginTime = GetTickCount
ReDim arr(CNTS)
For i = 0 To CNTS
If i Mod 2 = 0 Then
arr(cnt) = "test"
cnt = cnt + 1
End If
Next
ReDim Preserve arr(cnt - 1)
Debug.Print (GetTickCount - lBeginTime) / 1000
End Sub
</sample>
On my machine (1600+, 512RAM) test1 takes about 5.5 seconds, test2 about
0.5 seconds.
A list with 5 elememts doesn´t matter but, I think, it cannot be harmed
to know about this.

Signature
Viele Grüße
Michael Bauer
> > Because the ReDim is very expensive I would dim the
> > array with the maximum of items first.
[quoted text clipped - 9 lines]
>
> Alan.
Alan - 31 Oct 2004 23:16 GMT
>> Would you mind expanding on and, if possible, quantifying what
>> you mean by 'expensive'?
[quoted text clipped - 3 lines]
>
> <sample>
{Snipped sample code}
> </sample>
>
[quoted text clipped - 4 lines]
> A list with 5 elememts doesn?t matter but, I think, it cannot be
> harmed to know about this.
Thanks Michael.
I am doing something quite like that, and it does take a noticeable
amount of time using a ReDim at each step (constructing an array of
around 50 unique elements built from a non-unique list of about 3000)
so I will change it to your suggestion.
Regards,
Alan.