Thanks:  0
Likes:  0
Dislikes:  0

# Thread: how to pop out element from an array and delete

1. ## how to pop out element from an array and delete

Lets say we have 3 items in array arrExmple
Need to find a logic to pop out first element from the array i.e arrExmple(0) and then show it in msgbox and then delete that element from the array.
Next if we display the array elements, the first element should not be shown. pls help

Below is the code that i am trying
popElement=0
popElement=popElement+1
If (popElement&lt;=arrCount) Then
var= arrQueue(popElement-1)
msgbox var

2. ## Re: how to pop out element from an array and delete

Try this:

a=array("s1","s2","s3","s4")
If Ubound(a)&gt;0 Then
msgbox a(0)
a(0)=""
End If
msgbox a(0)

3. ## Re: how to pop out element from an array and delete

Hi Nandhini you understood wrongly. He wants to delete the element but you fixed as zero length string. Read again carefully.

4. ## Re: how to pop out element from an array and delete

there are many ways of doing the same, simply you can copy 1 Array to another skipping the undesired value or index, but the another way is this.

<font class="small">Code:</font><hr /><pre>
aArray = Array("cat","bat","mat")
ArrayRemoveItem(aArray, 0) 'remove the first 1

Sub ArrayRemoveItem(ByRef aArray, ByVal aIndex)
Dim i,ub
ub = UBound(aArray) - 1
For i = aIndex To ub
aArray(i) = aArray(i + 1)
Next
ReDim Preserve aArray(ub)
End Sub
</pre><hr />

5. ## Re: how to pop out element from an array and delete

thanks Nandini and Price. I got the solution.
Pls find below

set index=0 initially

For i = index To UBound(array) - 1
arrQueue(i) = arrQueue(i + 1)
Next

6. ## Re: how to pop out element from an array and delete

thanks Manish

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.