5 Replies - 7918 Views - Last Post: 22 June 2009 - 09:01 AM Rate Topic: -----

#1 erickrimmel  Icon User is offline

  • New D.I.C Head

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

delete row in multi-dimensional array

Post icon  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  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 zql  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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!
Was This Post Helpful? 0
  • +
  • -

#4 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#5 erickrimmel  Icon User is offline

  • New D.I.C Head

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

Re: delete row in multi-dimensional array

Posted 22 June 2009 - 04:46 AM

View Postmark.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.



View Postmark.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.
Was This Post Helpful? 0
  • +
  • -

#6 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1