+ Reply to Thread
Results 1 to 3 of 3

Returning array from a function

Hybrid View

  1. #1
    Registered User
    Join Date
    12-02-2008
    Location
    USA
    Posts
    38

    Returning array from a function

    Hello,

    Using the following code, I am defining a function that will output an array as result. For some reason it is not working and not able figure this out.
    Function values(c As Integer, a As Integer) As Variant()
    Dim cr As Variant
    cr = Array(0, 0, 0, 0, 0, 0)
    cr(0) = c + a
    cr(1) = 4 * a
    cr(5) = 7 + a
    
    
    values = cr
    End Function
    
    Sub get_io()
    Dim val As Variant
    val = values(9, 8)
    
    End Sub
    After executing get_io sub, the varaiable val is empty? It should have the values calculted from the function?

    Thanks,
    Leyo Joseph

  2. #2
    Forum Contributor
    Join Date
    03-21-2012
    Location
    Ho Chi Minh city
    MS-Off Ver
    Excel 2003
    Posts
    180

    Re: Hope this help!

    You look in the file

    {CTRL}+{SHIFT}+{RNTER}
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    12-02-2008
    Location
    USA
    Posts
    38

    Re: Hope this help!

    Hello
    Thanks. I am celar about defining the function "values". But how to call this function? See the following code:
    Sub ght()
    Dim val() As Variant
    val = values(6, 5)
    [a9] = val(0)
    [a10] = val(1)
    [a11] = val(2)
    [a12] = val(3)
    [a13] = val(4)
    [a14] = val(5)
    End Sub
    if this works fine, cell a9 should be 13..but I am getting 20...same issues with other cells...What I am mssing here?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1