General discussion

Locked

Need Help with Stopping a command

By techman ·
I have a small search program that goes through a ascii file. the file is about 70000 records so it takes a minute or so to parse. They want me to be make it so that once the user types in the search criteria and click the search button ( a command button ( to be able to cancel the search. I've tried having all the code behind the command1_click button and having another button to click that creates a value to stop it. However once it's executing the code it won't let the user click anthinguntil it's finished. I've also tried useing a sub procedure and the results stayed the same. I'm using VB 4.0 Thanks

Dwane

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Need Help with Stopping a command

by andrew In reply to Need Help with Stopping a ...

Within the processing loop, call DoEvents.
This will momentarily release control to the OS, so that it can process messages.

Collapse -

Need Help with Stopping a command

by Shanghai Sam In reply to Need Help with Stopping a ...

Poster rated this answer

Collapse -

Need Help with Stopping a command

by andrew In reply to Need Help with Stopping a ...

Here's a little example:

Put a command button and a text box on a form. Set the button's caption to "Stopped".

add this code to the command button:

Private Sub Command1_Click()
Dim n
If Command1.Caption = "Running" Then
Command1.Caption = "Stopped"
Else
Command1.Caption = "Running"
End If

Do
If Command1.Caption = "Stopped" Then Exit Do
n = n + 1
Text1 = n
DoEvents 'release control to the OS
Loop
End Sub

Each click on the button will start/stop the looping counter. Without the DoEvents statement, it would loop forever because the form cannot process waiting click messages.

Collapse -

Need Help with Stopping a command

by Shanghai Sam In reply to Need Help with Stopping a ...

Thank you.. the Doevents works like a charm. I really appreciate the help. BTW you wouldn't by chance have a tip on getting data from the screen into Word ( auto launching word ) and automatically putting it in would you?

Thanks
Dwane

Collapse -

Need Help with Stopping a command

by techman In reply to Need Help with Stopping a ...

This question was closed by the author

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums