Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Determining whether dynamic array has been used

This seemed to work okay for me. It returns a user defined error code (2001)
if the argument is not an array, which you can remove if you like or do
something else.

Function IsDimmed(arrArg As Variant) As Variant
Dim lngUbound As Long

If IsArray(arrArg) Then
On Error Resume Next
lngUbound = UBound(arrArg)
IsDimmed = IIf(Err.Number, False, True)
Else: IsDimmed = CVErr(2001)
End If
End Function




"MDW" wrote:

Say I've got an array of user-defined variables. I don't know how many
"slots" I'm going to need, so I dimension it as a dynamic array.

Dim udtSheets() As MyDataType

When I want to add a new slot, I get the UBound.

ReDim Preserve udtSheets(UBound(udtSheets)+1)

However, the first time I try this, I get a "subscript out of range" error
because the zero-eth slot hasn't been done yet. I'm trying to find a VBA
function that can tell me whether that has happened yet. Something like

If HasBeenRedimmed(udtSheets) Then

ReDim Preserve udtSheets(UBound(udtSheets)+1)

Else

ReDim Preserve udtSheets(0)

End If


I tried "IsArray" and it returns True even if there have been no slots used.
For some reason I can't create my own function because Excel won't let me
pass a UDT array as a function parameter.

TIA.

--
Hmm...they have the Internet on COMPUTERS now!

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
Determining number of values in an array (2 related questions) KR Excel Programming 3 March 4th 05 09:33 PM
Determining Array Limit Chaplain Doug Excel Programming 3 January 5th 05 01:37 AM
Dynamic Array Michael168[_82_] Excel Programming 1 June 2nd 04 07:26 AM
Dynamic 2D Array ExcelMonkey[_52_] Excel Programming 4 January 31st 04 09:32 PM
see if dynamic array used RobcPettit Excel Programming 2 January 17th 04 12:44 AM


All times are GMT +1. The time now is 09:19 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"