[Gambas-user] Multidimensional dynamic array basics

Kevin Fishburne kevinfishburne at ...1887...
Fri Aug 21 08:52:20 CEST 2015


On 08/21/2015 12:00 AM, Kevin Fishburne wrote:
> On Wed, Aug 19, 2015 at 9:22 AM, Kevin Fishburne <
> kevinfishburne at ...1887...> wrote:
>
>> I need to know how to declare, initialize and add elements to a
>> two-dimensional dynamic array. Using trial-and-error for every possible
>> syntax hasn't been too helpful so far. I'd post my code but it's pretty
>> useless and embarrassing and I think the basic question sums it up.
> On 08/19/2015 08:17 AM, Jussi Lahtinen wrote:
>> You can't do it dynamically with normal syntax:
>> Dim iMyArray As Integer[x, y]
>>
>> Instead use declaration like this:
>> Dim iMyArray As Integer[][]
>>
>> But then, you can't access it as the normal way (iMyArray[x, y]) either,
>> but instead:
>> iMyArray[x][y] = something
>>
>> iMyArray[x].Add(something)
>> iMyArray[x][y].Add(something)
>>
>> So, it's really array of arrays.
> Thanks everyone for the responses. The whole quadruple bracket thing
> [][] is what was confusing me. It's all good now. :)
>

Okay, I was wrong. I still don't know what I'm doing.

I need to dynamically add elements to SomeArray[][] and the syntax 
eludes me. I start with this:

Public StageListWall As ObjModel[][]
StageListWall = New ObjModel[][]

Then madness and stupidity ensues (this is but one example of dozens of 
combinations I've tried):

StageListWall.Add([Null])
StageListWall[0].Add(Null)

Obviously that doesn't work, but at this point I'm trying first to avoid 
syntax errors and second to actually get it working and understand why.

To bring context to the situation, in each stage there are x number of 
wall positions and y number of wall models per position, so assuming I 
can add elements to StageListWall[][] when loading the wall model 
display lists I would be able to access/refer to them like this:

StageListWall[Position][DisplayList]

There are an arbitrary number of positions and display lists per 
position. I also can't seem to refer to the length of individual arrays, 
such as by doing:

StageListWall[].Length

or

StageListWall[][].Length

The basic logic is that I would be referring to an individual display 
list using two numbers, position and list index. The display list itself 
would be the element value. If it were a static array it would look like 
this:

Public StageListWall[1000, 1000] as ObjModel
StageListWall[Position, DisplayList].Draw

The logic for the static array is dead simple, yet translating this to a 
dynamic array is just killing me. Obviously I can just implement it as 
static and "make it work", but I'd like to do it the proper/efficient 
way if it's possible. Any help is appreciated.

-- 
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...1887...
phone: (770) 853-6271





More information about the User mailing list