Page 1 of 1

Returning an array from a procedure

Posted: Fri Jun 20, 2008 2:58 pm
by jcoggins
Is there a way to have a procedure return an entire array?

Jason

Posted: Fri Jun 20, 2008 3:55 pm
by Trond
No, you must pass the array as a parameter, and then let the procedure fill it in.

Posted: Fri Jun 20, 2008 4:52 pm
by jcoggins
Can anyone provide a simple example?

Jason

Posted: Fri Jun 20, 2008 5:04 pm
by pdwyer

Code: Select all

Procedure MyProc(MyArray.l(1)) ;1 in brackets is the number of dimensions
    MyArray(5) = 100
    MyArray(10) = 1000
EndProcedure

Dim AnArray.l(20)
AnArray(5) = 10

Debug AnArray(5)
Debug AnArray(10)

MyProc(AnArray())

Debug AnArray(5)
Debug AnArray(10)

Posted: Fri Jun 20, 2008 5:06 pm
by byo
EDIT: Removed because of nonsense. :lol:

Posted: Fri Jun 20, 2008 5:10 pm
by pdwyer
still preoccupied with returning a structure? :twisted:

Edit, I can't keep up with your edits Byo!! :shock:

Posted: Fri Jun 20, 2008 6:55 pm
by netmaestro
You can create an array in a procedure and return its address via ProcedureReturn @MyArray() with one proviso - the array must be created with a persistent scope, e.g. Global or Static else it's gone after the procedure finishes.