Re: ReDim by JGM
JGM
Fri Dec 05 10:57:33 CST 2003
Hi Jan,
I think, just for the sake of keeping things clear, when you say "empty
array," you mean "array with a Null size."
I mean, if you declare
Dim MyArray()
then it is not only "empty", but it has no size or dimension, it is 0x0, but
has the potential of being anything we want.
Whereas, if you declare
Dim MyArray()
ReDim MyArray(5000)
then now you have an empty array, but it has a size of 1column x 5000rows...
I think this is why I have always seen this way of working with array (the
Dim / Redim above), because I do not think there is a way of determining an
array dimension size by testing it, but if there is, I would really like to
know!
But in your case, since you create the array within your code and you fill
it in yourself, then you know its size at all times. So the first time
around, the size is Null, then you make it 1x1, put something in it, then
the second time around you know that it is 1x1, so you make it 1x2, and so
on...
Every example I have seen with arrays followed that pattern (Dim > ReDim >
ReDim Preserve), but from reading your post, I got the feeling you did not
want to go that way, especially when I saw the nice way by which you
dynamically resized the array at every pass, so this is whay I suggested the
Boolean trick...
Still, another way to go is as follows (you may find thai more aesthetically
pleasing!):
'_______________________________________
Dim myarray()
'Set starting size, i.e. 1x1
ReDim myarray(0)
For i = 0 To 4
myarray(i) = "item " & i
'increase size by one for next pass
ReDim Preserve myarray(UBound(myarray) + 1)
Next i
'remove last row that was added at the end of the last pass,
'but was not used because we got out of the For...Next
ReDim Preserve myarray(UBound(myarray) - 1)
'_______________________________________
Good luck!
--
_______________________________________
Jean-Guy Marcil
jmarcil@sympatico.ca
"Jan Eliasen" <spam@eliasen.dk> a écrit dans le message de news:
jdb1tvk67qbu7jbrh242v826cndfffhijd@4ax.com...
> On Fri, 5 Dec 2003 09:07:43 -0500, "JGM" <no-spam@leaveme.alone>
> wrote:
>
> >Have you tried (if it is possible in your case.. I do not know how you
> >select what you are trying to store in the array...) something like:
> Yes, I suppose that could be done. It just seems funny - there must be
> somehow to check for an empty array.
>
> --
> Jan Eliasen, representing himself and not the company he works for.