Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default tips for initializing/reusing dynamic arrays

I have the code below for doing this now, as part of a function. It needs to
take into account that:
- the array may not be dimensioned yet
- the array may be dimensioned, but Item(0) is 'empty"
- the array may be added to (this function may be called multiple times and
add to the array on each call)

It works and all, but looks so...inelegant. Anyone see anything I'm doing
wrong here?

I'm wondering if I could encapsulate this generically somehow. It seems the
only tricky part in doing that would be the test for Item(0) being empty,
which seems like it needs to be a logical test unique to the items you are
storing. Any ideas? Worth it?

Thanks, Eric
---------------------------
Dim restoreIndex As Integer
On Error Resume Next ' in case the array is not dimensioned
yet
Dim bFirstAdd As Boolean ' true if the array is either not
dimension or dimensioned but empty
' tests for emptiness, and will generate error 9 if not dimensioned
bFirstAdd = IsNothing(m_filterRestore(0).m_wksName)
If Err.Number = 9 Then
' not dimensioned yet. so let's do it
ReDim m_filterRestore(0)
bFirstAdd = True
On Error GoTo 0
End If
restoreIndex = IIf(bFirstAdd, 0, UBound(m_filterRestore) + 1)
ReDim Preserve m_filterRestore(restoreIndex + (fltrs.Count))


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
Dynamic Arrays chaz Excel Discussion (Misc queries) 1 May 23rd 06 12:43 AM
Dynamic arrays Driver New Users to Excel 3 November 7th 05 10:11 PM
Dynamic Arrays Chiba Excel Worksheet Functions 2 July 9th 05 03:58 AM
Dynamic Arrays as arguments Marcotte A Excel Programming 4 December 16th 04 08:05 PM
Dynamic Arrays Alan Beban[_2_] Excel Programming 12 December 9th 04 12:50 AM


All times are GMT +1. The time now is 06:37 PM.

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"