Code archives/Algorithms/Send Multi-Dimensional Arrays to a Function

This code has been declared by its author to be Public Domain code.

Download source code

Send Multi-Dimensional Arrays to a Function by Chroma2005
Does what the title says. :o-)

You can increase the number of dimensions by adding commas to brackets ie. [,,,]. Just remember to make them all match up.

Btw, thanks goes to Perturbatio, Azazoth, YouCanCode, and Tom Darby for helping me work this out. Thanks guys...hugs and kisses. Teehee.
Print

'Make array1 and fill it with values
Local array1:Int[2,2]
For b=0 To 1
	For a=0 To 1
		array1[a,b]=a
		Print "array1 "+a+","+b+" = "+array1[a,b]
	Next
Next
Print

'Make array2
Local array2:Int[,]

'Pass array1 to the function and get array1 back and put it in array2
array2 = ArrayFunc(array1)

'Show the results
Print
For b=0 To 1
	For a = 0 To 1
		Print "Back From ArrayFunc "+a+","+b+" = "+array2[a,b]
	Next
Next

End



Function ArrayFunc[,](this:Int[,])
	For b=0 To this.length/2-1
		For a=0 To this.length/2-1
			Print "Inside ArrayFunc "+a+","+b+" = "+this[a,b]
			this[a,b]:+5
		Next
	Next
	Return this
End Function

Comments

None.

Code Archives Forum