Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Deleting an element in the middle of an array

I have my own dynamic array

Type LinkInfo
href As String
InnerText As String
End Type

Dim Links() As LinkInfo

which I am redimensioning as I go along

but I have the need to delete an array element, e.g. links(5) from the
middle of the array when its upper bound is 10

How do I do this please. I can only find the erase method to purge the
whole array
--
Mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Deleting an element in the middle of an array

On Sun, 13 Mar 2005 at 05:14:31, Mike NG (Mike NG
) wrote:
I have my own dynamic array

Type LinkInfo
href As String
InnerText As String
End Type

Dim Links() As LinkInfo

which I am redimensioning as I go along

but I have the need to delete an array element, e.g. links(5) from the
middle of the array when its upper bound is 10

How do I do this please. I can only find the erase method to purge the
whole array

I've also tried Links.Remove 5, but this doesn't appear to work

It appears as though I have to filter my array to a new array and copy
everything over manually
--
Mike
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Deleting an element in the middle of an array

Mike,

There is a simpler way using Filter. Here is an example

Dim vMatch
Dim i As Long
Dim ary

ary = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
For i = LBound(ary) To UBound(ary)
Debug.Print ary(i)
Next i

vMatch = Chr(255)
ary(7) = vMatch ' change the 8
ary = Filter(ary, vMatch, False)
For i = LBound(ary) To UBound(ary)
Debug.Print ary(i)
Next i

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mike NG" wrote in message
...
On Sun, 13 Mar 2005 at 05:14:31, Mike NG (Mike NG
) wrote:
I have my own dynamic array

Type LinkInfo
href As String
InnerText As String
End Type

Dim Links() As LinkInfo

which I am redimensioning as I go along

but I have the need to delete an array element, e.g. links(5) from the
middle of the array when its upper bound is 10

How do I do this please. I can only find the erase method to purge the
whole array

I've also tried Links.Remove 5, but this doesn't appear to work

It appears as though I have to filter my array to a new array and copy
everything over manually
--
Mike



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Deleting an element in the middle of an array

Is there a Filter function that works with 2-D arrays?

RBS


"Bob Phillips" wrote in message
...
Mike,

There is a simpler way using Filter. Here is an example

Dim vMatch
Dim i As Long
Dim ary

ary = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
For i = LBound(ary) To UBound(ary)
Debug.Print ary(i)
Next i

vMatch = Chr(255)
ary(7) = vMatch ' change the 8
ary = Filter(ary, vMatch, False)
For i = LBound(ary) To UBound(ary)
Debug.Print ary(i)
Next i

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mike NG" wrote in message
...
On Sun, 13 Mar 2005 at 05:14:31, Mike NG (Mike NG
) wrote:
I have my own dynamic array

Type LinkInfo
href As String
InnerText As String
End Type

Dim Links() As LinkInfo

which I am redimensioning as I go along

but I have the need to delete an array element, e.g. links(5) from the
middle of the array when its upper bound is 10

How do I do this please. I can only find the erase method to purge the
whole array

I've also tried Links.Remove 5, but this doesn't appear to work

It appears as though I have to filter my array to a new array and copy
everything over manually
--
Mike




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Deleting an element in the middle of an array

We wish :-)

--

HTH

RP
(remove nothere from the email address if mailing direct)


"RB Smissaert" wrote in message
...
Is there a Filter function that works with 2-D arrays?

RBS


"Bob Phillips" wrote in message
...
Mike,

There is a simpler way using Filter. Here is an example

Dim vMatch
Dim i As Long
Dim ary

ary = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
For i = LBound(ary) To UBound(ary)
Debug.Print ary(i)
Next i

vMatch = Chr(255)
ary(7) = vMatch ' change the 8
ary = Filter(ary, vMatch, False)
For i = LBound(ary) To UBound(ary)
Debug.Print ary(i)
Next i

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mike NG" wrote in message
...
On Sun, 13 Mar 2005 at 05:14:31, Mike NG (Mike NG
) wrote:
I have my own dynamic array

Type LinkInfo
href As String
InnerText As String
End Type

Dim Links() As LinkInfo

which I am redimensioning as I go along

but I have the need to delete an array element, e.g. links(5) from the
middle of the array when its upper bound is 10

How do I do this please. I can only find the erase method to purge

the
whole array

I've also tried Links.Remove 5, but this doesn't appear to work

It appears as though I have to filter my array to a new array and copy
everything over manually
--
Mike








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Deleting an element in the middle of an array

