PDA

Click to See Complete Forum and Search --> : Delete element from array


omarswan
Jan 21st, 2000, 02:46 AM
If I have 10 elements in an array, how can I delete element from slot number 5 and move the element that was in slot number 6 to slot number 5 and then leave slot number 10 empty.


Example:Before
---------------
Slots--Element
--[1]---[Name1]
--[2]---[Name2]
--[3]---[Name3]
--[4]---[Name4]
--[5]---[Name5]
--[6]---[Name6]
--[7]---[Name7]
--[8]---[Name8]
--[9]---[Name9]
-[10]---[Name10]


Example:After - Remove Element 5
----------------------------------
Slots--Element
--[1]---[Name1]
--[2]---[Name2]
--[3]---[Name3]
--[4]---[Name4]
--[5]---[Name5] - previously Element-6
--[6]---[Name6] - previously Element-7
--[7]---[Name7] - previously Element-8
--[8]---[Name8] - previously Element-9
--[9]---[Name9] - previously Element-10
-[10]---[Empty]



------------------
OmarSwan
omarswan@yahoo.com
http://www.omarswan.cjb.net
To God Be The Glory

jpark
Jan 21st, 2000, 03:41 AM
If it's ok try to use collection.


Dim testCol As New Collection
testCol.Add "1"
testCol.Add "2"
testCol.Add "3"
testCol.Add "4"
testCol.Add "5"
testCol.Add "6"
testCol.Add "7"
testCol.Add "8"
testCol.Add "9"
testCol.Add "10"

'Remove element 5
testCol.Remove 5

' After you remove element5, there are 9 elements left in the collection. If you want to keep number of elements, then simply add one with empty string.
This will become the last element(10) of your collection.
testCol.Add ""

MsgBox testCol(5)
MsgBox testCol(10)


Joon