Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Performance Impact: By Reference or By Value

Assuming that you're not modifying a parameter within a procedure, is there
any performance difference in passing the parameter as 'ByRef' or 'ByVal'.

For example

Dim arr as variant
arr = Array(12,40)
arr = TimesTwo(arr)

Function TimesTwo(ByRef or ByVal arr as variant)
Dim i as integer,arrTemp as variant
Redim arrTemp(ubound(arr))
For i = lbound(arr) to ubound(arr)
arrTemp(i) = 2 * arr(i)
Next
TimesTwo = arrTemp
End Function

Also can arrays only be declared as variants in situations such as this one.

Thanks,
Wayne C.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Performance Impact: By Reference or By Value

You can only assign an array to a variant or (exl2000 and later) to an
dynamic variant array.

I would think passing byval would require copying the array and this would
incur a penalty.

--
Regards,
Tom Ogilvy

"TheVisionThing" wrote in message
m...
Assuming that you're not modifying a parameter within a procedure, is

there
any performance difference in passing the parameter as 'ByRef' or 'ByVal'.

For example

Dim arr as variant
arr = Array(12,40)
arr = TimesTwo(arr)

Function TimesTwo(ByRef or ByVal arr as variant)
Dim i as integer,arrTemp as variant
Redim arrTemp(ubound(arr))
For i = lbound(arr) to ubound(arr)
arrTemp(i) = 2 * arr(i)
Next
TimesTwo = arrTemp
End Function

Also can arrays only be declared as variants in situations such as this

one.

Thanks,
Wayne C.





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Performance Impact: By Reference or By Value

Interesting info, Tom, thanks.

By dynamic variant array in Excel 2000 or later, did you mean:

Dim arr as variant
Redim arr(2,2)
Redim Preserve arr(2,50)

Where only the last dimension of the array can be altered.

Regards,
Wayne C.

"Tom Ogilvy" wrote in message
...
You can only assign an array to a variant or (exl2000 and later) to an
dynamic variant array.

I would think passing byval would require copying the array and this would
incur a penalty.

--
Regards,
Tom Ogilvy

"TheVisionThing" wrote in message
m...
Assuming that you're not modifying a parameter within a procedure, is

there
any performance difference in passing the parameter as 'ByRef' or
'ByVal'.

For example

Dim arr as variant
arr = Array(12,40)
arr = TimesTwo(arr)

Function TimesTwo(ByRef or ByVal arr as variant)
Dim i as integer,arrTemp as variant
Redim arrTemp(ubound(arr))
For i = lbound(arr) to ubound(arr)
arrTemp(i) = 2 * arr(i)
Next
TimesTwo = arrTemp
End Function

Also can arrays only be declared as variants in situations such as this

one.

Thanks,
Wayne C.







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Performance Impact: By Reference or By Value

No,
Dim arr() as Variant

as opposed to

Dim arr as Variant

However, there is no advantage to doing that and it just makes it
incompatible with xl97.

--
Regards,
Tom Ogilvy

"TheVisionThing" wrote in message
m...
Interesting info, Tom, thanks.

By dynamic variant array in Excel 2000 or later, did you mean:

Dim arr as variant
Redim arr(2,2)
Redim Preserve arr(2,50)

Where only the last dimension of the array can be altered.

Regards,
Wayne C.

"Tom Ogilvy" wrote in message
...
You can only assign an array to a variant or (exl2000 and later) to an
dynamic variant array.

I would think passing byval would require copying the array and this

would
incur a penalty.

--
Regards,
Tom Ogilvy

"TheVisionThing" wrote in message
m...
Assuming that you're not modifying a parameter within a procedure, is

there
any performance difference in passing the parameter as 'ByRef' or
'ByVal'.

For example

Dim arr as variant
arr = Array(12,40)
arr = TimesTwo(arr)

Function TimesTwo(ByRef or ByVal arr as variant)
Dim i as integer,arrTemp as variant
Redim arrTemp(ubound(arr))
For i = lbound(arr) to ubound(arr)
arrTemp(i) = 2 * arr(i)
Next
TimesTwo = arrTemp
End Function

Also can arrays only be declared as variants in situations such as this

one.

Thanks,
Wayne C.









  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Performance Impact: By Reference or By Value

Understood. Thanks.

Regards,
Wayne C.

"Tom Ogilvy" wrote in message
...
No,
Dim arr() as Variant

as opposed to

Dim arr as Variant

However, there is no advantage to doing that and it just makes it
incompatible with xl97.

--
Regards,
Tom Ogilvy

"TheVisionThing" wrote in message
m...
Interesting info, Tom, thanks.

By dynamic variant array in Excel 2000 or later, did you mean:

Dim arr as variant
Redim arr(2,2)
Redim Preserve arr(2,50)

Where only the last dimension of the array can be altered.

Regards,
Wayne C.

"Tom Ogilvy" wrote in message
...
You can only assign an array to a variant or (exl2000 and later) to an
dynamic variant array.

I would think passing byval would require copying the array and this

would
incur a penalty.

--
Regards,
Tom Ogilvy

"TheVisionThing" wrote in message
m...
Assuming that you're not modifying a parameter within a procedure, is
there
any performance difference in passing the parameter as 'ByRef' or
'ByVal'.

For example

Dim arr as variant
arr = Array(12,40)
arr = TimesTwo(arr)

Function TimesTwo(ByRef or ByVal arr as variant)
Dim i as integer,arrTemp as variant
Redim arrTemp(ubound(arr))
For i = lbound(arr) to ubound(arr)
arrTemp(i) = 2 * arr(i)
Next
TimesTwo = arrTemp
End Function

Also can arrays only be declared as variants in situations such as
this
one.

Thanks,
Wayne C.











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
Impact of Fees on Growth Rate dlb21 Excel Discussion (Misc queries) 1 April 23rd 10 03:41 PM
Visualizing fiscal year impact Tiffany McKerahan Excel Discussion (Misc queries) 0 April 8th 10 02:36 PM
Impact of many VLOOKUPs in a spreadsheet Chuck M Excel Worksheet Functions 2 August 8th 08 03:19 PM
OS Version impact on Excel functionality Peter-d Excel Worksheet Functions 1 March 23rd 06 12:15 AM
Hiding sheets - Impact on Speed Timmy Mac1 Excel Discussion (Misc queries) 4 December 13th 05 07:08 PM


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