Results 1 to 4 of 4

Thread: Subroutines multitasking?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350
    Take look at this code:

    Code:
      Sub Misc1()
       For i = 1 to 10
        Call Misc2 (i)
       Next i
      End Sub
    
    
     Sub Misc2(Num)
      Do ...
       ...
       Doevents
      Loop
     End Sub
    When I call Misc2 with parametr i, the Do..Loop cycle is started and the Next i clause is called after exiting Misc2.

    How to force the program to call Misc2 and continue doing what it should do (not waiting to subroutine end)?

  2. #2
    Lively Member
    Join Date
    Jul 1999
    Posts
    99
    try inserting DoEvents in Misc1's For Next loop.

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    That won't work -- the problem is that your program has only one thread.

    In a thread, only one thing happens at once, so execution of your program passes from one sub to another, completing everything on the way.

    In order to do what you want you need to create another thread, but it's very iffy in VB. However, you can just-about simulate it by using an ActiveX DLL that's external to your program.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    Do it like this.....

    Code:
    Sub Misc1()
      For i = 1 to 10
         Call Misc2 (i)
      Next i
    End Sub
    
    
    Sub Misc2(Num)
      Do
        DoEvents
      Loop Until DoEvents
    End Sub
    DocZaf
    {;->

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