Results 1 to 5 of 5

Thread: Using a keypress to break out a loop

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 1999
    Posts
    33

    Post

    I've currently have a loop of a ball bouncing around the screen, but i wanna know if thers any way u can get the loop to break if you hit escape or x. I tried to call form_keypress with in the loop to see if a key was pressed but that doesnt seem to be working. can anyone help?

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    Hi,

    This may work:
    dim run as boolean

    --------------------

    do until run = false
    ' ball bouncing code
    loop

    Private Sub Form_KeyPress(KeyAscii As Integer)
    dim strKey as string
    strKey = chr(keyascii)
    if strKey = "x" then run = false
    End Sub

    -------------------

    I hope it works!



  3. #3
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    355

    Post

    remember to put DoEvents inside your loop, or it will hang the OS while your prog is running

    ------------------
    cintel rules
    www.cintelsoftware.co.uk

  4. #4
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633

    Post

    Inorder for you to break a loop, you must use the function Doevents. Look this up in the help because that is the official method of breaking a loop.

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 1999
    Posts
    33

    Post

    Thank you for the help, The DoEvents worx great =)

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