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

Thread: Special timer

  1. #1
    Join Date
    May 2001
    Posts
    23

    Special timer

    Hay i need to make an timer in Vb .I know now u guys will say there area lots of timer on this site.but the problem is i need timer to return me value in h:m:s just like normal watch.In short I need make an watch but I can control this watch make it start from 0:0:0



  2. #2
    Join Date
    Apr 2000
    Posts
    737

    Re: Special timer

    use a variable to keep track of the timer. like this :

    dim l as long


    set the timer interval to 1 second and in the timer function, put this.

    l = l + 1

    put a button to form and in the click event, set l = 0.

    then l will always contains the time after u click the button, you can get the hour, min, and sec as below

    second = l mod 60
    minute = (l \ 60) mod 60
    hour = l mod 3600

    HTH

    cksiow
    http://vblib.virtualave.net - share our codes


  3. #3
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Special timer

    You can use the gettickcount API.

    Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () as Long

    Dim lStart as long

    private Sub Command1_Click()
    lStart = GetTickCount()
    Timer1.Enabled = true
    End Sub
    private Sub Timer1_Timer()
    dim lNow as lomg, lElapsed as Long
    dim ShowTime as string, ShowHrs as Long, ShowMin as Long, ShowSec as Long
    lNow = GetTickCount
    ' get ti;e elapsed in seconds
    lElapsed = (lNow - lStart) / 1000
    ' hours
    ShowHrs = int(lElapesed / 3600)
    lElapsed = lElapsed - (ShowHrs * 3600)
    ' minutes
    ShowMin = int(lElapesed / 60)
    lElapsed = lElapsed - (ShowMin * 60)
    ' seconds
    ShowSec = lElapsed
    Label1.Caption = ShowHrs & ":" & ShowMin & ":" & ShowSec
    End Sub





    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  4. #4
    Join Date
    May 2001
    Posts
    23

    Re: Special timer

    thank for it but when I start the timmer it start from 24:2:00 some thing like this I want it to be start from 0:0:00


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