+ Reply to Thread
Results 1 to 3 of 3

Function to return Array

Hybrid View

  1. #1
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Welcome to the forum.

    There are various ways to return arrays from function. I would probably do this (and have done similar things) with a user-defined data type. Here's an example:
    Type uPartRecd
        sName   As String           ' part name
        sPN     As String           ' part number
        nComp   As Long             ' number of components
        asComp(1 To 20) As String   ' components by name
    End Type
    
    Sub x()
        Dim auPart() As uPartRecd
        Dim i As Long
        
        ReDim auPart(1 To 100)
        
        auPart(1) = getPart
        
        With auPart(1)
            Debug.Print .sName, .sPN, .nComp
            For i = 1 To .nComp
                Debug.Print i, .asComp(i)
            Next i
        End With
        
    End Sub
    
    Function getPart() As uPartRecd
        With getPart
            .sName = "Axle"
            .sPN = "1234-012"
            .nComp = 3
            .asComp(1) = "case"
            .asComp(2) = "widget"
            .asComp(3) = "thingee"
        End With
    End Function
    I'd spend a lot of time thinking about data structures before launching into this.

  2. #2
    Forum Expert
    Join Date
    12-24-2004
    Location
    Sweden
    Posts
    1,256

    Break down Parts into Components

    Here is one option (see encl. file, sheet 3)
    Ola
    Attached Files Attached Files

+ 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