Looking for duplicates..

Posted on 2011-05-09
Last Modified: 2012-05-11
Idle_Mind, you are right but I am not sure how to implement it.

I will create new question, can u help in the next one?  I understand i can find duplicates keys but what If I have:


both are not duplicate but it should still fail because from 0000 to 0003 there is 0001 and 0002 and 0003 inside it already in the first line (between 0001 and 0004)

do you have time for a little code?
Question by:PhilippeRenaud
    LVL 1

    Author Comment

    In other words, did you mean that by "collisions"?
    LVL 27

    Expert Comment


    Public Class Numbers
        Private m_List As New List(Of Point)
        Private minVal As Integer = 0
        Private maxVal As Integer = 990
        Public Function AddPair(ByVal pFrom As Integer, ByVal pTo As Integer) As Boolean
            If pFrom >= pTo Then
                MsgBox("pFrom >= pTo")
                Return False
            End If
            If Not IsBetween(pFrom, minVal, maxVal) Then
                MsgBox("pFrom not in limits")
                Return False
            End If
            If Not IsBetween(pTo, minVal, maxVal) Then
                MsgBox("pTo not in limits")
                Return False
            End If
            For i As Integer = 0 To m_List.Count - 1
                Dim p As Point = m_List(i)
                If IsBetween(pFrom, p.X, p.Y) Then
                    MsgBox(String.Format("pFrom {0} already exists in row {1} from {2} to {3}", pFrom, i, p.X, p.Y))
                    Return False
                ElseIf IsBetween(pTo, p.X, p.Y) Then
                    MsgBox(String.Format("pTo {0} already exists in row {1} from {2} to {3}", pTo, i, p.X, p.Y))
                    Return False
                End If
            m_List.Add(New Point(pFrom, pTo))
            Return True
        End Function
        Public ReadOnly Property List() As List(Of Point)
                Return m_List
            End Get
        End Property
        Private Function IsBetween(ByVal value As Integer, ByVal min As Integer, ByVal max As Integer) As Boolean
            Return (value >= min AndAlso value <= max)
        End Function
    End Class

    Open in new window

    LVL 1

    Author Comment

    did you test it  with values?
    LVL 27

    Accepted Solution


        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim num As New Numbers
            num.AddPair(1000, 2000)
            num.AddPair(1, 4)
            num.AddPair(10, 50)
            num.AddPair(1000, 2000)
            num.AddPair(0, 3)
            num.AddPair(20, 60)
        End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now