1. Moderator
Join Date
Dec 2004
Location
Posts
3,928

I have a grid with cells 1 through 150 (15 columns by 10 rows) . I want to detect if the cells are diagonally BUT I don't want to go off the edge of the grid to do it. For example, cell 115 is diagonal to 83 (on the grid) and cell 106 is diagonal to 74 (but I want it to return false for 106 to 74 because you have to go off the edge of the grid.

Here's what I'm using...

If Int((OrgPieceIndex - Index) / 16) = ((OrgPieceIndex - Index) / 16) Then
and
If Int((OrgPieceIndex - Index) / 14) = ((OrgPieceIndex - Index) / 14) Then

(Teddy - I have to ask this again as I'm having problems with the equation.)
Last edited by pkstormy; 07-03-07 at 20:53.

2. Purveyor of Discontent
Join Date
Mar 2003
Location
The Bottom of The Barrel
Posts
6,102
Hmmmm, I overlooked that possiblity...

You should be starting with this, which tells you that the two values are on vertically adjacent rows and the offset one column from each other:

Code:
`If ABS(Ceiling(OrgPieceIndex / 15) - Ceiling(Index / 15)) = 1 and ABS(OrgPeiceIndex % 15 - Index % 15) = 1`
The extra step to check is to ensure you don't have one value % 15 = 1, and the other % 15 = 0, this would mean they're at opposite sides of the grid:

Code:
`If Not (OrgPieceIndex mod 15 + Index mod 15) = 1 Then...`
You know those were modulo operators in my first post and not divisors right?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•