Results 1 to 20 of 244

Thread: Bet Angel and Excel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,709
    Location
    I think there's something wrong with your logic...

    You want to run a sub 50 times a second (20 ms) but that sub may take longer than 20 ms itself. In any case (Even at 5 times a second (200 ms),) the code takes some varying amount of time.

    I would set a variable to NOW, call the main sub, and at its end, call the timer sub, which would re-call the main sub 200 ms after the variable, or immediately if 200 ms has already passed. Windows Excel can measure 0.2 seconds accurately down to 5 or so decimal places.

    Something like this
    Dim StartTime As Double
    
    Sub Delay
        'Maybe use Microtimer for "Now"
        Do While Now < starttime + 2.31481E-06 '1/5 second according to Excel
        Loop
        StartTime = Now 
        Call MainSub
    End Sub
    
    MainSub
        'Blah
        'Blah
        'Blah
        Sub Delay
    End sub
    Last edited by Aussiebear; 12-31-2024 at 01:20 PM.
    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

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