Login    
 
 
 
 
Text/HTML
  
You are here :: Blogs Saturday, May 19, 2012

Search
Note: This uses the internal blog search engine. The Google search engine is also available at the top of the page.
  
Disclaimer

Please review the site disclaimer before downloading or using content found on this site

  
Categories
  
DEVSHED Blog
As always, I welcome your comments!
Sep 13

Written by: Steve Gray
9/13/2010 4:59 PM  RssIcon

All the examples that I find show how to delete from a List (of String), but my objects are rarely that simple. Here’s how to delete from a more complicated structure.

In this project, we’re dealing with SQL Server databases, so we start with a class that defines one database.

Public Class Target
    Public ServerInstance As String
    Public Database As String

    Sub New(ByVal strServerInstance As String, ByVal strDatabase As String)
        ServerInstance = strServerInstance
        Database = strDatabase
    End Sub
End Class

Then we have a class that contains a List (of Target). This class also has the ‘deleteTarget’ method. Populate a ‘target’ object and pass it to ‘deleteTarget’. We’ll look for something that matches this.

 

We need a public ‘findTarget’ for the ‘myFind’ routine to look at.

FindIndex returns the index of any matching list entry, and RemoveAt removes the item from the List

 

Public Class Profiles
    Public CurrentProfile
    Public ScriptsFolder
    Public Targets As New List(Of Target)
    Public findTarget As Target

    Sub deleteTarget(ByVal t As Target)
        findTarget = t

        Dim i As Int16 = Me.Targets.FindIndex(AddressOf myfind)
        Me.Targets.RemoveAt(i)
    End Sub

    Function myfind(ByVal t As Target) As Boolean
        If t.Database = findTarget.Database And t.ServerInstance = findTarget.ServerInstance Then
            Return True
        Else
            Return False
        End If
    End Function
End Class

Tags:
Categories:
As always, I welcome your comments!
  
 
 
Home | Products | Blogs | Contact Us | Links | God's Plan
Privacy Statement | Terms Of Use
 
Copyright 2011 by Devshed.us