How can I stop another function in the middle no matter which line it's at? Can I use something like Exit Sub or Exit Function on another function? Thanks
Printable View
How can I stop another function in the middle no matter which line it's at? Can I use something like Exit Sub or Exit Function on another function? Thanks
Nope. Application code runs in a single thread; no two functions will execute concurrently.
You can only do that by making a global boolean variable that when set to True causes all functions to halt. Of course, functions must have a check for that global variable, preferably at every long lasting loop.
Okay, so the only "real" way is to run a multithreaded application? I've heard that it's possible to create a multithreaded VB application but it would be very unstable. Why is that?
So, the best way to solve my problem would be to put something like:
If Stop = True Then Exit Function
after each line in the function?
You can't create truely multithreaded applications in VB because of the thread-local storage used by the COM. Because application code executes in a single thread you won't run into the situation where you would need to stop another method mid-execution.
If you describe your problem in more detail and give an example of where you think this is required then we can suggest an appropriate solution.
Oh, never mind. Actually, I will use something like:
If Stop = True Then Exit Function
but I just looked at the code and I won't need to put it after EVERY line. It would just be a couple of lines.
Stop is a reserved word - use something else or you'll get compile errors.
Yeah, I didn't use that exact code, anyway. Thanks