Help With Column Algorithm

  • Thread starter Thread starter ChrisB
  • Start date Start date
C

ChrisB

Hi all, I've written a function to return true or false if the value I
supply to it is close to a predefined column:

Private Function IsOnColumn(ByVal Position As Integer) As Boolean
Const COLUMN_WIDTH As Integer = 100
Const SNAP_DISTANCE As Integer = 20

Return (Position Mod COLUMN_WIDTH > COLUMN_WIDTH - SNAP_DISTANCE
OrElse Position Mod COLUMN_WIDTH < SNAP_DISTANCE)
End Function

I've been trying to modify it so that the column detection shifts to the
left (COLUMN_WIDTH /2). So instead of the columns appearing at 0, 100, 200,
300 400 etc., they appear at 50, 150, 250, 350, 450 and so on, but I'm
pulling hair out!

Can anyone help?
Many thanks,
Chris.
 
Private Function IsOnColumn(ByVal Position As Integer) As Boolean
Const COLUMN_WIDTH As Integer = 100
Const SNAP_DISTANCE As Integer = 20
Return (Position Mod COLUMN_WIDTH > COLUMN_WIDTH - SNAP_DISTANCE
OrElse Position Mod COLUMN_WIDTH < SNAP_DISTANCE)
End Function

I've been trying to modify it so that the column detection shifts to the
left (COLUMN_WIDTH /2). So instead of the columns appearing at 0, 100, 200,
300 400 etc., they appear at 50, 150, 250, 350, 450 and so on, but I'm
pulling hair out!

If I understand correctly, you want position+(COLUMN_WIDTH /2) to behave
like position does in the above code. If that is true, insert
position -= (COLUMN_WIDTH /2)
after the const statements.
 
Thanks mate, I thought the answer would be a simple one, but after staring
at my monitor for so long, I was just going blind to all the Mod's and
COLUMN_WIDTH's!

Nice one,
Chris.
 
Back
Top