Problem with a loop


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: Problem with a loop

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Posts
    57

    Problem with a loop

    Within a mousemove event I have, I have a loop that continues to run if the user is holding the
    mouse down. Here is the code:

    Code:
    Private Sub picAlien1_MouseMove(index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    On Error GoTo ExitSub
        If MouseDown Then
            Do While MouseDown
            Dim i As Integer
                GetCursorPos Mouse
                ScreenToClient hwnd, Mouse
                With picAlien1(index)
                    If Mouse.X Mod 10 = 0 Then .left = Mouse.X
                    If Mouse.Y Mod 10 = 0 Then .top = Mouse.Y
                    For i = 0 To UBound(Alien1, 1)
                        If Alien1(i).index = index - 1 Then
                            Alien1(i).X = .left
                            Alien1(i).Y = .top
                        End If
                    Next
                End With
                DoEvents
            Loop
            With picAlien1(index)
                Unload Properties
                Properties.Show
                Properties.SetProperties .left, .top, 1, index - 1
            End With
        End If
    ExitSub: End Sub
    The problem is when the user lets go of the mouse and the control finally reaches the End Sub line,
    the control goes back to the end of the loop, yet the mousedown boolean is still equal to false.

    I have tried to comment the line of code that tell the program what to do when an error occurs, I've
    commented the line of code between the end of the Loop and the End If(this would be the with block) and
    I am out of ideas, any help would be appreciated, thanks.

    Edit: Figured out problem, it seems that the mousemove event kept calling itself, although I didn't see it happen
    in code so in the end the program would read the line of code that it was on before the doevents command however
    many times mousemove called itself. Fixed this with a boolean that tells the program if the program is already inside of the loop.
    Last edited by salvinger; 05-07-2005 at 08:03 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center