deleting an element from an array - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

deleting an element from an array

djgaloredjgalore Posts: 56Member
hi there, i m having problems deleting an element from an array. my function is as follows: the problem is that my array deletes the number i wanna delete bt copies the last value in the array twice ie. if i want to delete 54 from my array : 33 54 71 i get 33 71 71. can anyone please help.

private function delete(ByVal array as Integer(),byVal num as Integer) as Integer()

for count=0 to UBound(array)
redim preserve array(length-1) 'length a global variable
for(j=index to UBound(array))
return array
end if


  • rlcrlc Posts: 448Member
    something like this....

    Public Sub DeleteElement(ByRef r_Arr as integer(), ByVal v_Element as integer)

    Dim l_Start As Integer = Array.IndexOf(r_Arr, v_Element)

    For l_Loop As Integer = l_Start To r_Arr.Length - 2
    r_Arr(l_Loop) = r_Arr(l_Loop) + 1

    ReDim Preserve r_Arr(r_Arr.Length - 2)

    End Sub[/code]

Sign In or Register to comment.