A question about time (easy)

Ok, I've been trying to display the time in real time (meaning it is actively counting the seconds, minutes, hours just like the clock in the systray in windows). I want to put this in a label on my form. I know it's got to be some easy piece of code that I'm just overlooking. I've tried using the Time() function but that basically only puts a 'snapshot' of the time when the program is executed. Any help is greatly appreciated.
Dan.


Comments

  • : Ok, I've been trying to display the time in real time (meaning it is actively counting the seconds, minutes, hours just like the clock in the systray in windows). I want to put this in a label on my form. I know it's got to be some easy piece of code that I'm just overlooking. I've tried using the Time() function but that basically only puts a 'snapshot' of the time when the program is executed. Any help is greatly appreciated.
    : Dan.
    :
    --------------
    hi dan,

    u can do this easily using a Timer control.

    Put the following on a new form:
    - A timer control (Name: Timer1)
    - A textbox (Name: Text1)

    Put the following code in the respective events:

    Dim hrs, mins, secs As Integer

    Private Sub Form_Load()
    Text1.Text = Format(Time, "hh:mm:ss") // setting default time
    Timer1.Interval = 1000 // activates every second
    Timer1.Enabled = True // duh!
    End Sub

    Private Sub Timer1_Timer()
    hrs = Hour(Text1.Text)
    mins = Minute(Text1.Text)
    secs = Second(Text1.Text)

    If secs = 59 Then
    secs = 0
    If mins = 59 Then
    mins = 0
    If hrs = 23 Then
    hrs = 0
    Else
    hrs = hrs + 1
    End If
    Else
    mins = mins + 1
    End If
    Else
    secs = secs + 1
    End If

    Text1.Text = Format(hrs & ":" & mins & ":" & secs, "hh:mm:ss")
    End Sub


    -thats all there is to it






  • : : Ok, I've been trying to display the time in real time (meaning it is actively counting the seconds, minutes, hours just like the clock in the systray in windows). I want to put this in a label on my form. I know it's got to be some easy piece of code that I'm just overlooking. I've tried using the Time() function but that basically only puts a 'snapshot' of the time when the program is executed. Any help is greatly appreciated.
    : : Dan.
    : :
    : --------------

    actually a much easier way would be to call the Time function within a timer control....

    set the interval of the timer control to 1000. (every second)

    in its event, type the following:

    Private Sub Timer1_Timer()
    label1.caption=time
    end sub

    thats it!





  • Create a timer (timer1)
    and a label (label1)

    form load()
    label1.caption = ""
    timer1.enabled = true
    timer1.interval = 1 'not 1000, this will make it more accurate and in real time

    end sub

    private sub timer1()
    label1.caption = cstr(time) 'same applies to getting the date, simply replace (time) with (date)
    end sub

    Don't do thing's the hard way, it just create's more resource eating programs.
    Alway's find the easy way =)


    URL:http://www.angelfire.com/nc/gimpdafied

  • Gimpdafied - that's EXACTLY what I was looking for!
    Thanks, and Happy New Year!
    Dan


    URL:http://www3.sympatico.ca/dgrasley

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories