|
-
Dec 16th, 2000, 07:07 PM
#1
Thread Starter
Frenzied Member
Hi,
Is it possible to have a function return an array as it's return value?
Well actually, I guess it is possible to return an array because it seem to be returning the array, but I can't figure out how to use it in the calling sub.
When it the function returns the array, and I try to assign that array to another array, it won't let me.. So I guess the real question is, how do you use an array returned from a function?
Any help or examples would be appreciated..
dan
-
Dec 16th, 2000, 08:18 PM
#2
Frenzied Member
CODE
If I could see the code, I could be of more help.
-
Dec 16th, 2000, 08:23 PM
#3
Thread Starter
Frenzied Member
Nevermind... I found the answer.. Both arrays have to be dynamic..
Thanks,
Dan
-
Dec 16th, 2000, 09:11 PM
#4
Addicted Member
Perhaps here is THE code:
Code:
'
'--------------------------------------------------
' Demonstration of a Sub returning an array
' Simulating the Split function in VB 6
' Create a new project with a large textbox
' Set the MultiLine property of the textbox to True
' strMyArray() is the returned array
'--------------------------------------------------
Option Explicit
Private Sub Form_Load()
Dim strMyString As String
Dim i As Long
Dim strMyArray() As String
strMyString = "This is a trial." & vbCrLf & "It is a good trial." & vbCrLf & "I like it very much" _
& vbCrLf & "Do you like it?" & vbCrLf & "Yes, I do." & vbCrLf & "We all do, too."
RetArray strMyString, vbCrLf, strMyArray()
For i = 0 To UBound(strMyArray)
Text1.Text = Text1.Text & strMyArray(i) & vbCrLf
Next
End Sub
Private Sub RetArray(ByVal InString As String, ByVal Separator As String, RetArr() As String)
'
'--------------------------------------------------
' Sub returning an array
'--------------------------------------------------
Dim i As Long
Dim j As Long
Dim k As Long
i = 0
j = 1
Do While j < Len(InString)
k = j
Do While j < Len(InString)
If Mid$(InString, j, Len(Separator)) = Separator Then
ReDim Preserve RetArr(i)
RetArr(i) = Mid$(InString, k, j - k)
j = j + 1
Exit Do
End If
j = j + 1
Loop
i = i + 1
Loop
End Sub
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
|