|
-
Jan 11th, 2003, 05:55 PM
#1
Thread Starter
New Member
Can a function return an Array? *Resolved*
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
Last edited by netlias; Jan 11th, 2003 at 06:47 PM.
-
Jan 11th, 2003, 06:17 PM
#2
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...
-
Jan 11th, 2003, 06:46 PM
#3
Thread Starter
New Member
-
Jan 11th, 2003, 08:46 PM
#4
Frenzied Member
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
-
Jan 12th, 2003, 12:55 AM
#5
Addicted Member
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++]
-
Jan 12th, 2003, 01:15 AM
#6
Registered User
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++]
lol
agree agree
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|