Results 1 to 3 of 3

Thread: (RESOLVED) How to create a function that returns an array?

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2002
    Posts
    50

    (RESOLVED) How to create a function that returns an array?

    Apologies if this has been covered before, I am trying to create a function that will return an array - I'm not sure how to declare this.

    If this is the declaration:

    Private Function NameOfFunction(blablabla) As Double

    I want "NameOfFunction" to be, say, a 10*10 array. Any suggestions would be great.

    Another question too, after I'm done with this, can I just assign this to an array, like:
    dim table(9,9) as Double
    table=NameOfFunction

    ... or will I need to assign each element of the array separately?

    Thank you!
    Last edited by tassosp; Oct 26th, 2004 at 03:42 AM.

  2. #2
    Fanatic Member Blade's Avatar
    Join Date
    Jan 1999
    Location
    Stoke-on-Trent, UK
    Posts
    527
    hi, here is a quick example of how to do return an array from a function. Note, you can't explicitly declare the size of the array the function will return.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.  
    5.     Dim arrTest() As Long
    6.    
    7.     arrTest = ReturnArray
    8.    
    9.     MsgBox arrTest(2, 2)
    10.  
    11. End Sub
    12.  
    13. Private Function ReturnArray() As Long()
    14.     Dim arrFNArray(5, 5) As Long
    15.    
    16.     'put in value so we can see
    17.     arrFNArray(2, 2) = 66
    18.    
    19.     ReturnArray = arrFNArray
    20.    
    21. End Function

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2002
    Posts
    50
    Thank you ! - what I needed exactly! Saved me the pain of browsing through msdn!

    Best wishes!

Posting Permissions

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



Click Here to Expand Forum to Full Width