| | |
Exiting a sub procedure ?
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Consider this VB6 source code
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().
Does anyone have an answer?
How to do it?
visualbasic Syntax (Toggle Plain Text)
Public bc As Boolean Dim x As Long Private Sub Command1_Click() If bc Then MsgBox x Exit Sub Else Call exec End If End Sub Private Sub Command2_Click() bc = True Call Command1_Click End Sub Private Sub Form_Load() bc = False End Sub Public Sub exec() While 1 = 1 x = x + 10 Label1 = x DoEvents Wend 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().
Does anyone have an answer?
How to do it?
Last edited by RahulV; Mar 4th, 2009 at 12:58 pm.
You're asking to make code do something different without changing it. It's kind of difficult to do.
I would say, if you wanted to halt execution on the sub-routine before it completes without changing the code in the sub-routine, then you'd have to call it asynchronously in a new thread and have your original thread halt execution when a condition is met (like Labell equalling a specific value) by killing your new thread prematurely. Would that cause a memory leak? Almost definitely, but, it meets your criteria. Besides that, I can't think of a way to do what you're describing. I would highly, highly recommend that you don't do that, though.
I'd have to ask why you're calling a sub-routine that goes into an infinite loop, anyway. I'd also have to ask why you insist that it can't be changed to suit your needs.
I would say, if you wanted to halt execution on the sub-routine before it completes without changing the code in the sub-routine, then you'd have to call it asynchronously in a new thread and have your original thread halt execution when a condition is met (like Labell equalling a specific value) by killing your new thread prematurely. Would that cause a memory leak? Almost definitely, but, it meets your criteria. Besides that, I can't think of a way to do what you're describing. I would highly, highly recommend that you don't do that, though.
I'd have to ask why you're calling a sub-routine that goes into an infinite loop, anyway. I'd also have to ask why you insist that it can't be changed to suit your needs.
Last edited by SlyMaelstrom; Mar 4th, 2009 at 2:25 pm.
•
•
•
•
If you don't want it executed, don't call it from the click event.
We'll see what he says, I guess.
•
•
Join Date: Mar 2009
Posts: 901
Reputation:
Solved Threads: 167
•
•
•
•
Do you think he is looking to avoid executing it, at all? I didn't even consider that's what he was asking. He said stop execution and I saw that exec() continued in an infinite loop, so I assumed he was looking for a way to halt execution at a point.
We'll see what he says, I guess.
•
•
•
•
You're asking to make code do something different without changing it. It's kind of difficult to do.
I would say, if you wanted to halt execution on the sub-routine before it completes without changing the code in the sub-routine, then you'd have to call it asynchronously in a new thread and have your original thread halt execution when a condition is met (like Labell equalling a specific value) by killing your new thread prematurely. Would that cause a memory leak? Almost definitely, but, it meets your criteria. Besides that, I can't think of a way to do what you're describing. I would highly, highly recommend that you don't do that, though.
I'd have to ask why you're calling a sub-routine that goes into an infinite loop, anyway. I'd also have to ask why you insist that it can't be changed to suit your needs.
I too had considered the Thread concept but I dont know how to implement Thread in VB 6.
Can you help me how to create and implement Threads? I think that would work.
Any other techniques to perform the required would be highly appreciated.
•
•
•
•
Do you think he is looking to avoid executing it, at all? I didn't even consider that's what he was asking. He said stop execution and I saw that exec() continued in an infinite loop, so I assumed he was looking for a way to halt execution at a point.
We'll see what he says, I guess.
•
•
•
•
Thank you,
I too had considered the Thread concept but I dont know how to implement Thread in VB 6.
Can you help me how to create and implement Threads? I think that would work.
Any other techniques to perform the required would be highly appreciated.
There is way too much to be said about multi-threading to write in a reply to this thread and I don't have the time or patience to write it all. Not to mention, I wouldn't want the opportunity to miss something and give you bad info. As I said in the first place, it's a very bad idea to kill a thread prematurely. It basically has the same effects of running a macro in some scripting language and clicking the kill button before it finishes. You leak file buffers, you leak stack frames. It's just a big mess and represents bad programming practice. I only said it because it is the only way I can think of doing what you feel you need. However, from my experience, I'd say you probably don't need what you think you need. Step back and take another look at it. There is a better solution there.
If you want to run another thread in VB6 that's independent of your main program, you should write an ActiveX exe file that will take on its own independent thread.
Microsoft in their MSDN documentation recommends using an out of process ActiveX exe.
These aren't really that hard to program. But you might want to go through their examples found in the MSDN CD's or on the archives for MSDN on the internet.
Microsoft in their MSDN documentation recommends using an out of process ActiveX exe.
•
•
•
•
The fact that an out-of-process component runs in its own process means that a client can tell it to do something, and then go about its business while the component does the work. When such a system is properly set up, the component can tell the client when the task is done using an asynchronous notification, as explained in "Asynchronous Call-Backs and Events" in "Building Code Components."
![]() |
Similar Threads
- Installing software on Linux: source code (*nix Software)
- SpeedUp Your Window XP Never Than Before (Windows tips 'n' tweaks)
- MSVC++ Express 8 error C2228 (C++)
- Help With Delphi Petrol Pump Logic. (Pascal and Delphi)
- Program Airline (Pascal and Delphi)
- SATA hard drive not recognized (Storage)
- using ifstream, counting elements of each line in a dat file (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: How to open a Word Document in Read-only mode
- Next Thread: Popup menu icon on left(help ls)
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window





