Whats the use of having a method than can return an array if you cannot assign directly like this (pseudocode x()=methodarray) but you are forced to copy each single item using a loop ?
what am I missing ?
I don’t quite understand… I’ve just made a sample project. In it is a single PushButton with this code:
dim x() as string
x = MethodArray
break
and the method MethodArray, which takes no parameters and returns String():
dim y() as string
y.Append "1"
y.Append "2"
return y
When my PushButton code breaks, then x is a string array with two items.
No copying with loops…?
[quote=153581:@Horacio Vilches]Whats the use of having a method than can return an array if you cannot assign directly like this (pseudocode x()=methodarray) but you are forced to copy each single item using a loop ?
what am I missing ?[/quote]
Returning an array is a way to return multiple values from a method without using ByRef. And that is rather convenient.
And Hamish just showed that copying an array is not an issue.
When I tried to return an Array from a Method, I searched a long time how to do.
We have to write : Return Type: String()
or Return Type: Boolean()
or etc. in order to return an array.
It seems evident but it’s not. As when we declare we write Dim MyVar() as String
or Dim MyVar(-1) as String
but not Dim MyVar as String()
.
And it doesn’t work if we write Return Type: String(-1)