View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dan Thompson Dan Thompson is offline
external usenet poster
 
Posts: 125
Default arrayname as variable

Im not sure if I am getting this right but I think you have already assigned
an
Array() to a variable name if I got this right and now you want to pass it
to a function but your getting errors when the function try's to return a
value.

This is because when you pass an array to a function you almost always need
to specify if it is beeing passed "ByRef" or "ByVal" although I think you can
pass arrays to functions without the "ByVal" or "ByRef" if you are not using
Option Explicit not sure though cause I allways use them.
Anyhow try this...

function dosomethingwitharray (ByRef arrayname() as string) as variant
test1 = ubound(arrayname)
test2 = lbound(arrayname)
' do something with array
End function



"Jim Thomlinson" wrote:

An array is a variable not an object so it sould be passed more like this...
I assume you know what type of varaibles the array holds. If not then specify
variant

public function dosomethingwitharray (arrayname() as string) as variant
test1 = ubound(arrayname)
test2 = lbound(arrayname)
' do something with array
End function

--
HTH...

Jim Thomlinson


"devo" wrote:

Hi

Could someone please explain how to do the following

I wish to have a function which i can pass a string which is an array name
and then be allowed to manipulate the array

ie

array_width or array_drop

function dosomethingwitharray (arrayname as object)
test1 = arrayname.ubound
test2 = arrayname.lbound
' do something with array
End function

but i seem to be getting erros with setting and passing the arrayname