469,898 Members | 1,574 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Determining where date overlapping is occuring

I am creating a custom control that contains a list view with dates and times. I need to make sure that times do not overlap. I would like the control to determine if the overlap is occuring with the starting time or with the ending time and offer the user an adjusted time entry. Below is the code I'm using currently to check the date and time. How would I modify it to detect where the overlap is occuring.

Public Sub Add(ByVal StartTime As DateTime, ByVal EndTime As DateTime)
If Me.CheckTimes(StartTime, EndTime) = -1 Then
MsgBox("The starting time cannot occur before the ending time!")
Exit Sub
ElseIf Me.CheckTimes(StartTime, EndTime) = 0 Then
StartTime = Me.LatestTime(StartTime, EndTime)
If MsgBox("You are attempting to insert an overlapping time." & vbCrLf & " The starting time has been adjusted to " & StartTime & vbCrLf & "Continue inserting this time?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
Me.Add(StartTime, EndTime)
End If
Exit Sub
End If
Dim myItem As New ListViewItem
myItem.Text = StartTime
myItem.SubItems.Add(FormatNumber(DateDiff(DateInte rval.Minute, StartTime, EndTime) / 60, 2))
TotalHours.Text = FormatNumber(Me.CalculateHours) & " hrs."
End Sub

Private Function CheckTimes(ByVal StartTime as datetime, ByVal EndTime as datetime) As Integer
If StartTime > EndTime Then
Return -1
End If
For Each item As ListViewItem In Me.Times.Items
Dim testEnd As DateTime = item.SubItems(1).Text
Dim testStart As DateTime = item.Text
If StartTime < testEnd And EndTime > testStart Then
Return 0
End If
Return 1
End Function
Thanks for any input!
Jul 21 '05 #1
0 1318

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John Baker | last post: by
6 posts views Thread by HateSpam | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.