Lorraine Donaldson wrote:

> To date, I have only used 2D arrays, but theoretically 
> it is not limited in the number of dimensions.  
> I think the limitation would lie with the redim statement:

>    redim rowI(iIndex).ColJ(iColumnCount).......

This is a fatal limitation: It won't compile.

I've never actually needed a 2D Array, but I've had plenty of
array of types that contain other types, and so on.

I've gotten around this by writing three routines for 
every user-defined type.  One copies an object of a the type,
One copies an array of the type, and the last resizes an 
array of the type,

So, Given the declaration:

type Foo
     '
     ' members...
     '
end type

You'd have

declare sub CopyFoo (src as foo, dest as foo)

declare sub CopyFooArray (src (0) as Foo, dest (0) as Foo, ByVal ct as
smallint, ByVal pad as smallint)

declare sub ResizeFooArray (a (0) as Foo, ByVal ct as smallint, ByVal pad as
smallint)

(Remember that unlike Visual Basic, MapBasic requires a
 dimension for every array. Since it can be redim'ed away 
 later, 0 is as good a dimension as any). 

The details of CopyFoo() vary from type to type, but the other
two are fixed:


sub CopyFooArray (src (0) as Foo, dest (0) as Foo, ByVal ct as smallint,
ByVal pad as smallint)

dim i as smallint

redim dest (ct+pad)

if ct > 0
   then for I = 1 to ct
            call CopyFoo (src (i), dest (i))
        next
end if
end sub


sub ResizeFooArray (a (0) as Foo, ByVal ct as smallint, ByVal pad as
smallint)

dim t (0) as foo

if ct > 0
   then call CopyFooArray (a, t, ct, 0)
        call CopyFooArray (t, a, ct, pad)
end if
end sub


(Notice that I never rely on Ubound() to tell me how many elements are
 in the array.  You could do this, but inserting and deleting elements
 would become much more expensive).


So, why am I bringing this up in a discussion of multi-dimensional arrays?

It turns out that a routine like ResizeFooArray() is the only way you'll be
able
to resize a specific element in the inner array, what Lorraine wanted to do
with
"redim rowI(iIndex).ColJ(iColumnCount)"

Given

type Bar
     '
     ' other members...
     '
     myfoos as smallint
     myfoo (0) as Foo
end type


CopyBar() can look like this:

sub CopyBar (src as Bar, dest as Bar)
'
' copy other members...
'
dest.myfoos=src.myfoos
call CopyFooArray (src.myfoo, dest.myfoo, dest.myfoos, 0)
end sub


In addition, given an array of Bar:

dim mybar(0) as Bar

you could eventually do something like

call ResizeFooArray (mybar(3).myfoo, 6, 0)



HTH
Spencer











---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 5274

Reply via email to