CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: timer question

  1. #1
    Join Date
    May 2001
    Location
    Australia
    Posts
    1

    timer question

    I am trying to creat a stop watch using three labels and three timers (minutes, seconds and tenths of a second). So far I have the tenths of a second working with this:
    lblTSec.Caption = lblTSec.Caption + 1
    how do I make it start at zero again once it reaches 59 and what speed do I set the timers at for minutes and seconds?


  2. #2
    Join Date
    Apr 2001
    Posts
    95

    Re: timer question

    The Interval property of a timer is measured in miliseconds... therefore a tenth of a second is 10... a second is 1000 and one minute is 60000.

    To reset the lbl to 0 do this:


    If CInt(lblTSec.Caption) = 59 then
    lblTSec.Caption = "0"
    end if





    You can do it with one timer like this:



    private Sub tmrClock_Timer()
    Dim nSec as Integer
    Dim nTSec as Integer
    Dim nMin as Integer

    nTSec = CInt(lblTSec.Caption)
    nSec = CInt(lblSec.Caption)
    nMin = CInt(lblMin.Caption)

    nTSec = nTSec + 1

    If nTSec = 100 then
    nTSec = 0
    nSec = nSec + 1
    End If

    If nSec = 60 then
    nSec = 0
    nMin = nMin + 1
    End If

    lblTSec.Caption = CStr(nTSec)
    lblSec.Caption = CStr(nSec)
    lblMin.Caption = CStr(nMin)
    End Sub





    Hope this helps.


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

Featured