Hello-
I was wondering if a function can return an array. I have tried this, but could not get it to work. Does anyone else know how to do this?
Thanks
Printable View
Hello-
I was wondering if a function can return an array. I have tried this, but could not get it to work. Does anyone else know how to do this?
Thanks
netlias,
One way to do what you want is to pass the function a pointer to the array and have the function modify it.
VB Code:
Private sub Main dim tmpArray() as string PopulateArray(tmpArray) end sub Private sub PopulateArray(byRef myArray() as string) redim myArray(100) myArray(0) = .... end Sub
Hope this helps...
Thanks
Or you can just return an array...
VB Code:
' Function that returns an array: Private Function ReturnArray(nNumElements As Integer) As String() Dim asTest() As String Dim nCounter As Integer ReDim asTest(nNumElements) For nCounter = 0 To nNumElements - 1 asTest(nCounter) = "Element #" & nCounter + 1 Next ReturnArray = asTest End Function ' Usage example: Private Sub TestSub() Dim asMyStrArray() As String asMyStrArray = ReturnArray(5) MsgBox "UBound of asMyStrArray is: " & UBound(asMyStrArray) End Sub
with vb however, you needn't even include a parameter for the size of the array, as vb include ubound and lbound functions....unlike c++, that stupid language....[inaudible anger at c++]
lolQuote:
Originally posted by jmiller
with vb however, you needn't even include a parameter for the size of the array, as vb include ubound and lbound functions....unlike c++, that stupid language....[inaudible anger at c++]
agree agree