Click to See Complete Forum and Search --> : doevents


ma622
August 16th, 2001, 02:55 AM
i made a funtcio that conatains in the WHILE the DOEVENTS
but when i need to write in my CANCEL BUTTON?

Cakkie
August 16th, 2001, 04:09 AM
You will need to add a boolean to you WHILE loop.

Do While (X > 10) And Not(blnCancelPressed)
' some code
DoEvents
Loop



The (X > 10) must be replaced by your condition. Then when the cancel button is pressed, set the blnCancelPressed to true, so you will exit the loop. Then after the loop, check if they pressed cancel, and exit. This must only be done if further processing comes after the loop. Make sure that blnCancelPressed is accessible from the two functions, so add it to the general declaration section of the module/form.

' Cancel Button
private Sub cmdCancel_Click()

blnCancelPressed = true

End Sub

private Sub SomeSub()

blnCancelPressed = false

Do While (X > 10) And Not(blnCancelPressed)
' some code
DoEvents
Loop

If blnCancelPressed then Exit Sub

' Some Other Processing

End Sub




Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

ma622
August 16th, 2001, 01:04 PM
ok 10X, and whats about FOR ....but i want the button to cancel the for and not "end for"

hoa01206
August 16th, 2001, 01:40 PM
Could you please show me your code concerning your question, and tell me exactly what you are trying to do

Thanks
Hisham