How to return an array from a function

Parent Form Function that passes back an Array / Vector

 Private Sub ReceiveArray_Click()
    Dim intRcvArray() As Integer
    Dim i As Integer

    UserInterface.Text = ""
    intRcvArray = NumberList()                   ‘ —Get the array of strings.
   
    For i = LBound(intRcvArray) To UBound(intRcvArray)     ‘ —Display the strings.
       UserInterface.Text = UserInterface.Text & CStr(i) & " "
    Next i

End Sub

Private Function NumberList() As Integer()          ‘ — This function returns an array 
  Dim intArray() As Integer
  Dim i As Integer

    ReDim intArray(1 To 10)
    For i = 1 To 10
        intArray(i) = i             
    Next i

    NumberList = intArray
End Function

 

Code here: ReturnArray.zip

Categories: CodingVisual-Basic

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *