Results 1 to 4 of 4

Thread: Help with Delays!

  1. #1
    Guest
    In my program I have some calls that when I put message box between them (i was just debugging) it works fine. Without the message box it screws up. I tried using a Delay instead the code for my delay is

    Code:
    Private Sub Delay(ByVal pt As Integer)
    Dim pausetime, Start
        
        pausetime = pt   ' Set duration.
        Start = Timer   ' Set start time.
        Do While Timer < Start + pausetime
           
            DoEvents   ' Yield to other processes.
        Loop
    End Sub
    However, this doesn't solve the problem. I've even tried setting the integer value for the delay to a longer time, but that doesn't help either. How can I affect the program the way the message box does so the I can be sure my program works correctly?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    First timer is very inaccurate, up to 53 ms, so use gettickcount api that is accurate up to 1 ms. Secondly pt is a integer, which causes you can only specify seconds. Pass pt as a long specifying amount of milliseconds instead of seconds:
    Code:
    Declare Function GetTickCount Lib "kernel32" () As Long
    
    Sub Delay(ByVal pt As Long)
        Dim t As Long
        t = GetTickCount + pt
        Do
            DoEvents
        Loop Until t < GetTickCount
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Don't put the DoEvent's in there, DoEvent's only concern's your app, Other applications will get proccessor Time Even if you put Your Code in a loop Without DoEvents

  4. #4
    Guest
    Will the looping even allow other parts of the program to process? I thought DoEvents allowed the events to finish processing before beginning the next step. They've served to help me prevent a call to an object before another event was finished with it.

    Does affecting the time even help?


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