transferring arrays between subroutines

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
 
G

Gary''s Student

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
 
M

mdmackillop

Option Base
Dim TempArray(10, 2

Public Sub Uno(

Call du

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

End Su

Public Sub duo(

For i = 1 To 1
TempArray(i, 1) =
TempArray(i, 2) = 2 *
Next

End Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top