ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Arrays as Arguments in Functions (https://www.excelbanter.com/excel-programming/302278-arrays-arguments-functions.html)

Dean[_6_]

Arrays as Arguments in Functions
 
I'm having some trouble with this function. I want to
preserve the values of array between calls to a function.
But I cannot figure out how to define the argument for the
function and what the call function statement should look
like. Has anyone done this?

Charles Williams

Arrays as Arguments in Functions
 
You can either declare the arrays as static or as module level variables.

Charles
______________________
Decision Models
The Excel Calculation Site.
www.DecisionModels.com

"Dean" wrote in message
...
I'm having some trouble with this function. I want to
preserve the values of array between calls to a function.
But I cannot figure out how to define the argument for the
function and what the call function statement should look
like. Has anyone done this?




Stephen Bullen[_3_]

Arrays as Arguments in Functions
 
Hi Dean,

I'm having some trouble with this function. I want to
preserve the values of array between calls to a function.
But I cannot figure out how to define the argument for the
function and what the call function statement should look
like. Has anyone done this?


Something like this (untested):

Sub Test()

Dim asStuff(0 to 1) As String

asStuff(0) = "Hello"
asStuff(1) = "Goodbye"

MsgBox WhatString(asStuff)

End Sub

Function WhatString(ByRef asArray() As String) As String
WhatString = asArray(0) & ", " & asArray(1)
End Function

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.ie



Dean[_7_]

Arrays as Arguments in Functions
 

Thanks! I thought I had to use as Variant and it wasn't working.


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT +1. The time now is 04:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com