Microsoft KB Archive/43747

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Knowledge Base


PtInRects Returns Incorrect Value with Multidimensional Arrays

Article ID: 43747

Article Last Modified on 11/21/2006

This article was previously published under Q43747

SUMMARY

The modified version of the PointinRec example below demonstrates that PtInRects does not work correctly if the coordinates of the boxes are stored in a multidimensional array. When you click the mouse within a particular box, the box number is returned.

MORE INFORMATION

In the example below, the box number returned is off by (2 * N - 1), where N is the number of the box that the mouse was clicked in. If the first box is clicked, it returns a 1; if the second box is clicked, it returns a 3; the third box returns a 5; and the fourth box returns a 7.

Microsoft is researching this problem and will post more information as it becomes available.

The following code example demonstrates the problem:

'----------------------------------------------------------------'
' PointinRec example. Copyright 1988 Microsoft Corp. This
' program is for personal use only. It may not be redistributed in
' any form, electronic or mechanical, for any purpose, without the
' written permission of Microsoft Corporation.
'----------------------------------------------------------------'

' This program draws four rectangles on the screen and waits for
' the user to click the mouse inside of one of the rectangles. It
' will then print out the number of the rectangle that the mouse
' was clicked in.

DIM box1%(7,7),pt%(1)
num% = 8
first% = 0
box1%(0,0)=40
box1%(1,0 )=10
box1%(2,0)=100
box1%(3,0)=130
'--------------
box1%(0,1)=110
box1%(1,1)=10
box1%(2,1)=170
box1%(3,1)=130
'--------------
box1%(0,2)=40
box1%(1,2)=140
box1%(2,2)=100
box1%(3,2)=260
'--------------
box1%(0,3)=110
box1%(1,3)=140
box1%(2,3)=170
box1%(3,3)=260
FRAMERECT (VARPTR(box1%(0,0)))
CALL MOVETO (13,45)
PRINT "Box 1
FRAMERECT (VARPTR(box1%(0,1)))
CALL MOVETO (13,115)
PRINT "Box 2"
FRAMERECT (VARPTR(box1%(0,2)))
CALL MOVETO (143,45)
PRINT "Box 3"
FRAMERECT (VARPTR(box1%(0,3)))
CALL MOVETO (143,115)
PRINT "Box 4"
LOCATE 13,10
PRINT "Use File Menu to Quit"
WHILE 1
WHILE MOUSE (0) = 0 :WEND
SetPt pt%(0),MOUSE (3), MOUSE(4)
    PtInRects pt%(0),box1%(0,0),num%,first%
    PRINT first%
    FRAMERECT (VARPTR(box1%(0,0)))
    LOCATE 1,1
    PRINT first%
WEND
                


Additional query words: MQuickB

Keywords: KB43747