PDA

View Full Version : Passing Array Issues



orcas
03-07-2013, 05:51 AM
Hi,

Please could you help?

I have the following program


Sub MyProgram1()

dim RefWeights() as variant

'code goes in here

Sub Myprogram2()

dim RefReturns(), dim LossParam()

LossParam(x) = RefReturns(x)*RefWeights(x)

'code goes in here

end sub




As you can see from the above, RefWeights array was filled in the first sub routine, is there a way i can modify my code so that the contents of the Refweights array are available to use in the second sub routine?


Thanks for your help.

patel
03-07-2013, 06:28 AM
dim RefWeights() as variant ' before all subs
Sub MyProgram1()
'code goes in here
end sub

Sub Myprogram2()
dim RefReturns(), dim LossParam()
LossParam(x) = RefReturns(x)*RefWeights(x)
'code goes in here
end sub

snb
03-07-2013, 06:53 AM
2 illustrations: passing to a function, passing to a sub

Sub tst()
MsgBox sum_snb(Array(3, 5, 7, 9))
sub_snb Array(3, "text", Date, 9)
End Sub

Function sum_snb(sn)
sum_snb = Application.Sum(sn)
End Function

Sub sub_snb(sn)
For Each it In sn
MsgBox it
Next
End Sub

orcas
03-07-2013, 08:33 AM
You guys are simply great!!!

Thanks.