Yes, didn't think there was.
Luckily, just looping through the array elements is quite fast.

RBS

"Bob Phillips" wrote in message
...
We wish :-)

--

HTH

RP
(remove nothere from the email address if mailing direct)


"RB Smissaert" wrote in message
...
Is there a Filter function that works with 2-D arrays?

RBS


"Bob Phillips" wrote in message
...
Mike,

There is a simpler way using Filter. Here is an example

Dim vMatch
Dim i As Long
Dim ary

ary = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
For i = LBound(ary) To UBound(ary)
Debug.Print ary(i)
Next i

vMatch = Chr(255)
ary(7) = vMatch ' change the 8
ary = Filter(ary, vMatch, False)
For i = LBound(ary) To UBound(ary)
Debug.Print ary(i)
Next i

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mike NG" wrote in message
...
On Sun, 13 Mar 2005 at 05:14:31, Mike NG (Mike NG
) wrote:
I have my own dynamic array

Type LinkInfo
href As String
InnerText As String
End Type

Dim Links() As LinkInfo

which I am redimensioning as I go along

but I have the need to delete an array element, e.g. links(5) from
the
middle of the array when its upper bound is 10

How do I do this please. I can only find the erase method to purge

the
whole array

I've also tried Links.Remove 5, but this doesn't appear to work

It appears as though I have to filter my array to a new array and copy
everything over manually
--
Mike






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Deleting an element in the middle of an array

On Sun, 13 Mar 2005 at 12:02:32, Bob Phillips (Bob Phillips
) wrote:
We wish :-)

Cheers Bob

Nice idea - except my array of type LinkInfo is effectively 2D isn't it?
--
Mike
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Deleting an element in the middle of an array

Mike NG wrote:
I have my own dynamic array

Type LinkInfo
href As String
InnerText As String
End Type

Dim Links() As LinkInfo

which I am redimensioning as I go along

but I have the need to delete an array element, e.g. links(5) from the
middle of the array when its upper bound is 10

How do I do this please. I can only find the erase method to purge the
whole array

Is Links a one-column array?

Alan Beban
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Deleting an element in the middle of an array

On Sun, 13 Mar 2005 at 12:41:22, Alan Beban (Alan Beban
) wrote:
Mike NG wrote:
I have my own dynamic array
Type LinkInfo
href As String
InnerText As String
End Type
Dim Links() As LinkInfo
which I am redimensioning as I go along
but I have the need to delete an array element, e.g. links(5) from
the
middle of the array when its upper bound is 10
How do I do this please. I can only find the erase method to purge
the
whole array

Is Links a one-column array?

Depends what you mean, but each element of the Links() array is of type
LinkInfo

I have decided to carry on using arrays. For the sake of being able to
use add and delete easily, referencing the elements as (0), (1), (2) etc
is not as friendly as using .href, .Innertext etc
--
Mike
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Deleting an element in the middle of an array

If you have a need to remove an element from the middle of an 'array'
then an array is probably the wrong data type structure to begin with.
Consider a linked list.
How To Implement a Linked List in Visual Basic
http://support.microsoft.com/default...b;en-us;166394

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
I have my own dynamic array

Type LinkInfo
href As String
InnerText As String
End Type

Dim Links() As LinkInfo

which I am redimensioning as I go along

but I have the need to delete an array element, e.g. links(5) from the
middle of the array when its upper bound is 10

How do I do this please. I can only find the erase method to purge the
whole array



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Deleting an element in the middle of an array

On Mon, 14 Mar 2005 at 19:25:10, Tushar Mehta (Tushar Mehta
) wrote:
If you have a need to remove an element from the middle of an 'array'
then an array is probably the wrong data type structure to begin with.
Consider a linked list.
How To Implement a Linked List in Visual Basic
http://support.microsoft.com/default...b;en-us;166394

Cool never thought of that

May consider this for a future project
--
Mike
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Deleting an element in the middle of an array

Hi,
you might want to investigate the Scripting.Dictionary object as well.

Hth,
O

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set array element to empty Raul Excel Programming 2 March 2nd 05 03:53 PM
Array Element question S G Booth Excel Programming 5 February 23rd 05 09:59 PM
Array element Andrea[_8_] Excel Programming 5 December 7th 04 08:24 PM
Deleting data and element in a 1D array ExcelMonkey[_124_] Excel Programming 11 May 17th 04 06:29 AM
deleting array element michael Excel Programming 0 December 18th 03 08:55 PM


All times are GMT +1. The time now is 02:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"