Results 1 to 8 of 8

Thread: [RESOLVED] Interrupt a Function

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Resolved [RESOLVED] Interrupt a Function

    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

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Interrupt a Function

    Nope. Application code runs in a single thread; no two functions will execute concurrently.

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Interrupt a Function

    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.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Re: Interrupt a Function

    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?

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Interrupt a 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.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Re: Interrupt a Function

    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.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: [RESOLVED] Interrupt a Function

    Stop is a reserved word - use something else or you'll get compile errors.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Re: [RESOLVED] Interrupt a Function

    Yeah, I didn't use that exact code, anyway. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width