Updated: Insert an Element Into an Array without Looping

Category:
Lists, Collections and Arrays
Type:
Snippets
Difficulty:
Advanced

Author: Jason Thorn

Version Compatibility: Visual Basic 6, Visual Basic 5

More information:
Use the example below to allow you to insert and remove one or more elements to or from the middle of an array without the need to loop through each element in the array. You can modify the routine to support any structure or variable type by simply changing the declaration. This can improve performance when manipulating large arrays. Thanks to Davide Di Loreto for helping to debug this code.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: