Array.Copy and Multi-dimensional arrays...

  • Thread starter Thread starter rmorvay
  • Start date Start date
R

rmorvay

I have a requirement to search a multi-dimensional array for an item, then
delete the item and "reset" the array so that their are no gaps in the
resulting array. I have been trying to figure out how to use the Array.Copy
method to accomplish this but it seems to only work for single dimension
arrays. Here is a code sample:

'dim arrTest(600,3) as string 'Actual array dimension needed
dim arrTest(600) as string 'Used only in this test
dim intIndex as Integer
dim randomNum as New Random()

'Get random index into array for delete test
intIndex = random.Next(0, UBound(arrTest))

'Shifts elements from arrTest(intIndex + 1) to arrTest(intIndex)
Array.Copy(arrTest, intIndex + 1, arrTest, intIndex, UBound(arrTest) - 1)

'Clears the last element
arrTest.Clear(arrTest, arrTest.GetUpperBound(0), 1)

Any idea on how to modify this code or let me know a better approach to
doing this for a multidimensional array?

Thanks in advance.
 
I am not sure how I could use the ArrayList. My understanding is that the
ArrayList is a single dimension approach. Would I have to deconstruct the 2
dimensional array to accomplish this?
 
Thanks. I think I can use an ArrayList with a structure to accomplish my
requirements without a need for a major code overhaul.
 
Back
Top