Here is what I think should work for all cases, I have made a couple of changes for the sake of efficiency, I have removed the no intersection references, if you don't hit an intersection point, then you don't have one, and I have added the code to handle the horizontal and vertical line cases.
'===========================================================
Private Sub FindIntersections()
Dim FrameRight As Long
Dim FrameBottom As Long
Dim LineLeft As Long
Dim LineTop As Long
Dim LineRight As Long
Dim LineBottom As Long
Dim CaseType As Integer
Dim Slope As Double
Dim OverLapStart As Long
Dim OverLapEnd As Long
Dim XInter As Long
Dim YInter As Long
FrameRight = Frame.Left + Frame.Width - 1
FrameBottom = Frame.Top + Frame.Height - 1
CaseType = 3 ' Assume Diagonal Line
If (Line.X1 < Line.X2) Then
LineLeft = Line.X1
LineRight = Line.X2
Else
LineLeft = Line.X2
LineRight = Line.Y1
If (Line.X1 = Line.X2) Then
CaseType = 2 ' Line is Vertical
End If
End If
If (Line.Y1 < Line.Y2) Then
LineBottom = Line.Y1
LineTop = Line.Y2
Else
LineBottom = Line.Y2
LineTop = Line.Y1
If (Line.Y1 = Line.Y2) Then
CaseType = 1 ' Line is Horizontal
End If
End If
Select Case CaseType
Case 1 ' Horizontal Line
If ((Frame.Left >= LineLeft) And (Frame.Left <= LineRight)) Then
' <We Intersect Left at Coordinate (Frame.Left, Line.Y1) >
End If
If ((FrameRight >= LineLeft) And (FrameRight <= LineRight)) Then
' <We Intersect Right at Coordinate (FrameRight, Line.Y1) >
End If
If ((Frame.Left <= LineRight) And (FrameRight >= LineLeft)) Then
If (Line.Y1 = Frame.Top) Then
OverLapStart = Max(Frame.Left, LineLeft)
OverLapEnd = Min(FrameRight, LineRight)
' <We Overlap Top from OverLapStart to OverLapEnd
Else
If (Line.Y1 = FrameBottom) Then
OverLapStart = Max(Frame.Left, LineLeft)
OverLapEnd = Min(FrameRight, LineRight)
' <We Overlap Bottom from OverLapStart to OverLapEnd
End If
End If
End If
Case 2 ' Vertical Line
If ((Frame.Top >= LineBottom) And (Frame.Top <= LineTop)) Then
' <We Intersect Top at Coordinate (Line.X2, Frame.Top) >
End If
If ((FrameBottom >= LineBottom) And (FrameBottom <= LineTop)) Then
' <We Intersect Bottom at Coordinate (Line.X2, FrameBottom) >
End If
If ((FrameBottom <= LineTop) And (Frame.Top >= LineBottom)) Then
If (Line.X1 = Frame.Left) Then
OverLapStart = Max(FrameBottom, LineBottom)
OverLapEnd = Min(Frame.Top, LineRight)
' <We Overlap Left from OverLapStart to OverLapEnd
Else
If (Line.X1 = FrameRight) Then
OverLapStart = Max(FrameBottom, LineBottom)
OverLapEnd = Min(Frame.Top, LineRight)
' <We Overlap Right from OverLapStart to OverLapEnd
End If
End If
End If
Case 3 ' Diagonal Line
Slope = (Line.Y2 - Line.Y1) / (Line.X2 - Line.X1)
' Check for Top Border Intersection
If ((Frame.Top >= LineBottom) And (Frame.Top <= LineTop)) Then
XInter = ((Frame.Top - Line.Y1) / Slope) + Line.X1
If ((XInter >= Frame.Left) And (XInter <= FrameRight)) Then
' <We Intersect Top at coordinate (XInter, Frame.Top) >
End If
End If
' Check for Bottom Border Intersection
If ((FrameBottom >= LineBottom) And (FrameBottom <= LineTop)) Then
XInter = ((FrameBottom - Line.Y1) / Slope) + Line.X1
If ((XInter >= Frame.Left) And (XInter <= FrameRight)) Then
' <We Intersect Bottom at coordinate (XInter, FrameBottom) >
End If
End If
' Check for Left Border Intersection
If ((Frame.Left >= LineLeft) And (Frame.Left <= LineRight)) Then
YInter = (Slope * (Frame.Left - Line.X1)) + Line.Y1
If ((YInter >= FrameBottom) And (YInter <= Frame.Top)) Then
' <We Intersect Left at Coordinate (Frame.Left, YInter) >
End If
End If
' Check for Right Border Intersection
If ((FrameRight >= LineLeft) And (FrameRight <= LineRight)) Then
YInter = (Slope * (FrameRight - Line.X1)) + Line.Y1
If ((YInter >= FrameBottom) And (YInter <= Frame.Top)) Then
' <We Intersect Right at Coordinate (FrameRight, YInter) >
End If
End If
End Select
End Sub
'===========================================================
Private Function Max(Value1 As Long, value2 As Long) As Long
Max = IIf(Value1 > value2, Value1, value2)
End Function
Private Function Min(Value1 As Long, value2 As Long) As Long
Min = IIf(Value1 < value2, Value1, value2)
End Function
-----
I probably will not be back on-line until Monday, so I wish you well. I will check the board on Monday
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein