Learn how to a build a cloud-first strategyRegister Now


Looking for duplicates..

Posted on 2011-05-09
Medium Priority
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
  • 2
  • 2

Author Comment

ID: 35725304
In other words, did you mean that by "collisions"?
LVL 28

Expert Comment

ID: 35725772

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


Author Comment

ID: 35726039
did you test it  with values?
LVL 28

Accepted Solution

Ark earned 2000 total points
ID: 35726370

    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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Integration Management Part 2
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 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