home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.visual.basic      MS Visual Basic discussions, NOT dot-net      10,840 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 9,513 of 10,840   
   Steve Gerrard to William Bub   
   Re: Timer Control   
   17 May 05 18:46:28   
   
   From: mynamehere@comcast.net   
      
   "William Bub"  wrote in message   
   news:P7Uhe.35683$ia6.31372@twister.nyroc.rr.com...   
      
   > Is there an accurate way to create a "stopwatch" good to 1/10 of a second?   
      
   The basic idea for all timing is to use a timer to cause events to occur, but   
   to   
   read a clock to get the elapsed time.The example below uses a timer called   
   Timer1, and also calls the Timer() function, so don't confuse the two. The   
   Timer() call returns elapsed seconds, and is good to between 5 and 50 msecs,   
   depending on the OS.   
      
   You can also use the API call GetTickCount, or even QueryPerformanceCounter for   
   very precise timings.   
      
   Option Explicit   
      
   Private mStart As Single   
      
   Private Sub Form_Load()   
       Timer1.Enabled = False   
       ' interval smaller than desired resolution   
       Timer1.Interval = 20   
   End Sub   
      
   Private Sub Command1_Click()   
       If Timer1.Enabled Then   
           Timer1.Enabled = False   
           Me.Caption = Format(Timer() - mStart, "0.0")   
       Else   
           Timer1.Enabled = True   
           mStart = Timer()   
       End If   
   End Sub   
      
   Private Sub Timer1_Timer()   
       Me.Caption = Format(Timer() - mStart, "0.0")   
   End Sub   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca