Passing an array in a user defined function

L

Laurie

Hi,

I am wondering that, in the below post from Charles (on Feb 3rd, 2005),
after declaring "Array1 as Variant" in the user-defined function name, then
in the UDF codes, should we declare Array1 again for its dimension(s)?

Basically, how to make use of Array1 in the UDF, if Array1 has been defined
in another UDF?

For example,

1. In defining the UDF function 1:

Functionname1()

--- Array1 is defined and assigned values
--- Functioname2(Array1,...)

End Function

2. In defining the UDF function 2:

Funcitonname2(Array1 as variant, ...)
...
End Function


My questions are:

a) In item 1 above for defining the functionname1 to use the second UDF
functionname2, what is the right syntax for specifying Array1 as a parameter
arguement of functionname2?

b) In item 2 above for defining the functionname2, how do we use the Array1
or how do we change the elements' values of Array 1 in the functionname2?

Thank you very much in advance and any suggestion would be highly
appreciated!!!


Sincerely,
Laurie
 
J

Joel

Function name1(Array1 As Variant)

Array_Sum = 0
For i = 1 To UBound(Array1)
Array_Sum = Array_Sum + Array1(i)
Next i
name1 = name2(Array1, "a", "b", "C")

End Function


Function name2(Array1 As Variant, parm2, parm3, parm4)

Array_Sum = 0
For i = 1 To UBound(Array1)
Array_Sum = Array_Sum + Array1(i)
Next i

name2 = Array_Sum
End Function
 
L

Laurie

Thanks Joel!!

I am gonna try your suggestion.

One more thing is that in specifying "Array1 as Variant" as a parameter for
the UDF "name1" or "name2", will "Array1() as Variant" also be ok?

Thanks again,
Laurie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top