STOP a process in between .....

Reply

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: 212
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

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

 
0
  #11
Feb 18th, 2009
Uh, yeah. Instead of "end", have a global Boolean variable. Have it set to like false.... then in button2, have it says something like flag = true, then in button1, have an if or something like if flag = true then exit sub. Or something.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 92
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
  #12
Feb 22nd, 2009
Consider this code:

visualbasic Syntax (Toggle Plain Text)
  1. Public bc As Boolean
  2. Dim x As Long
  3.  
  4. Private Sub Command1_Click()
  5. If bc Then
  6. MsgBox x
  7. GoTo EndHere
  8. Else
  9. Call exec
  10. End If
  11. EndHere:
  12. End Sub
  13.  
  14. Private Sub Command2_Click()
  15. bc = True
  16. Call Command1_Click
  17. End Sub
  18.  
  19. Private Sub Form_Load()
  20. bc = False
  21. End Sub
  22.  
  23. Public Sub exec()
  24. While 1 = 1
  25. x = x + 10
  26. Label1 = x
  27. DoEvents
  28. Wend
  29. End Sub

now here, i want to stop the execution of a sub-procedure Public Sub exec() which is called by another sub-procedure Private Sub Command1_Click() but without changing or adding any code into Public Sub exec().
even after applying all ur helps it did not work as needed. But all your help was valuable.

How to do it?

(Forgive me for not providing the code earlier.)
Last edited by RahulV; Feb 22nd, 2009 at 11:00 am.
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: 212
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

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

 
0
  #13
Feb 22nd, 2009
It's a very bad practice to use goto in programming. It is strongly frowned upon by professional programmers, and actually forbidden in business code. Instead, you can use "exit sub" to replace that goto statement. Even that (since it is just a single if statement and nothing else) isn't even necessary, as the code will simply end once the if statement is completed.
Last edited by Comatose; Feb 22nd, 2009 at 12:35 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 92
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
  #14
Feb 23rd, 2009
Originally Posted by Comatose View Post
It's a very bad practice to use goto in programming. It is strongly frowned upon by professional programmers, and actually forbidden in business code. Instead, you can use "exit sub" to replace that goto statement. Even that (since it is just a single if statement and nothing else) isn't even necessary, as the code will simply end once the if statement is completed.
But if i replace the GoTo statement with End Sub, it give a compiler error "Block If without End If". So i had to use the GoTo statement.

Now pls can anyone help me in solving the basic problem being discussed here?

PLEASE HELP !!!
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: 212
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

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

 
0
  #15
Feb 23rd, 2009
Not end sub.... exit sub...
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 92
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
  #16
Feb 24th, 2009
Originally Posted by Comatose View Post
Not end sub.... exit sub...
O!
i'm terribly sorry for that!!
(What's happening to me these days? ...... might be that im in high tension to know more!!!)
once again i'm sorry!!

Pls help me with the main problem!! that we are discussing here.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 92
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
  #17
Feb 24th, 2009
ONCE AGAIN REPEATING THE PROBLEM

Originally Posted by RahulV View Post
Consider this code:

visualbasic Syntax (Toggle Plain Text)
  1. Public bc As Boolean
  2. Dim x As Long
  3.  
  4. Private Sub Command1_Click()
  5. If bc Then
  6. MsgBox x
  7. GoTo EndHere
  8. Else
  9. Call exec
  10. End If
  11. EndHere:
  12. End Sub
  13.  
  14. Private Sub Command2_Click()
  15. bc = True
  16. Call Command1_Click
  17. End Sub
  18.  
  19. Private Sub Form_Load()
  20. bc = False
  21. End Sub
  22.  
  23. Public Sub exec()
  24. While 1 = 1
  25. x = x + 10
  26. Label1 = x
  27. DoEvents
  28. Wend
  29. End Sub

now here, i want to stop the execution of a sub-procedure Public Sub exec() which is called by another sub-procedure Private Sub Command1_Click() but without changing or adding any code into Public Sub exec().
even after applying all ur helps it did not work as needed. But all your help was valuable.

How to do it?

(Forgive me for not providing the code earlier.)
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


Views: 1441 | Replies: 16
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC