Results 1 to 40 of 47

Thread: [RESOLVED] Delete item(s) from array

Threaded View

  1. #33

    Thread Starter
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: [RESOLVED] Delete item(s) from array

    Quote Originally Posted by Merri
    Spoo, you can still keep the logic simple, you just need to reconsider the order you do things:
    Code:
    kk = 0
    kill = "B"
    For ii = 0 to UBound(MyArray)
       If MyArray(ii) <> kill Then
            If kk < ii Then
                MyArray(kk) = MyArray(ii)
                MyArray(ii) = Empty
            End If
            kk = kk + 1
        Else
            MyArray(ii) = Empty
        End If
    Next ii
    That's the code I was looking for in the OP. I don't see a need to zero out deleted values, though, since they'll either get overwritten or redimmed into the void.
    Code:
    Private Sub FilterUDT(ptyp() As TESTUDT, pstrFilter As String)
        Dim lngKeep As Long
        Dim lngSwap As Long
        
        For lngSwap = 0 To UBound(ptyp)
            If ptyp(lngSwap).B <> pstrFilter Then
                If lngKeep < lngSwap Then ptyp(lngKeep) = ptyp(lngSwap)
                lngKeep = lngKeep + 1
            End If
        Next
        Select Case lngKeep
            Case 0: Erase ptyp
            Case Is <= UBound(ptyp): ReDim Preserve ptyp(lngKeep - 1)
        End Select
    End Sub
    Last edited by Ellis Dee; Dec 6th, 2008 at 05:07 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width