Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Impact of Fees on Growth Rate | Excel Discussion (Misc queries) | |||
Visualizing fiscal year impact | Excel Discussion (Misc queries) | |||
Impact of many VLOOKUPs in a spreadsheet | Excel Worksheet Functions | |||
OS Version impact on Excel functionality | Excel Worksheet Functions | |||
Hiding sheets - Impact on Speed | Excel Discussion (Misc queries) |