Results 1 to 10 of 10

Thread: [RESOLVED] Timers VS DoEvents()

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Resolved [RESOLVED] Timers VS DoEvents()

    can i use the DoEvents() key code line in a Timer(with short interval(100 or less)), without a problem?
    the cicle works normaly or sametimes can be ignored?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Timers VS DoEvents()

    You can run into problems. DoEvents allows re-entrance into code. A short interval like that may not cause problems but you can avoid it...
    Example to prevent timer1 from firing again before it finishes:
    Code:
    Private Sub Timer1_Timer()
    If Timer1.Tag = "" Then
       Timer1.Tag = "no recursion"
       do stuff
       DoEvents
       Timer1.Tag = ""
    End If
    End Sub
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Post Re: Timers VS DoEvents()

    Quote Originally Posted by LaVolpe View Post
    You can run into problems. DoEvents allows re-entrance into code. A short interval like that may not cause problems but you can avoid it...
    Example to prevent timer1 from firing again before it finishes:
    Code:
    Private Sub Timer1_Timer()
    If Timer1.Tag = "" Then
       Timer1.Tag = "no recursion"
       do stuff
       DoEvents
       Timer1.Tag = ""
    End If
    End Sub
    hi LaVolte
    sorry the interval is 10.
    i have like these:
    Code:
    Private Sub Timer1_Timer()
    If something Then
       do stuff
       raiseevent Move
       DoEvents
       do stuff
      raiseevent Collision()  
     'i try use Doevents too
    elseif
     do stuff
     raiseevent someevent
    End If
    End Sub
    [/QUOTE]
    tell me what you think?
    i know that these isn't the real code, but we are speak about timers and Doevents() keyword.
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Timers VS DoEvents()

    Timers are asynchronous. They run in their separate thread. You do not need to call DoEvents inside it because it yields to the system after each cycle by itself.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Timers VS DoEvents()

    You can also use a flag to determine when to continue"
    Do Until mDone = True
    DoEvents
    Loop
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: Timers VS DoEvents()

    then the colision event(i'm speak in new UC), is, always, called without a problem, right?
    but my event isn't always called
    can you tell me more that you know?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Timers VS DoEvents()

    in VB6 timers are not accurate. So it is possible that you won't get the events at exactly 10ms. If you are looking for better accuracy, you may use API timers instead.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  8. #8

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: Timers VS DoEvents()

    Quote Originally Posted by Pradeep1210 View Post
    in VB6 timers are not accurate. So it is possible that you won't get the events at exactly 10ms. If you are looking for better accuracy, you may use API timers instead.
    i don't know use the API timers
    (note: you can see the problem here: http://www.vbforums.com/showpost.php...28&postcount=4. download the project and change the FileName property. then move RUN it and move the sonic by walls. you well see that not everytime that tatch the wall he do what must do)
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  9. #9
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Timers VS DoEvents()

    I don't have VB6 on this machine. So I won't be able to have a look at it.
    But just search this forum; you would find many examples of timers using API.
    Last edited by Pradeep1210; Oct 9th, 2009 at 05:54 PM.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  10. #10

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: Timers VS DoEvents()

    Quote Originally Posted by Pradeep1210 View Post
    I don't have V6 on this machine. So I won't be able to have a look at it.
    But just search this forum; you would find many examples of timers using API.
    ok.. thanks
    but i woud like that someone test it and tell me something
    please someone...
    VB6 2D Sprite control

    To live is difficult, but we do it.

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