Hello.
I can return an array from a function, but have to assign it to a Variant. Is it not possible to
assign the return value (an array) directly to another array of the same dimensions?
Thanks, Andy.
Return array from function
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
Return array from function
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
-
- Lounger
- Posts: 47
- Joined: 26 Jan 2010, 01:05
Re: Return array from function
Certainly; if this is in response to the question you had in the thread I started, simply create your second array (if you've got an array with 10 items, it would look like this)
If that's not what you're trying to do I'm gonna need more explanation.
Code: Select all
For intCount=0 to 9
Range2(intCount)=Range(intCount)
Next intCount
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
Re: Return array from function
Hi. I have a function:
but I can only do so if myArray is declared as a Variant (not an array).
Hope this helps, Andy.
Code: Select all
Function GetArray() As String()
Dim temp(1 To 3) As String
' fill temp()
GetArray = temp() ' to return the array
End Function
' in my Sub, I want to use
myArray() = GetArray()
Hope this helps, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
-
- Lounger
- Posts: 47
- Joined: 26 Jan 2010, 01:05
Re: Return array from function
I don't see myArray being declared at all...
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
Re: Return array from function
Sorry, I omitted this:
Sub UseGetArray()
Dim myArray(1 To 3) As String
myArray() = GetArray() 'causes an error.
Andy.
Sub UseGetArray()
Dim myArray(1 To 3) As String
myArray() = GetArray() 'causes an error.
Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
-
- 5StarLounger
- Posts: 818
- Joined: 24 Jan 2010, 15:56
Re: Return array from function
You need a dynamic array:
Code: Select all
Sub UseGetArray()
Dim myArray() As String
myArray() = GetArray()
End Sub
Regards,
Rory
Rory
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
Re: Return array from function
That's fab. Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.