For example:
Public Type DEF
a as string
b as long
c as single
d as byte
End Type
Public Type ABC
name as string
index as long
itemdata as DEF()
End Type
I have no problem initally dimming the arrays and populating them. The
specs call for a maximum array size of ABC of 1 to 25, and DEF of 1 to
720.
Thus I begin with the follolowing
Dim udtABC() as ABC, i as long
Redim udtABC(1 to 25)
For i = 1 to 25
ReDim udtABC(i).itemdata(1 to 720)
Next i
The program then fills all the arrays and UDT variables with data,
quite efficiently. The problem is that there are far more variables
than shown here, so the ABC() array could be on the order of 20-30MB
by the time its filled with data for rendering. Thus, since the 25
element max on ABC() is rarely reached (as is the 720 max on DEF), I
would like to trim off the excess array elements.
Both of the following examples fail with a run-time error 9 and I
can't figure out why.
Dim defCount as Long, abcCount as Long
defCount = 600
ReDim Preserve udtABC(i).itemdata(defCount)
abcCount = 20
ReDim Preserve udtABC(abcCount)
Evan
They fail because you are specifying a lower bound in the declaration, and
using the implied lower bound in ReDim Preserve.
I seem to recall that is a recipe for disater. Something about excessive
memory requirements...
> Thus I begin with the follolowing
> Dim udtABC() as ABC, i as long
> Redim udtABC(1 to 25)
> For i = 1 to 25
> ReDim udtABC(i).itemdata(1 to 720)
> Next i
Note you use a lower bound of 1 (0 is the default, correct?)
> Both of the following examples fail with a run-time error 9 and I
> can't figure out why.
> Dim defCount as Long, abcCount as Long
> defCount = 600
> ReDim Preserve udtABC(i).itemdata(defCount)
>
> abcCount = 20
> ReDim Preserve udtABC(abcCount)
>
You let VB supply the lower bound (of 0) which is out of the
range you initially declared. The same error can be shown by
this example:
Dim A() As Long
ReDim A(1 To 5)
ReDim Preserve A(2)
HTH
LFS
Thanks "nobody" and Larry.
I would have changed the Option Base, except there are standard 0-
based arrays used in the software. In this case the two 1-base arrays
save a lot of extraneous calculations because the array indices are
explicitly stored in the binary data we're reading in.
Evan
"All your base are belong to us"