
Originally Posted by
WarrenW
Hi,
I have two X/Y points on my form. I need to find every X/Y between the two as if you were drawing a line. I tried thinking how to do it but I'm having trouble.
I know I need as many steps in between as possible. For example, if X1 and X2 are only one pixel apart and Y1 and Y2 are 20 pixels apart, I need 20 points in between. So I need the most depending on if the X or Y has the biggest difference.
I should know how to do this but its been a long morning!
I think this might give you what you need, but it I didnt really test it much
I really dont understand how you are caculating the number of points though ... shouldnt it just be square root of the sum of the deltas squared?
Code:
Private Sub Command1_Click()
Dim i As Integer, x(1) As Double, y(1) As Double
Dim yInt As Double, slope As Double
Dim tstY As Double
x(0) = 1: x(1) = 200: y(0) = 1: y(1) = 200
slope = (y(1) - y(0)) / (x(1) - x(0))
yInt = y(1) - slope * x(1)
Dim strResults As String
For i = x(0) To x(1)
tstY = slope * i + yInt
If tstY - Fix(tstY) = 0 Then
strResults = strResults & i & "," & tstY & vbCrLf
End If
Next i
MsgBox strResults
End Sub