Results 1 to 2 of 2

Thread: What is wrong in this code

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    15

    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
    Last edited by anhdung; Jan 27th, 2009 at 10:24 AM.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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

Posting Permissions

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



Click Here to Expand Forum to Full Width