realbasic-nug
[Top] [All Lists]

Re: Deleting a row of a Multi-Dimension Array

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Deleting a row of a Multi-Dimension Array
From: CV <atauqua at hit dot net>
Date: Mon, 31 Jan 2005 17:11:27 -0600
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <7A8AB8CC-61F7-11D9-AF1C-000A95728606 at aboutfacedata dot ab dot ca> <a06200701be071346d041 at [10 dot 10 dot 13 dot 4]> <3FC9FAD7-730D-11D9-81C8-000A95DB6C90 at fireyesoftware dot com>
You can use a method something like this to delete a row in a 2D numeric array:

Sub DeleteRow(mArray(,) as double, Row as integer)
  dim i, j as integer
  dim LastRow, LastColumn as integer

  LastRow = UBound(mArray,1)        //cache some limits
  LastColumn = UBound(mArray,2)

  For i = Row to LastRow
    For j = 0 to LastColumn
      If i + 1 <= LastRow then
        mArray(i, j) = mArray(i +1, j)
      End if
    Next
  Next

  Redim mArray(LastRow - 1, LastColumn)
End Sub

Note the "," in the parameter mArray(,).

For a test call, from a button, for example:

  dim MultiArray(10,10) as double
  dim i, j,UboundRow,UBoundCol as integer

  'Populate an array with whatever
  For i = 0 to 2
    For j = 0 to 2
      MultiArray(i, j) = i + j + 1
    Next
  Next

  'set UBound to reflect actual population before call
  Redim MultiArray(i -1, j -1)

  'Call method to delete row 2 of MultiArray
  DeleteRow(MultiArray, 2)

HTH,

Jack


On Jan 9, 2005, at 11:59 AM, Joseph J. Strout wrote:

I can't seem to find a simple way to delete a row of a multi-dimension array, from the middle of the array, given that the array.remove method only works for single dimension arrays?

That's right. There's no simple way to remove a column, either (nor a higher-dimensional slab of a multi-dimensional arrays).

Is the only way some strange re-assignment and redim operation?


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>