B
Birgit
Hi all,
I am trying to sort out the fijner points of passing arrays between
functions. I simply do not understand how this works. Of course I get it all
to work with a global array, which I can modify anytime, but I'd rather
learn to do it by passing arguments. I have already found to use ByRef while
digging in the archive.
If I run the function UseArray I get as result:
, bla
instead of
<some character> , bla
what's wrong?
code follows
-------
Function MakeArray(ByRef myArray As Variant)
Dim teller As Long
For teller = 1 To 10
'assign some random alphanumeric stuff to array
myArray(teller) = Chr(teller * 10)
Next teller
End Function
Function UseArray()
Dim varArr As Variant
Dim i As Long
'give a large dimension here because can't redim preserve inside other
function
'can be shrunk afterwards if I ever get this to work
'this code is just a tryout for other stuff I'm doing in a project where
I don't know
'how many items I pick up along the way.
ReDim varArr(100)
MakeArray (varArr)
For i = 1 To 10
Debug.Print varArr(i) & " , bla"
Next i
End Function
I am trying to sort out the fijner points of passing arrays between
functions. I simply do not understand how this works. Of course I get it all
to work with a global array, which I can modify anytime, but I'd rather
learn to do it by passing arguments. I have already found to use ByRef while
digging in the archive.
If I run the function UseArray I get as result:
, bla
instead of
<some character> , bla
what's wrong?
code follows
-------
Function MakeArray(ByRef myArray As Variant)
Dim teller As Long
For teller = 1 To 10
'assign some random alphanumeric stuff to array
myArray(teller) = Chr(teller * 10)
Next teller
End Function
Function UseArray()
Dim varArr As Variant
Dim i As Long
'give a large dimension here because can't redim preserve inside other
function
'can be shrunk afterwards if I ever get this to work
'this code is just a tryout for other stuff I'm doing in a project where
I don't know
'how many items I pick up along the way.
ReDim varArr(100)
MakeArray (varArr)
For i = 1 To 10
Debug.Print varArr(i) & " , bla"
Next i
End Function