View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default Coordinates extraction and comparison

popovsky,
Don't know if it's worth it, but you could use the Intersect API.
You get the intersecting area as a result, if that would be useful to you.

If you get the initial worksheet in a more friendly format, it would help
also.

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function IntersectRect Lib "user32" (lpDestRect As RECT, _
lpSrc1Rect As RECT, _
lpSrc2Rect As RECT) _
As Long

Dim rectTest(100) As RECT
Dim rectResult As RECT
Dim i As Long
Dim j As Long
Dim Overlaps As Long

'Create our rects
For i = 0 To 99
With rectTest(i)
.Left = (20 * Rnd) + 2
.Top = (10 * Rnd) + 2
.Right = (30 * Rnd) + 2
.Bottom = (40 * Rnd) + 2
End With
Next

'Compare each to all the others
For i = 0 To 99
For j = 0 To 99
'No need to compare to itself
If i < j Then
If IntersectRect(rectResult, rectTest(i), rectTest(j)) < False
Then
MsgBox "Rect " & i & " & rect " & j & " overlap."
End If
End If
Next
Next

NickHK

"popovsky" wrote in
message ...

Get and compare numbers

I would really appreciate if you would help me out with this:

i have a couple of sheets with colums containing names and coordinates
of objects. as text.
something like this:
in column A : names of objects.
in column B : coordinates as a text field with the folowing
formatting:
A B
SEA 'coord x:4.50cm y:27.50cm w:21.12cm h:28.87cm index:2

(+some values can be missing.. for ex :SHIP coord x:11.50cm y:32.00cm
h:2.08cm index:40)


i need to compute the following :
for each object i gotta find out if it inside the coordinates of
another object.
Like this:
we take X value (lets call it x1) of one object and compare to other
object's values of X (lets call it x2) and X+W (lets call it XW).
if x2<x1<xw and y2<y1<yh (same thing for vertical) then the object is
inside and i need a msgbox saying : SHIP is inside SEA.

THANX. I really appreciate your help.


--
popovsky


------------------------------------------------------------------------
popovsky's Profile:

http://www.excelforum.com/member.php...o&userid=25309
View this thread: http://www.excelforum.com/showthread...hreadid=387953