Here is the rough code. It needs error checking, entity type testing, etc
But I think it gets the idea across (if I interpreted you first post correctly).
Public Sub testGetClosestEndpoint()
Dim oEnt As AcadEntity
Dim vPickedPoint As Variant
Dim vPoint As Variant
Dim vResult As Variant
ThisDrawing.Utility.GetEntity oEnt, vPickedPoint, "Pick (p)Line: "
vResult = GetClosestEndPt(oEnt, vPickedPoint, False)
Debug.Print vResult(0), vResult(1), vResult(2)
End Sub
Public Function GetClosestEndPt(pLineEnt As AcadEntity, pPoint As Variant, p3dIfTrue As Boolean) As Variant
Dim vTemp1 As Variant
Dim oLine As AcadLine
Dim oLwPline As AcadLWPolyline
Dim oPline As AcadPolyline
Dim o3dPline As Acad3DPolyline
Dim maxVert As Integer
Dim dist1 As Double
Dim dist2 As Double
Dim retVal As Variant
If TypeOf pLineEnt Is AcadLine Then
Set oLine = pLineEnt
dist1 = CalcDist(oLine.StartPoint, pPoint, p3dIfTrue)
dist2 = CalcDist(oLine.EndPoint, pPoint, p3dIfTrue)
If dist1 <= dist2 Then
retVal = oLine.StartPoint
Else
retVal = oLine.EndPoint
End If
ElseIf TypeOf pLineEnt Is AcadLWPolyline Then
Set oLwPline = pLineEnt
maxVert = (UBound(oLwPline.Coordinates) - 1) / 2
dist1 = CalcDist(oLwPline.Coordinate(0), pPoint, p3dIfTrue)
dist2 = CalcDist(oLwPline.Coordinate(maxVert), pPoint, p3dIfTrue)
If dist1 <= dist2 Then
retVal = oLwPline.Coordinate(0)
Else
retVal = oLwPline.Coordinate(maxVert)
End If
ElseIf TypeOf pLineEnt Is AcadPolyline Then
Set oPline = pLineEnt
maxVert = (UBound(oPline.Coordinates) - 2) / 3
dist1 = CalcDist(oPline.Coordinate(0), pPoint, p3dIfTrue)
dist2 = CalcDist(oPline.Coordinate(maxVert), pPoint, p3dIfTrue)
If dist1 <= dist2 Then
retVal = oPline.Coordinate(0)
Else
retVal = oPline.Coordinate(maxVert)
End If
ElseIf TypeOf pLineEnt Is Acad3DPolyline Then
Set o3dPline = pLineEnt
maxVert = (UBound(o3dPline.Coordinates) - 2) / 3
dist1 = CalcDist(o3dPline.Coordinate(0), pPoint, p3dIfTrue)
dist2 = CalcDist(o3dPline.Coordinate(maxVert), pPoint, p3dIfTrue)
If dist1 <= dist2 Then
retVal = o3dPline.Coordinate(0)
Else
retVal = o3dPline.Coordinate(maxVert)
End If
End If
GetClosestEndPt = retVal
End Function
Public Function CalcDist(pPt1 As Variant, pPt2 As Variant, p3dIfTrue As Boolean) As Double
Dim temp As Double
If p3dIfTrue Then
temp = Sqr((pPt1(0) - pPt2(0)) ^ 2 + (pPt1(1) - pPt2(1)) ^ 2 + (pPt1(2) - pPt2(2)) ^ 2)
Else
temp = Sqr((pPt1(0) - pPt2(0)) ^ 2 + (pPt1(1) - pPt2(1)) ^ 2)
End If
CalcDist = temp
End Function
The LISP vlax-curve-* functions would probably be helpful to you for determining stationing. They can probably be accessed in VBA using the VL Active X module and/or through Frank O's VLAX class.