measure the distance between two points on a form in centimeter

Mohammad Alsolaiman
Mohammad Alsolaiman used Ask the Experts™
on
Hi
Can I measure the distance between two points on a form in centimeter ?
I  need when I click on a form the first click (I keep the first position value), then the second click(I keep the second position value) then get the distance between these two points in centimeter .
Is it possible to do so with ms access?
Please help
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

Commented:
The distance between points should be in twips. To convert, there are 567 twips in a centimeter
Top Expert 2011

Commented:
To handle either direction try:

ABS([StartPoint] - [EndPoint]) / 567 =  centimeter
Mohammad Alsolaimanapplication programmer

Author

Commented:
ABS([StartPoint] - [EndPoint]) / 567 =  centimeter
is this will fit to any direction on a form?
as you know the first click maybe at top left of form
and second click maybe at bottom right of form.
does this equation will work to any direction as long as i  have to points?
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

Top Expert 2016
Commented:
Top Expert 2011

Commented:
M_SOLAIMAN,

My example assumed you were doing a start line either vertical or horizontal.  If it is a slanted line then you will need to  to look at it as a right triangle triangle.  You can calculate the sides for vertical and horizontal. Now you can calculate the third side. Remember the Right Triangle (90°  corner) stuff from geometry class about The Pythagorean theorem?

a = horizontal distance
b= vertical distance
c (the distance you want) = square root of (a² + b ²)



hi

pls try this method ..

1, get two points from cursor position in form.
2, and then apply the centimete calculation

by
kumaresan. v

Declare Function xFind_centimeter_twopoints Lib "user32" _
      (lpPoint As POINTAPI) As Long
      ' Access the GetCursorPos function in user32.dll
      Declare Function SetCursorPos Lib "user32" _
      (ByVal x As Long, ByVal y As Long) As Long

      ' GetCursorPos requires a variable declared as a custom data type
      ' that will hold two integers, one for x value and one for y value
      Type POINTAPI
         X_Pos As Long
         Y_Pos As Long
      End Type

      ' Main routine to dimension variables, retrieve cursor position,
      ' and display coordinates
      Sub Get_Cursor_Pos()

      ' Dimension the variable that will hold the x and y cursor positions
      Dim Hold As POINTAPI

      ' Place the cursor positions in variable Hold
      GetCursorPos Hold

      ' Display the cursor position coordinates
      MsgBox "X Position is : " & Hold.X_Pos & Chr(10) & _
         "Y Position is : " & Hold.Y_Pos
      End Sub

      ' Routine to set cursor position
      Sub Set_Cursor_Pos()

      ' Looping routine that positions the cursor
         For x = 1 To 480 Step 20
            SetCursorPos x, x
            For y = 1 To 40000: Next
         Next x
      End Sub

Open in new window

hi

please try this method also...

by
kumaresan
Function Convert_Decimal() As Double
   ' Declare the variables to be longint.
   Dim xStart_Points As longint
   Dim xEnd_Points As longint
   Dim xCentimeter As double

   dim X_Pos As Long
   dim Y_Pos As Long

   'Read start position on first click event
    xStart_Points  :=  self.X_Pos; 

   'Read start position on first click event
    xEnd_Points :=  self.Y_Pos ; 

    'calculate centimeter..
    xCentimeter  := xEnd_Points - xStart_Points;
    xCentimeter  := abs(xCentimeter/567)

    ' Display the centimeter value
    MsgBox "centimeter between two points is : " & xCentimeter & 
    End Sub

End Function

Open in new window

Mohammad Alsolaimanapplication programmer

Author

Commented:
OK Now i get the  Start point (X,Y) = 6750,2565. and the  End point (X,Y) = 7350,5550.
please, how to measure the distance in between "centimeters"?
Top Expert 2016

Commented:
the values shown are in twips 1 cm = 567 twips

Start point (X,Y) = 6750,2565  'these values are in twips

Start point (X/567,Y/567) = values in cm

Mohammad Alsolaimanapplication programmer

Author

Commented:
OK
but how to calculate the distance between these two Cartesian axis
Top Expert 2011

Commented:
Where:

 Start point (X1,Y1) = 6750,2565.

 and

 End point (X2,Y2) = 7350,5550.

In VBA use:

Sqr( ABS(X1- X2) * ABS(X1-X2)) + ( ABS(Y1-Y2) * ABS(Y1-Y2) ) / 567

Open in new window


 Sqr((ABS((X1 - X2)/567) * ABS((X1 - X2)/567) ) + (ABS((Y1-Y2)/567) * ABS((Y1-Y2)/567)))

Open in new window



which would be:

? Sqr((ABS((6750 - 7350)/567) * ABS((6750 - 7350)/567) ) + (ABS((2565-5550)/567) * ABS((2565-5550)/567)))
 5.36984906375906 

Open in new window




Top Expert 2011
Commented:
Oop forgot to delete the first line of VBA code.

It should be:

Where:

 Start point (X1,Y1) = 6750,2565.

 and

 End point (X2,Y2) = 7350,5550.

In VBA use:

 Sqr((ABS((X1 - X2)/567) * ABS((X1 - X2)/567) ) + (ABS((Y1-Y2)/567) * ABS((Y1-Y2)/567)))

Open in new window



which would be:

? Sqr((ABS((6750 - 7350)/567) * ABS((6750 - 7350)/567) ) + (ABS((2565-5550)/567) * ABS((2565-5550)/567)))
 5.36984906375906 

Open in new window

Mohammad Alsolaimanapplication programmer

Author

Commented:
wonderful

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial