News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

removing an array cell completely?

Started by Alex, March 27, 2007, 04:19:53 PM

Previous topic - Next topic

Alex

hi,
is it possible to remove an array cell completely(not just setting it to zero)?
How would I go abouts doing this for a type array
I tried copying the entire array to another, and then only copying the values i wanted back into the original, and then redimming it, but this didn't work.

kevin

#1
 You can copy cells within an array, but you have to careful how the ranges overlap.. Bellow we have two methods, the first copies the following cells down over the removed cell, then resizes the array, the second just copies the last item down over the removed cell and resizes.  The second method doesn't keep the order in the tact though.

PlayBASIC Code: [Select]
 max=10
Dim Table(10)

For lp=0 to max
Table(lp)=1000+lp
next

ShowArray(Table())

RemoveCell(Table(),5)

ShowArray(Table())

RemoveCell2(Table(),9)

ShowArray(Table())

Sync
waitkey


Function ShowArray(Me())
Print "Array"
For lp=0 to Getarrayelements(me(),1)
t$=t$+Str$(Me(lp))+","
next
print TrimRight$(T$,",")

EndFunction


Function RemoveCell(Me(),Index)
Size=getarrayelements(me(),1)
; Some safe code to to Clip Illegal values
if Index<0 Then Index=0
If Index<(Size+1)
// Copy Cell Down Method
CopyArrayCells Me(),Index+1,1,Me(),Index,1,Size
Redim Me(Size-1)
Endif
EndFunction



Function RemoveCell2(Me(),Index)
Size=getarrayelements(me(),1)
; Some safe code to to Clip Illegal values
if Index<0 Then Index=0
If Index<(Size+1)
// Copy Last Cell to Remove point then resize
CopyArrayCells Me(),Size,1,Me(),Index,1,1
Redim Me(Size-1)
Endif
EndFunction





Related To:

      * Pack Array






Alex