Passing Arrays into functions by Reference/Handle

Started by kevin, February 17, 2008, 09:16:39 AM

Previous topic - Next topic

kevin

 This tiny example shows how to pass integer arrays (in this case) into functions.


PlayBASIC Code: [Select]
 Dim Table(10)
Dim Stuff(20)

; fill table with random values
FillArray(Table())

; fill stuff array with random values
FillArray(Stuff())

; display the table array
ShowArray(Table())

; display the stuff array
ShowArray(Stuff())

Sync
waitkey


Function FillArray(me())
For lp=0 to getArrayElements(Me(),1)
me(lp)=rnd(1000)
next
EndFunction


Function ShowArray(me())
For lp=0 to getArrayElements(Me(),1)
s$=s$+str$(me(lp))+","
next
print trimright$(s$,",")
EndFunction






  Related Articles

   * Managing Arrays - 2D Grids
   * Using 1D arrays as a 2D array
   * Ideas for Managing A Character Inventory (Typed Arrays)
   * Dynamic Array Allocation
   * Dynamically Creating Objects From Data Statements
   * Quick Sort Typed Arrays
   * Swapping Typed Cells In Arrays