VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Remove item from dynamic type array (MemCopy fast solution)

~:. Jeff 'Capes' .:~  ()   Windows API Call/Explanation   Visual Basic 5.0   Advanced   Wed 3rd February 2021

Erase a specified (mIndex) item in a Dynamic Type Array. When the index is valid it shrinks the Array, so an item will not hold any 'empty' variable/data (1,2,3,4, 0 ,6,7,8 OR "a","b","c","d", "" ,"f","g")
This is the fastest possible way I know.
Please comment anything!

Inputs
Private Sub Command1_Click() ' NOTE: I didn't use ArrayOfType(0) Dim arrayItems As Long arrayItems = 10 ' array size (10 items) ReDim ArrayOfType(arrayItems) As ArrayOfType ' set array For i = 1 To arrayItems ' 10 items - i didn't use item (0) ArrayOfType(i).item_01 = i ArrayOfType(i).item_02 = i ArrayOfType(i).item_03 = i ArrayOfType(i).item_04 = i ' fill array items with data ArrayOfType(i).item_05 = i ArrayOfType(i).item_06 = i ArrayOfType(i).item_07 = i Next i ' remove item #7 in array If RemoveArrayItem(7) = True Then MsgBox "item #7 in array removed..." & vbCrLf & vbCrLf & "look in you debugwindow!", vbInformation, "info" End If ' check your debug-window for the resized array For i = 1 To UBound(ArrayOfType) Debug.Print "ArrayOfType(" & i & ")" Debug.Print vbTab & "|___ item_01 = " & ArrayOfType(i).item_01 Debug.Print vbTab & "|___ item_02 = " & ArrayOfType(i).item_02 Debug.Print vbTab & "|___ item_03 = " & ArrayOfType(i).item_03 Debug.Print vbTab & "|___ item_04 = " & ArrayOfType(i).item_04 Debug.Print vbTab & "|___ item_05 = " & ArrayOfType(i).item_05 Debug.Print vbTab & "|___ item_06 = " & ArrayOfType(i).item_06 Debug.Print vbTab & "|___ item_07 = " & ArrayOfType(i).item_07 Debug.Print Next i Debug.Print "UBound(ArrayOfType) = " & UBound(ArrayOfType) Debug.Print String(50, "-") Debug.Print End Sub

Side Effects
d5mn' fast

Rate Remove item from dynamic type array (MemCopy fast solution) (2(2 Vote))
Remove item from dynamic type array (MemCopy fast solution).bas

Remove item from dynamic type array (MemCopy fast solution) Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters