Remove a Record from an Array
No attachments for this post
Remove any record from an array, without leaving a gap in the records.
Private Type my_type
field1 As String
field2 As Long
field3 As Integer
Const MAX_ARRAY = 10
Dim my_array(0 To MAX_ARRAY - 1) As my_type
'Delete the record RecPos (from 0 to MaxRecs)...MaxRecs is the maximum array dimension
Public Sub DeleteRecordFromMyArray(RecPos As Integer, MaxRecs As Integer)
Dim i As Integer
'Move all the record forward by one position
For i = RecPos To MaxRecs - 1
my_array(i) = my_array(i + 1)
'Reset the last array record
my_array(MaxRecs).field1 = ""
my_array(MaxRecs).field2 = 0
my_array(MaxRecs).field3 = 0
Private Sub Command1_Click()
DeleteRecordFromMyArray 3, MAX_ARRAY - 1
This code originally appeared on AndreaVB.com, and has been republished here with the permission of Andrea Tincani.
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.