# Thread: Equation Help

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

## Unanswered: Equation Help

I need some help on an equation.
I have a starting position called: OrgPieceIndex
I have an ending position called: Index

Where OrgPieceIndex and Index are locations on a grid 15 by 9. (Grid starting location is 1 and ending location is 150.) What I want is to test to see if OrgPieceIndex and Index falls within the same row on the grid. The grid is 1 to 15 (first row), 16 to 30 (second row), 31 to 45 (third row), etc... up to 150.

I'd rather not use a case statement but somehow configure an if statement like that below...

If OrgPieceIndex > Index then
If OrgPieceIndex > 0 And OrgPieceIndex < 16 And Index > 0 And Index < 16 Then
'Test here to see if OrgPieceIndex and Index are on the same row
Call SameRow(Index, OrgPieceIndex, -1)
Exit Sub
End If
If OrgPieceIndex > 15 And OrgPieceIndex < 31 And Index > 15 And Index < 31 Then
'Test here to see if OrgPieceIndex and Index are on the same row
Call SameRow(Index, OrgPieceIndex, -1)
Exit Sub
End If
If OrgPieceIndex > 30 And OrgPieceIndex < 46 And Index > 30 And Index < 46 Then
'Test here to see if OrgPieceIndex and Index are on the same row
Call SameRow(Index, OrgPieceIndex, -1)
Exit Sub
End If

If Index > OrgPieceIndex then
If OrgPieceIndex > 0 And OrgPieceIndex < 16 And Index > 0 And Index < 16 Then
'Test here to see if OrgPieceIndex and Index are on the same row
Call SameRow(Index, OrgPieceIndex, -1)
Exit Sub
End If
If OrgPieceIndex > 15 And OrgPieceIndex < 31 And Index > 15 And Index < 31 Then
'Test here to see if OrgPieceIndex and Index are on the same row
Call SameRow(Index, OrgPieceIndex, -1)
Exit Sub
End If
If OrgPieceIndex > 30 And OrgPieceIndex < 46 And Index > 30 And Index < 46 Then
'Test here to see if OrgPieceIndex and Index are on the same row
Call SameRow(Index, OrgPieceIndex, -1)
Exit Sub
End If

Can someone please give me a hand with this equation? I can't change anything with the structure of the grid and how it is numbered. I want to combine all these statements...

If OrgPieceIndex > 0 And OrgPieceIndex < 16 And Index > 0 And Index < 16 Then Call SameRow(Index, OrgPieceIndex, -1)
If OrgPieceIndex > 15 And OrgPieceIndex < 31 And Index > 15 And Index < 31 Then Call SameRow(Index, OrgPieceIndex, -1)
If OrgPieceIndex > 30 And OrgPieceIndex < 46 And Index > 30 And Index < 46 Then Call SameRow(Index, OrgPieceIndex, -1)
If OrgPieceIndex > 45 And OrgPieceIndex < 61 And Index > 45 And Index < 61 Then Call SameRow(Index, OrgPieceIndex, -1)
If OrgPieceIndex > 60 And OrgPieceIndex < 76 And Index > 60 And Index < 76 Then Call SameRow(Index, OrgPieceIndex, -1)
If OrgPieceIndex > 75 And OrgPieceIndex < 91 And Index > 75 And Index < 91 Then Call SameRow(Index, OrgPieceIndex, -1)
If OrgPieceIndex > 90 And OrgPieceIndex < 106 And Index > 90 And Index < 106 Then Call SameRow(Index, OrgPieceIndex, -1)
If OrgPieceIndex > 105 And OrgPieceIndex < 121 And Index > 105 And Index < 121 Then Call SameRow(Index, OrgPieceIndex, -1)
If OrgPieceIndex > 120 And OrgPieceIndex < 136 And Index > 120 And Index < 136 Then Call SameRow(Index, OrgPieceIndex, -1)
If OrgPieceIndex > 135 And OrgPieceIndex < 151 And Index > 135 And Index < 151 Then Call SameRow(Index, OrgPieceIndex, -1)

into 1 statement.

I would also like to see if the OrgPieceIndex and Index are vertically aligned (for example, OrgPieceIndex = 45 and index = 30) or (OrgPieceIndex = 58 and Index = 43). And if possible, if OrgPieceIndex is diagonal to Index (for example, OrgPieceIndex = 30 and Index = 14) or (OrgPieceIndex = 45 and Index =13) or (OrgPieceIndex = 50 and Index = 98).
Last edited by pkstormy; 06-30-07 at 21:22.

2. Purveyor of Discontent
Join Date
Mar 2003
Location
The Bottom of The Barrel
Posts
6,102
What I want is to test to see if OrgPieceIndex and Index falls within the same row on the grid. The grid is 1 to 15 (first row), 16 to 30 (second row), 31 to 45 (third row), etc... up to 150.
If Ceiling(OrgPieceIndex / 15) = Ceiling(Index / 15) Then...

I would also like to see if the OrgPieceIndex and Index are vertically aligned (for example, OrgPieceIndex = 45 and index = 30) or (OrgPieceIndex = 58 and Index = 43).
If OrgPeiceIndex % 15 = Index % 15 then...

And if possible, if OrgPieceIndex is diagonal to Index (for example, OrgPieceIndex = 30 and Index = 14) or (OrgPieceIndex = 45 and Index =13) or (OrgPieceIndex = 50 and Index = 98).
If ABS(Ceiling(OrgPieceIndex / 15) - Ceiling(Index / 15)) = 1 and ABS(OrgPeiceIndex % 15 - Index % 15) = 1 then...

**I don't remember the actual functions that perform ceiling and abs in vb, but you get the idea
Last edited by Teddy; 07-02-07 at 14:08.

3. Moderator
Join Date
Dec 2004
Location
Posts
3,928
Cool! I got the idea. Thank you very much Teddy!

4. Moderator
Join Date
Dec 2004
Location
Posts
3,928
Teddy,

I get an error trying to utilize the Ceiling and ABS functions (byRef argument type match).

Is there something I need to do such as add a reference or are these functions that I need to add in from somewhere?

I've never worked with these functions before.

5. Moderator
Join Date
Dec 2004
Location