Results 1 to 5 of 5

Thread: testing time delay

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    testing time delay

    i would appreciate if anyone can see any possible cases where this routine could fail or error
    or other possible improvements

    the idea is to limit the maximum number if iterations (user set maxe) per hour, the test below i have changed to minutes, for testing purposes,
    vb Code:
    1. Sub test()
    2. Dim strtime As Date, e As Long, maxe As Long
    3. strtime = Now
    4. maxe = 850
    5.         For e = 1 To 100000
    6.  
    7.                             If e Mod maxe = 1 And Not e = 1 Then
    8. '                                .Disconnect
    9.                                 Do Until DateDiff("s", strtime, Now) > (e \ maxe) * 60
    10.                                     DoEvents
    11.                                     Sleep 3000
    12.                                 Loop
    13. '                                .Connect
    14.                                 Debug.Print Now
    15.                             End If
    16.         Next
    17.  
    18. End Sub
    within the application, this is actually in a do loop, e = e +1, with unknown maximum, but i would expect to always be less than 100000
    the computer is unlikely to be used for other purposes while this routine is running
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: testing time delay

    The only thing I can think of is what happens if the system is running when Daylight Saving starts or stops and the system clock goes forwards or backwards by an hour ? (or some intrepid user decides to change the clock whilst the process is running)

    Apart from that, I assume you're aware of the 'limtations' of the Sleep Function (http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx)

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: testing time delay

    yeah daylight saving changes could be an issue as the program is left running overnight, i will have to sort something on that (maybe "do not use" those 2 days of the year)

    precise start time is not relevant as long as it is greater than one hour from previous start, it is possible sometimes that it will take more than one hour for max number of iterations, processing time can vary considerably, depending on user options and other outside factors, which reminds me of some other not handled error possibility
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: testing time delay

    One other thought; I'm not sure whether the DoEvents is a good idea.

    I don't know too much about the Sleep API but I'm guessing that when the time has expired and the thread is schedulable again, any outstanding events will be serviced, which would do away with the need for DoEvents.

    Depending on user interaction and the design of your application, there may be a chance of some non-reenterable code being re-entered as a result of a call to DoEvents, which may cause problems. (eg the user idly clicking on some button or other) Such risks can be mitigated against by disabling buttons etc once the user has started the process running.

    The 'Daylight Saving' note was a bit tongue-in-cheek, but since you are not using the absolute values of Date and Time, and are only interested in relative time, you could, perhaps, use the QueryPerformanceFrequency and QueryPerformanceCounter APIs instead of 'Now', which would make it independent of System Date / Time.

    Then there's the obvious things, like validating all User input etc.... but I'm sure I don't have to mention that

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: testing time delay

    most of the input has been in use for some time, so should be ok, just a few modifications, which i am sure are likely to come back and haunt me, despite trying to make sure none of the additions will cause problems with the existing code, and being unable to test large parts of it on my system, does not help
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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