# delete row in multi-dimensional array

Page 1 of 1

## 5 Replies - 10246 Views - Last Post: 22 June 2009 - 09:01 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=110697&amp;s=94b68f6ee8c10d36068a543c770a26c4&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 erickrimmel

Reputation: 0
• Posts: 8
• Joined: 06-April 07

# delete row in multi-dimensional array

Posted 18 June 2009 - 08:02 AM

Is it possable to remove a row from a multi-dimensional array?
Is so, how?
Is This A Good Question/Topic? 0

## Replies To: delete row in multi-dimensional array

### #2 mark.bottomley

Reputation: 176
• Posts: 990
• Joined: 22-April 09

## Re: delete row in multi-dimensional array

Posted 18 June 2009 - 10:34 AM

The implementation of multi-dimensional arrays in VB.net is that only the last dimension actually contains data, all the other dimensions are 1 dimensional arrays of pointers to 1-dimensional arrays of pointers... to 1 dimensional arrays of data.
e.g. B(X,Y) with X down and Y across below:

0: ptr to Y(0) = {0, 1, 2,..., Y-1}
1: ptr to Y(1) = {0, 1, 2,..., Y-1}
...
X-1: ptr to Y(X-1) = {0, 1, 2,..., Y-1}

This allows VB.Net to have "ragged" arrays as each Row does not need to be the same length. e.g. Y(1) could be {0, 1, 2} - it does not need Y values. IIRC, ragged only applies to the last dimension of the array.

You are left with one of three problems, 1) the array now has a missing row, that is a pointer to Nothing in VB terms so deal with it when walking the array, or 2) After deleteing row J, you now shift row J+1 to J and so on and then either ReDim the array to get rid of the last row pointer or keep an external active dimension length variable (prevents using .Count etc.), or 3) you chose a better suited data structure for your problem - one that allows you to remove data in the middle with little overhead.

I suspect you are using the wrong data structure based on the question. Maybe you should tell us the real problem you are trying to solve.

### #3 zql

Reputation: 1
• Posts: 19
• Joined: 14-June 09

## Re: delete row in multi-dimensional array

Posted 18 June 2009 - 01:10 PM

Is it possible for collections to be multidimensional?

In the past, when I needed to delete a row from a multidimensional array.. I would either add in a variable to represent a flag, or if I had a string in there somewhere, I would use that instead.
Basically, when you need to delete a row.. just flag or mark it as "DELETED" and then have your code skip over any DELETED rows when reading. If you need to refer to your array items with an index, then you'll have to transfer the data to a second array without the deleted rows.
Simple deletion of lines from multidimensional arrays!

### #4 mark.bottomley

Reputation: 176
• Posts: 990
• Joined: 22-April 09

## Re: delete row in multi-dimensional array

Posted 18 June 2009 - 06:20 PM

Multi-dimensional collections are possible, but they are not indexable like arrays. Again, the question is - what are you trying to do! You don't need a deleted flag, just check for the row being "Nothing", no extra overhad of flags. (version 1) above).

This post has been edited by mark.bottomley: 18 June 2009 - 06:23 PM

### #5 erickrimmel

Reputation: 0
• Posts: 8
• Joined: 06-April 07

## Re: delete row in multi-dimensional array

Posted 22 June 2009 - 04:46 AM

mark.bottomley, on 18 Jun, 2009 - 09:34 AM, said:

The implementation of multi-dimensional arrays in VB.net is that only the last dimension actually contains data, all the other dimensions are 1 dimensional arrays of pointers to 1-dimensional arrays of pointers... to 1 dimensional arrays of data.
e.g. B(X,Y) with X down and Y across below:

0: ptr to Y(0) = {0, 1, 2,..., Y-1}
1: ptr to Y(1) = {0, 1, 2,..., Y-1}
...
X-1: ptr to Y(X-1) = {0, 1, 2,..., Y-1}

This allows VB.Net to have "ragged" arrays as each Row does not need to be the same length. e.g. Y(1) could be {0, 1, 2} - it does not need Y values. IIRC, ragged only applies to the last dimension of the array.

You are left with one of three problems, 1) the array now has a missing row, that is a pointer to Nothing in VB terms so deal with it when walking the array, or 2) After deleteing row J, you now shift row J+1 to J and so on and then either ReDim the array to get rid of the last row pointer or keep an external active dimension length variable (prevents using .Count etc.), or 3) you chose a better suited data structure for your problem - one that allows you to remove data in the middle with little overhead.

I suspect you are using the wrong data structure based on the question. Maybe you should tell us the real problem you are trying to solve.

mark.bottomley, on 18 Jun, 2009 - 09:34 AM, said:

The implementation of multi-dimensional arrays in VB.net is that only the last dimension actually contains data, all the other dimensions are 1 dimensional arrays of pointers to 1-dimensional arrays of pointers... to 1 dimensional arrays of data.
e.g. B(X,Y) with X down and Y across below:

0: ptr to Y(0) = {0, 1, 2,..., Y-1}
1: ptr to Y(1) = {0, 1, 2,..., Y-1}
...
X-1: ptr to Y(X-1) = {0, 1, 2,..., Y-1}

This allows VB.Net to have "ragged" arrays as each Row does not need to be the same length. e.g. Y(1) could be {0, 1, 2} - it does not need Y values. IIRC, ragged only applies to the last dimension of the array.

You are left with one of three problems, 1) the array now has a missing row, that is a pointer to Nothing in VB terms so deal with it when walking the array, or 2) After deleteing row J, you now shift row J+1 to J and so on and then either ReDim the array to get rid of the last row pointer or keep an external active dimension length variable (prevents using .Count etc.), or 3) you chose a better suited data structure for your problem - one that allows you to remove data in the middle with little overhead.

I suspect you are using the wrong data structure based on the question. Maybe you should tell us the real problem you are trying to solve.

I am using a text file to keep track of data on people. The code allows the user to enter people and data into an array that gets saved to the file. I want a way to delete incorrect names and data or names that have allready been entered.

### #6 mark.bottomley

Reputation: 176
• Posts: 990
• Joined: 22-April 09

## Re: delete row in multi-dimensional array

Posted 22 June 2009 - 09:01 AM

I would read the full array into memory and tag the lines of the array for people you want deleted. Upon exit, I would write back to the file only the valid lines.

If there is no order/sorting to the people then you can store the data into a structure and organize the structure with a linked list or a collection. Deleting from either fo these collections is easy and then just uptput the remaining collection items at program shutdown. The trick becomes dumping from and loading to the collection.