Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Fast way to add two array in VBA

It seems (see previous discussion) that the function "redim" is much
faster than going through a loop to reset an array to its initial
value.

I was wondering if there was a similar "smart" way to add two arrays
together, ie

doing something like

X=ZeSmartFunction(X,Y)

instead of

for i = 1 to n
X(i)=X(i)+Y(i)
next i

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Fast way to add two array in VBA

Redim sets the array's elements to blank. You don't want to set it to blank,
so you'll have to add the values together to generate new non-blank values.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Charles" wrote in message
ups.com...
It seems (see previous discussion) that the function "redim" is much
faster than going through a loop to reset an array to its initial
value.

I was wondering if there was a similar "smart" way to add two arrays
together, ie

doing something like

X=ZeSmartFunction(X,Y)

instead of

for i = 1 to n
X(i)=X(i)+Y(i)
next i



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Fast way to add two array in VBA

Jon Peltier wrote:
Redim sets the array's elements to blank. . . .


No. If the array type is String(), it resets them to blank. But, e.g.,
if the array type is Boolean(), it resets them to False; and if the
array type is Integer() or Double(), iit resets them to 0.

Alan Beban
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Fast way to add two array in VBA

Duh, I was trying to differentiate between default values, which Alan has
clarified, and "initial" values, which may not be the default values,
depending on how the user has initialized the array. Unfortunately I rushed
through my response.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Alan Beban" wrote in message
...
Jon Peltier wrote:
Redim sets the array's elements to blank. . . .


No. If the array type is String(), it resets them to blank. But, e.g., if
the array type is Boolean(), it resets them to False; and if the array
type is Integer() or Double(), iit resets them to 0.

Alan Beban



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Fast way to add two array in VBA

Thanks. Actually I was mostly interested in a way to add two arrays. I
haven't found anything on google nor in VBA's help. I guess there is
no faster way to add two arrays together than to go through every
single element with a loop.

Charles



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Fast way to add two array in VBA

There might be easier ways, but not faster ways, if you have access to
functions that do the hard work in the function and you only see the
function call:

NewArray = SumArrays(Array1, Array2)

I'm sure there are slower ways.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Charles" wrote in message
oups.com...
Thanks. Actually I was mostly interested in a way to add two arrays. I
haven't found anything on google nor in VBA's help. I guess there is
no faster way to add two arrays together than to go through every
single element with a loop.

Charles



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
Fast export large 2-dim array to worksheet aafraga Excel Programming 3 February 8th 06 02:59 PM
Need help fast! [email protected] Excel Discussion (Misc queries) 2 October 1st 05 04:10 AM
need help fast! spectator Excel Programming 6 July 27th 05 07:39 AM
range to VBA array, and doing this fast Erich Neuwirth Excel Programming 1 September 12th 04 04:25 PM
Remove First Row from Variant Array FAST? R Avery Excel Programming 18 August 20th 04 03:29 PM


All times are GMT +1. The time now is 05:29 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"