Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetDistance in VBA

Status
Not open for further replies.

RufussMcGee

Technical User
Jan 7, 2005
117
US
Having trouble getting distance between to known points in my VBA program. This is the line I wrote but it does not seem to like it.

Dim Pt3(2) as double
Dim Pt5(2) as double
Dim LenD as double

Pt3(0) = 0#: Pt3(1) = 0#: Pt3(2) = 0#
Pt5(0) = 2#: Pt5(1) = 4#: Pt5(2) = 0#

LenD = ThisDrawing.Utility.GetDistance(Pt3, Pt5)
MsgBox (LenD)

The whole code is more then just that but you get the general idea. Does anyone might have the solution?

Thanks.
May the Code be with you.
 
Hi Rufuss,

The "GetDistance" function is for user input, not calculating distances, try this courtesy of Mr. Oquendo:

Code:
Function Distance(Point1, Point2) As Double

    Dim dist As Double

    On Error Resume Next
    For i = LBound(Point1) To UBound(Point1)
        dist = dist + ((Point1(i) - Point2(i)) ^ 2)
        If Err Then Exit For
    Next

    Distance = Sqr(dist)

End Function

Where Point1 and Point2 are arrays of doubles.

HTH
Todd
 
MsgBox (LenD) is a function that gives a result, ranging from vbYes to VbCancel etc. Don't use the parantheses in this case.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top