STOP a process in between .....

Reply

Join Date: Jun 2007
Posts: 68
Reputation: RahulV is an unknown quantity at this point 
Solved Threads: 0
RahulV's Avatar
RahulV RahulV is offline Offline
Junior Poster in Training

STOP a process in between .....

 
0
  #1
Feb 14th, 2009
hi,
i've created a Form1 which contains a long running process. But i want an feature that will help the user to stop the running process in between, when i click a Button or some other control.

How is it possible?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 68
Reputation: RahulV is an unknown quantity at this point 
Solved Threads: 0
RahulV's Avatar
RahulV RahulV is offline Offline
Junior Poster in Training

Re: STOP a process in between .....

 
0
  #2
Feb 14th, 2009
Also the problem is that my Form1 which runs the process goes like disabled (automatically), ..... thats because, .... u can imagine because its a long process.

so im not able access the controls on the Form1.


PLS help !!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 509
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 88
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: STOP a process in between .....

 
0
  #3
Feb 15th, 2009
Hi, use

DoEvents function so that other process get chance. This function helps to disable your form.

Example
  1. Dim bStop As Boolean
  2.  
  3. Private Sub cmdProcess_Click()
  4. Do While bStop <> True
  5. '
  6. ' Long Process
  7. '
  8. CurrentX = 0
  9. CurrentY = 0
  10. Cls
  11. Print Time
  12. DoEvents
  13. Loop
  14. bStop = False
  15. End Sub
  16.  
  17. Private Sub cmdStop_Click()
  18. bStop = True
  19. End Sub
KSG
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: STOP a process in between .....

 
0
  #4
Feb 15th, 2009
If it is a system call (such as shell, or wsh.run) and it is blocking (ie, the program is waiting for shell or wsh.run to finish the externally running program), you need a much more complicated method involving things like waitforsingleobject...
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 68
Reputation: RahulV is an unknown quantity at this point 
Solved Threads: 0
RahulV's Avatar
RahulV RahulV is offline Offline
Junior Poster in Training

Re: STOP a process in between .....

 
0
  #5
Feb 16th, 2009
Originally Posted by selvaganapathy View Post
Hi, use

DoEvents function so that other process get chance. This function helps to disable your form.

Example
  1. Dim bStop As Boolean
  2.  
  3. Private Sub cmdProcess_Click()
  4. Do While bStop <> True
  5. '
  6. ' Long Process
  7. '
  8. CurrentX = 0
  9. CurrentY = 0
  10. Cls
  11. Print Time
  12. DoEvents
  13. Loop
  14. bStop = False
  15. End Sub
  16.  
  17. Private Sub cmdStop_Click()
  18. bStop = True
  19. End Sub

Sorry this did not work i told u that, mu Form1 gets disabled, thats normal when there's some long process is taking place. So im not getting access to the cmdButton (to click).
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 68
Reputation: RahulV is an unknown quantity at this point 
Solved Threads: 0
RahulV's Avatar
RahulV RahulV is offline Offline
Junior Poster in Training

Re: STOP a process in between .....

 
0
  #6
Feb 16th, 2009
Originally Posted by Comatose View Post
If it is a system call (such as shell, or wsh.run) and it is blocking (ie, the program is waiting for shell or wsh.run to finish the externally running program), you need a much more complicated method involving things like waitforsingleobject...

Im not running any other program or shell.
Its just that the Form1 is processing a long process. Like suppose counting to 1000crores or more.
Last edited by RahulV; Feb 16th, 2009 at 2:58 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: STOP a process in between .....

 
0
  #7
Feb 16th, 2009
then doevents should work just fine.... somewhere when your form1 is doing processing... probably in some kind of do loop or while loop or for loop, simply stick a doevents.
  1. for i = 0 to 1000000
  2. retval = i * i
  3. doevents
  4. next i
Last edited by Comatose; Feb 16th, 2009 at 3:53 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 68
Reputation: RahulV is an unknown quantity at this point 
Solved Threads: 0
RahulV's Avatar
RahulV RahulV is offline Offline
Junior Poster in Training

Re: STOP a process in between .....

 
0
  #8
Feb 18th, 2009
Originally Posted by Comatose View Post
then doevents should work just fine.... somewhere when your form1 is doing processing... probably in some kind of do loop or while loop or for loop, simply stick a doevents.
  1. for i = 0 to 1000000
  2. retval = i * i
  3. doevents
  4. next i
Sorry it did not work for me.....
Pls can anyone help me with this.

can creating thread help with this?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: STOP a process in between .....

 
0
  #9
Feb 18th, 2009
I'm going to need to see your code then, in order to be able to troubleshoot this further.
You can not create a thread in Visual Basic 4/5/6. Doevents is only a partial fix to your problem. Doevents tells VB that a long ass loop is going on, and that it needs to do other stuff too, like handle mouse clicks. So, just for example, make a form and put 2 buttons on it....in button1, put this:
  1. while 1 = 1
  2. x = 200 * 200
  3. wend
Then, in button2, put this:
Now run the code, and click button1. Now Try to click button2. Nice Huh? Now modify button1 to have this:
  1. while 1 = 1
  2. x = 200 * 200
  3. doevents
  4. wend
Run the code, click button1, now click button2..... oh wow. Big difference.
Last edited by Comatose; Feb 18th, 2009 at 9:29 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 68
Reputation: RahulV is an unknown quantity at this point 
Solved Threads: 0
RahulV's Avatar
RahulV RahulV is offline Offline
Junior Poster in Training

Re: STOP a process in between .....

 
0
  #10
Feb 18th, 2009
@ Comatose

Okay!
that does work.

but in ur example u had written
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. End
statement for Button2 and that ends the whole program, instead i want to just end the running sub-procedure or the loop.

You have any other idea on this?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC