[Gambas-user] How do I remove an element of a multidimensional array
Tobias Boege
taboege at ...626...
Fri Dec 5 15:47:46 CET 2014
On Fri, 05 Dec 2014, Gian wrote:
> Il 05/12/2014 13:42, Martin McGlensey ha scritto:
> > Hello,
> >
> >
> >
> > I need to remove one element of a multidimensional array. The dimensions
> > are [10, 4]. I want to delete, for example, all elements of array row 1. Can
> > I do this?
> >
> >
> >
> > Marty
> >
>
> A way not particulary clever? Copy your array in another with one row less.
> Hi
> Gianluigi
>
And it doesn't get better than this if you stick to what I call "real multi-
dimensional (m-d) arrays". Their bounds (i.e. the number of dimensions and
the size of each dimension) are fixed after you created them. A typical real
m-d array declaration looks like this
Dim myArray As Integer[Dim1, Dim2, ..., DimN]
If that's the way you declared your array, you can only solve your problem
by copying the wanted data into another, smaller array.
However, there is a second kind of m-d arrays in Gambas which I call "derived
m-d arrays". These are classes constructed by the interpreter at runtime out
of other classes. If you let it create array classes from array classes (and
so forth), you can achieve a m-d layout of your data BUT by using only 1-d
arrays over which you have more operations available, as you know.
An example of a declaration of a derived m-d array is
Dim myArray As Integer[][]...[] ' As many brackets as you want dimensions
For the rest I must refer you to this thread[0] because the explanation is
a bit lengthy and I don't want to repeat it. Anyway, it turns out that the
derived m-d arrays are *way* more flexible and that you can delete rows,
columns and whatever you call their higher-dimensional analogues more easily.
If there are questions left, don't hesitate.
Regards,
Tobi
[0] http://sourceforge.net/p/gambas/mailman/message/32228140/
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list