pass array as parameter ByRef

  • Thread starter Thread starter david epsom dot com dot au
  • Start date Start date
D

david epsom dot com dot au

I have an array declared like this:

ReDim xy_listBid(0 To 1, 0 To cln.Count - 1) As Double


I would like to pass that array to a subroutine, ByRef,
so that values can be updated.

I can't change the array definition: it is later passed
to a C api. I can't use a variant.

How do I declare a function which takes that array as a parameter?

(david)
 
david epsom dot com dot au said:
I have an array declared like this:

ReDim xy_listBid(0 To 1, 0 To cln.Count - 1) As Double


I would like to pass that array to a subroutine, ByRef,
so that values can be updated.

I can't change the array definition: it is later passed
to a C api. I can't use a variant.

How do I declare a function which takes that array as a parameter?

(david)

Am I missing something?

I think the array must be passed by reference. Would something like
this
run on your setup?

Sub MyArrTest(ByRef r_arr() As Double)

Dim i As Long
Dim j As Long

For i = 0 To 1
For j = 0 To UBound(r_arr, 2)
r_arr(i, j) = i + j
Next j
Next i
End Sub

Sub ArrTesting()

Dim arr() As Double
Dim i As Long
Dim j As Long
Dim k As Long

k = 2
ReDim arr(0 To 1, 0 To k)
Call MyArrTest(arr)
For i = 0 To 1
For j = 0 To k
Debug.Print arr(i, j)
Next j
Next i
End Sub
 
Yes!

Sorry for the stupid question, but I neglected to declare
the array 'as double' in the parameter declaration.

Thanx.

(david)
 
david epsom dot com dot au said:
Yes!

Sorry for the stupid question, but I neglected to declare
the array 'as double' in the parameter declaration.

Thanx.

(david)

Sorry, no disrespect was intended!

Based on the high quality of your replies in general, I was getting the
feeling there was something I'd missed somewhere, some context in which
it wouldn't work etc.
 
Back
Top