Re: newbie: array passing problem



"tom" <tadamsmar@xxxxxxxxx> wrote in message news:1184350761.343721.274120@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Can I pass a one dimension of an array as an array?
For instance:
DIM A(5,3) as Single
CALL FUBAR(A(1,2))
SUBROUTINE FUBAR(X() as Single)
Can X be treated as on dimensional array with 5 elements?

I'm not quite sure what you mean there, but if you want to perform some task on specific "column" (or "row" depending on how you look at things) of a two dimensional array then you can do so in the following manner. You can see immediately that it does not require any shifting about of actual array memory (because the array is passed by reference) by the fact that even though the entire array contains 25 million elements the 5000 elements in the specified "column" are deal with almost immediately you press the button. Unless of course I've misunderstood your question.

Mike

Option Explicit
Private a(1 To 5000, 1 To 5000) As Single

Private Sub DoSomething(ByRef b() As Single, z As Long)
Dim n As Long, p As Single
For n = LBound(b, 1) To UBound(b, 1)
b(n, z) = p
p = p + 0.001
Next n
End Sub

Private Sub Command1_Click()
' do something with the 999th "column"
' (or "row", depending how you look at things)
Call DoSomething(a, 999)
' print the first 20 elements as a check
Dim n As Long
For n = 1 To 20
Print Format(a(n, 999), "0.000")
Next n
End Sub




.