can I return some function with array variable
sample coding:
declare function getData() as <???>
...
...
function getData() as <???>
dim I as integer
dim datas(5) as integer
for I = 1 to ubound(datas)
datas(I)=I
next
return datas
end function
how i can fill type of data for this function?
correct me if this function is false
return a function with array
Code: Select all
Sub SomeFunc( Byref Array() As SomeType )
For I As Integer = lBound( Array ) To uBound( Array )
Array( I ) = SomeValue
Next
End Sub
Dim As SomeType foo( 0 To 9 )
Dim As SomeType bar( -100 To 99 )
SomeFunc( foo )
SomeFunc( bar )
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
You can't directly return arrays with functions. You have to pass the array as a parameter, then let the sub modify it that way.
I'll post another example, because 1000101's has a couple of syntax errors:
I'll post another example, because 1000101's has a couple of syntax errors:
Code: Select all
sub getData( datas() as integer )
redim datas(5) as integer
for I as integer = lbound(datas) to ubound(datas)
datas(I) = I
next
end sub
dim datas() as integer
getData( datas() )
for I as integer = lbound(datas) to ubound(datas)
print datas(I)
next
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Those aren't syntax errors. The problems I was referring to are:1000101 wrote:Mine doesn't have any syntax errors if you replace the obvious keywords to be replaced with appropriate values for your application.
- You can't use the ByRef (or ByVal) keyword when declaring an array parameter.
- When passing an array as a parameter, you have to put a pair of brackets "()" after it.
-
- Posts: 775
- Joined: Jul 01, 2005 18:45
I added this to the sourceforge tracker a little while ago ( http://sourceforge.net/tracker/index.ph ... tid=693199 ) but as there is an easy workaround already, it's not top priority.