Re: How to dynamically resize an array?
- From: "roidy" <rp@xxxxxxxxxx>
- Date: Sun, 10 May 2009 22:05:15 +0100
NoOfEpisodes is unknown until the episodes have read in one by one from the xml file. In the previous version of the program I just gave the array a large value eg. 40 as it is unlikely any season of a TV series will have that many episodes. I`m just tidying the program up and it seemed wasteful to declare an array that large when it probably isn`t needed. The only other way would be to read the xml file twice, firstly counting the number of episodes and then declaring the array, and then read it again and fetch in the episode data.
Rob
"Gazmik" <postmaster@xxxxxxxxx> wrote in message news:cOOdnU5oTsIlq5rXnZ2dnUVZ_g-dnZ2d@xxxxxxxxxxxxxx
Since you are keeping track of the number of episodes in the structure, one way to do it would be to set the episode array to a size that would be sufficient in most circumstances before you use it:.
NoOfEpisodes = 0: Redim Episode(32)
And then as you're adding to the array, check to see if it needs resized:
NoOfEpisodes += 1
If NoOfEpisodes > Episode.GetUpperBound(0) Then Redim Preserve Episode(Episode.GetUpperBound(0) + 32)
That way, you aren't redimensioning the the array every time that you add a new episode record.
- Follow-Ups:
- Re: How to dynamically resize an array?
- From: Michael Williams
- Re: How to dynamically resize an array?
- From: Mike
- Re: How to dynamically resize an array?
- References:
- How to dynamically resize an array?
- From: roidy
- Re: How to dynamically resize an array?
- From: Mike
- Re: How to dynamically resize an array?
- From: Family Tree Mike
- Re: How to dynamically resize an array?
- From: Mike
- Re: How to dynamically resize an array?
- From: roidy
- Re: How to dynamically resize an array?
- From: Gazmik
- How to dynamically resize an array?
- Prev by Date: Re: How to dynamically resize an array?
- Next by Date: Re: How to dynamically resize an array?
- Previous by thread: Re: How to dynamically resize an array?
- Next by thread: Re: How to dynamically resize an array?
- Index(es):
Relevant Pages
|