What is wrong in this code
I used code to divide a line into equal distant and resulted in picture as
http://img230.imageshack.us/my.php?image=dasdae1.gif
Code:
Private Sub Form_Load()
Dim X1 As Long, Y1 As Long
Dim X2 As Long, Y2 As Long
Me.AutoRedraw = True
Me.ScaleMode = vbPixels
X1 = 20: Y1 = 50
X2 = 300: Y2 = 400
Me.Line (X1, Y1)-(X2, Y2)
Call divideline(X1, Y1, X2, Y2, 50)
End Sub
Private Sub divideline(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long, segments As Long)
Dim i As Long
Dim dy, Y As Single
Dim dx, X As Single
dx = (X2 - X1) \ segments
dy = (Y2 - Y1) \ segments
For i = 0 To segments
Circle (X1 + dx * i, Y1 + dy * i), 1 'or whatever
X = X1 + dx * i
Y = Y1 + dy * i
List1.AddItem "X = " & X & vbTab & "Y = " & Y
Next i
End Sub
Re: What is wrong in this code
I cannot see the picture so this is a guess.
Use the floating point division operator /, not the integer division operator \
dx = (X2 - X1) / segments
dy = (Y2 - Y1) / segments