943,875 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Feb 18th, 2009
0

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

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 22nd, 2009
0

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

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 12:00 pm.
Reputation Points: 26
Solved Threads: 0
Junior Poster in Training
RahulV is offline Offline
92 posts
since Jun 2007
Feb 22nd, 2009
0

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

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 1:35 pm.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 23rd, 2009
0

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

Click to Expand / Collapse  Quote originally posted by Comatose ...
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 !!!
Reputation Points: 26
Solved Threads: 0
Junior Poster in Training
RahulV is offline Offline
92 posts
since Jun 2007
Feb 23rd, 2009
0

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

Not end sub.... exit sub...
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 24th, 2009
0

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

Click to Expand / Collapse  Quote originally posted by Comatose ...
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.
Reputation Points: 26
Solved Threads: 0
Junior Poster in Training
RahulV is offline Offline
92 posts
since Jun 2007
Feb 24th, 2009
0

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

ONCE AGAIN REPEATING THE PROBLEM

Click to Expand / Collapse  Quote originally posted by RahulV ...
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.)
Reputation Points: 26
Solved Threads: 0
Junior Poster in Training
RahulV is offline Offline
92 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: SSTAB problem with TAB2
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: access events of form in UserControl





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC