PDA

Click to See Complete Forum and Search --> : Using a keypress to break out a loop


Gumppy
Jan 13th, 2000, 03:01 AM
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?

rino_2
Jan 13th, 2000, 03:25 AM
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!

KENNNY
Jan 13th, 2000, 05:19 AM
remember to put DoEvents inside your loop, or it will hang the OS while your prog is running ;)

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

Nitro
Jan 13th, 2000, 05:37 AM
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.

Gumppy
Jan 13th, 2000, 06:39 AM
Thank you for the help, The DoEvents worx great =)