Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default ReDim string in loop

I remember seeing Myrna Larson's code a long time ago.

She would redim in groups of 100 keeping track of how many were used:

I found one sample where she used 20, but the theory would still hold:

Function GetFileList(FileSpec As String, FileNames() As String) As Integer
Dim Max As Integer
Dim NumFiles As Integer
Dim AFile As String

Max = 0
NumFiles = 0

AFile = Dir$(FileSpec)
Do While Len(AFile)
NumFiles = NumFiles + 1
If NumFiles Max Then
Max = Max + 20
ReDim Preserve FileNames(1 To Max) As String
End If
FileNames(NumFiles) = AFile
AFile = Dir$
Loop
GetFileList = NumFiles
If NumFiles Then ReDim Preserve FileNames(1 To NumFiles)

End Function 'GetFileList

From:
http://groups.google.co.uk/group/mic...7ff238 229169

or
http://tinyurl.com/hkowm



Bob Phillips wrote:

Yeah, makes sense, but Sod's law will say that one time you don't dim it big
enough.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Alan Beban" <unavailable wrote in message
...
Bob Phillips wrote:
Where is the Redim statement Arne? I would have expected to see it

within
the loop, something like

Do Until ...
Redim Preserver ary (r)
ary(r) = some_value
r=r+1
Loop

I think it's probably much more efficient to ReDim Preserve once at the
end, a la

Dim ary()
reDim ary(n)
Do Until . . .
ary(r) = some_value
r=r+1
Loop
ReDim Preserve ary(r-1)

where n is a number big enough to accommodate all possible iterations,
rather than ReDim Preserve in each iteration of the loop.

Alan Beban


--

Dave Peterson
Reply
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
Do Loop or use End iF for search string RGreen Excel Discussion (Misc queries) 4 September 1st 09 12:59 AM
ReDim Array Viktor Ygdorff Excel Programming 2 July 10th 06 04:04 PM
Dim and Redim Sean Excel Programming 4 June 5th 06 07:31 PM
ReDim Problem Casey[_4_] Excel Programming 4 January 7th 04 10:41 PM
ReDim an Array Art[_5_] Excel Programming 3 October 25th 03 03:30 PM


All times are GMT +1. The time now is 07:00 AM.

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

About Us

"It's about Microsoft Excel"