transferring arrays between subroutines

  • Thread starter Thread starter c1802362
  • Start date Start date
C

c1802362

I have two subroutines in a VBA module, "uno" and "duo". Uno calls sub
duo which put the results of calculations into an array. I want to
pass the array intact back to the main sub uno. Every attempt I've
tried results in an empty array. I don't believe I can use a function
call for sub duo as functions won't return arrays.

I'm also dimensioning the array in both subs even with the public
call.

Any suggestions? A notional code snippet is below:


Option Base 1
*********************
Public Sub Uno()

Dim TempArray(100,2), i as Integer

….code…..

Call duo

For i = 1 To 100
Cells(i, 1) = TempArray(i, 1)
Cells(i, 2) = TempArray(i, 2)
Next i

….More code ….

***********************************
Public Sub duo()

Dim TempArray(100,2), i as Integer

For i = 1 To 100
TempArray(i, 1) = function1
TempArray(i, 2) = function2
Next i

End Sub

Art
 
Dim TempArray only once and Dim it above the subs. That way it will be
global and accessable by both subs:

Dim TempArray(100,2) i as Integer
Sub Uno()
..
..
..
End Sub

Sub Duo()
..
..
..
End Sub
 
Back
Top