Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Nov 13, 1998



Application Security Testing: An Integral Part of DevOps

Deleting an Array Element

Conventional wisdom suggests that to delete an array element, you must move up all the subsequent elements to close the "gap" left by the deleted item. However, if the sequence of the elements isn't significant (as in an unsorted array), this algorithm quickly deletes an item:
' Element to delete
iDelete = 5
' Number of elements before deletion
nElements = UBound(Array)
' Replace iDelete with last item in array
Array(iDelete) = Array(nElements)
' Use ReDim Preserve to shrink array by one
ReDim Preserve Array(LBound(Array) _ 
	To nElements - 1)
Basil Hubbard
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date