By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,057 Members | 1,346 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,057 IT Pros & Developers. It's quick & easy.

stopping a running script with a keypress

P: 21
Hey,

I have a problem with a small program that I want to make. It's a script that keeps running by using a Do While loop. I want to stop the script when a certain key is pressed. But the problem is that the keypress sub isn't working because the other sub keeps running. Is there a way of doing this, or is there someone who knows how to replace the do while with the use of a timer or someting, so that I can make a pause between every run of my script.

Thanks already
Dec 10 '07 #1
Share this Question
Share on Google+
4 Replies


kadghar
Expert 100+
P: 1,295
Hey,

I have a problem with a small program that I want to make. It's a script that keeps running by using a Do While loop. I want to stop the script when a certain key is pressed. But the problem is that the keypress sub isn't working because the other sub keeps running. Is there a way of doing this, or is there someone who knows how to replace the do while with the use of a timer or someting, so that I can make a pause between every run of my script.

Thanks already
hmmm, try with DoEvents.

HTH
Dec 10 '07 #2

P: 21
I don't have any experience with that :-s, And I looked on google know but the first pages I found all used DoEvents with visual basic.Net. But is it also working in VB 6, because then I will continue my search.

But s small other question, can I vb executable close another running executable, because otherwise a make a small exe with only the keypress and the code for closing the other program. And in the other program, I just start the second program in the begin. Is this possible and how do I do this, because I can start something with shellexecute but i don't know how to close something.

thanks already fr you're fast support.
Dec 10 '07 #3

kadghar
Expert 100+
P: 1,295
I don't have any experience with that :-s, And I looked on google know but the first pages I found all used DoEvents with visual basic.Net. But is it also working in VB 6, because then I will continue my search.

But s small other question, can I vb executable close another running executable, because otherwise a make a small exe with only the keypress and the code for closing the other program. And in the other program, I just start the second program in the begin. Is this possible and how do I do this, because I can start something with shellexecute but i don't know how to close something.

thanks already fr you're fast support.
yes it's possible, but its easier using DoEvents
Lets make a little example.

create a label with caption = 1 and write:
Expand|Select|Wrap|Line Numbers
  1. private sub Label1_click()
  2. do
  3.     label1.caption = label1.caption +1
  4.     doEvents
  5. loop
  6. end sub
that will make the label increase its value as crazy when you click on it but you still can work with the rest of the form. That's what DoEvents is for. To do something else while a process is running.

then just put a command button with something like
Expand|Select|Wrap|Line Numbers
  1. private sub command1_click()
  2. end
  3. end sub
and you're done

HTH
Dec 10 '07 #4

P: 21
Really thank you a lot, you're not only giving me the solution, but also explaining me in short what all things do.

Thanks a lot!!!
Dec 10 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.