Results 1 to 5 of 5

Thread: Equation Help

  1. #1
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    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.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    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.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Cool! I got the idea. Thank you very much Teddy!
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    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.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    The problem is that if I have a cell (say 106 which is on the left edge), it sees cell 74 as diagonal (which is not diagonal on the grid unless you go off the left edge) whereas cell 116 is diagonal (on the grid) to 83. I don't want it to detect diagonally if it has to go off the edge to do it.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

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