Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Shifting Array Elements

Hello all,

Any help would be greatly appreciated...

I have a perpetual data stream which I bring into Excel via a DDE link.
I store the data and run analysis on the most recent 40000 rows. I
use an array to hold a column of data for manipulation but I do not
want it to be any larger then 40000 rows.

How do I shift the data within the array so that the oldest element
stored "falls-off the end", all other elements shift up and the new
data element is placed in the array - all within one-half second.

Is there a method or combination of methods which will achieve this.
Maybe copying back-and-forth between two arrays? Any thoughts??

Thanks!

Trip

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Shifting Array Elements

I think I got it...

For i = 1 To 40000
testarray(i - 1) = testarray(i)
Next i

or vise versa.

Any better ways??

Thanks all!

Trip

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Shifting Array Elements

Assuming your array is 1 to 40000 (not 0 to 40000), I think you want:

For i = 2 To 40000
testarray(i - 1) = testarray(i)
Next i

testarray(40000) = NewValue

When i = 2 it assigns a value to testarray(1). The loop continues until
testarray(39999) is assigned. It could be restated (and maybe should be for
clarity) as:

For i = 1 To 39999
testarray(i) = testarray(i + 1)
Next i

testarray(40000) = NewValue

To me, that's a little clearer-at-a-glance that each array member is being
assigned the value from the member above, and just which members the loop
will effect.

HTH,
--
George Nicholson

Remove 'Junk' from return address.

"Trip" wrote in message
oups.com...
I think I got it...

For i = 1 To 40000
testarray(i - 1) = testarray(i)
Next i

or vise versa.

Any better ways??

Thanks all!

Trip



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Shifting Array Elements

Perhaps

RedDim testarray(1 to 39999)
RedDim testarray(1 to 40000)
testarray(40000) = "newValue"

Alan Beban

George Nicholson wrote:
Assuming your array is 1 to 40000 (not 0 to 40000), I think you want:

For i = 2 To 40000
testarray(i - 1) = testarray(i)
Next i

testarray(40000) = NewValue

When i = 2 it assigns a value to testarray(1). The loop continues until
testarray(39999) is assigned. It could be restated (and maybe should be for
clarity) as:

For i = 1 To 39999
testarray(i) = testarray(i + 1)
Next i

testarray(40000) = NewValue

To me, that's a little clearer-at-a-glance that each array member is being
assigned the value from the member above, and just which members the loop
will effect.

HTH,

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Shifting Array Elements

"Alan Beban" wrote in message
...
Perhaps

(1 to 39999)
RedDim testarray(1 to 40000)
testarray(40000) = "newValue"

Alan Beban



Hi Alan,

Would that not shift rather more than the first item out of the array?


---
Regards,
Norman


,




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Shifting Array Elements

Rather more, indeed! Sorry, I misposted. Intended

Redim Preserve testarray(1 to 39999)
Redim Preserve testarray(1 to 40000)
testarray(40000) = "newValue"

But even that was silly; it simply replaces the last value, not the
first, which can of course simply be done with

testarray(40000) ="newValue"

To drop the first array element, retain the rest and add "newValue" as
the 40,000th element, if the functions in the freely downloadable file
at http://home.pacbell.net/beban are available to your workbook, you
might consider

testarray=MakeArray(SubArray(testarray, 2, 40000), Array("newValue"), 1)

Alan Beban

Norman Jones wrote:
"Alan Beban" wrote in message
...

Perhaps

(1 to 39999)
RedDim testarray(1 to 40000)
testarray(40000) = "newValue"

Alan Beban




Hi Alan,

Would that not shift rather more than the first item out of the array?


---
Regards,
Norman


,


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Shifting Array Elements

Alan Beban wrote:
. . .
To drop the first array element, retain the rest and add "newValue" as
the 40,000th element, if the functions in the freely downloadable file
at http://home.pacbell.net/beban are available to your workbook, you
might consider

testarray=MakeArray(SubArray(testarray, 2, 40000), Array("newValue"), 1). . . .


Using the Array function is redundant.

testarray=MakeArray(SubArray(testarray, 2, 40000), "newValue", 1)

works fine.

Alan Beban
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
Use formulas for array elements hmm Excel Discussion (Misc queries) 3 December 3rd 07 01:15 PM
Reference Elements w/in an Array M Moore Excel Discussion (Misc queries) 2 October 16th 06 03:33 PM
date array shifting kimdnw Excel Discussion (Misc queries) 2 February 8th 06 10:30 PM
Non-unique elements in an array Andrew Excel Discussion (Misc queries) 1 August 22nd 05 11:58 AM
Count elements in array Jason Morin[_3_] Excel Programming 7 January 31st 05 09:32 PM


All times are GMT +1. The time now is 03:57 AM.

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

About Us

"It's about Microsoft Excel"