Sunday 15 March 2015

How to pass an array to function in VBA? -



How to pass an array to function in VBA? -

i tryint write function accepts array argument. array can have number of elements.

function processarr(arr() variant) string dim n variant dim finalstr string n = lbound(arr) ubound(arr) finalstr = finalstr & arr(n) next n processarr = finalstr end function

here how seek phone call function:

sub test() dim fstring string fstring = processarr(array("foo", "bar")) end sub

i error saying:

compile error: type mismatch: array or user defined type expected.

what doing wrong?

this seems unnecessary, vba unusual place. if declare array variable, set using array() pass variable function, vba happy.

sub test() dim fstring string dim arr() variant arr = array("foo", "bar") fstring = processarr(arr) end sub

also function processarr() written as:

function processarr(arr() variant) string processarr = replace(join(arr()), " ", "") end function

if whole brevity thing.

arrays vba function ms-access access-vba

No comments:

Post a Comment