Consulting

Results 1 to 4 of 4

Thread: Passing Array Issues

  1. #1
    VBAX Regular
    Joined
    Aug 2011
    Posts
    17
    Location

    Passing Array Issues

    Hi,

    Please could you help?

    I have the following program

    [VBA]
    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

    [/VBA]


    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.

  2. #2
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    [vba]
    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
    [/vba]

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    2 illustrations: passing to a function, passing to a sub

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

    [VBA]Function sum_snb(sn)
    sum_snb = Application.Sum(sn)
    End Function[/VBA]

    [VBA]Sub sub_snb(sn)
    For Each it In sn
    MsgBox it
    Next
    End Sub[/VBA]

  4. #4
    VBAX Regular
    Joined
    Aug 2011
    Posts
    17
    Location
    You guys are simply great!!!

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •