Results 1 to 4 of 4

Thread: Up timer

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509

    Up timer

    I am trying to create an up timer in the format of HH:MM:SS. I know how to do this in vb.net. I tried to use the same method for vb6 but it doesn't have a variable Date.

    This is how to do it in vb.net, does someone know how to do it in vb6?

    Code:
    Public Class Form1
        Inherits System.Windows.Forms.Form
    
        Dim startTime As New Date
        Dim elapsedTime As TimeSpan
    
    ' Windows Form Designer generated code goes here
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Timer1.Enabled Then
                Timer1.Enabled = False
            Else
                startTime = Now
                Timer1.Enabled = True
            End If
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            elapsedTime = New TimeSpan(Now.Ticks - startTime.Ticks)
            TextBox1.Text = elapsedTime.ToString.Substring(0, 8)
        End Sub
    End Class

  2. #2
    Lively Member
    Join Date
    Aug 2003
    Location
    Philadelphia, Pa.
    Posts
    123
    In your timer code...


    Code:
    
    TextBox1.Text = Format(Now, "HH:MM:SS AMPM")

    the ampm part is optional

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509
    i know what u mean, but that takes the system time. Thats not what i wanted.
    i wanted a timer to start from 00:00:00 in the format of HH:MM:SS and count up.

  4. #4
    Lively Member
    Join Date
    Aug 2003
    Location
    Philadelphia, Pa.
    Posts
    123
    I dont know why they moved your question, it is about vb6.

    Try this under timer...

    Code:
    Static x As Long
    Static H, M As Long
    
        If IsNull(H) Then H = 0
        If IsNull(M) Then M = 0
        
        x = x + 1
        
        If x = 60 Then
            
        
            x = 0
            M = M + 1
            
            If M = 60 Then
                M = 0
                H = H + 1
            End If
            
        End If
        
        Label1.Caption = Format(H, "00") & ":" & Format(M, "00") & ":" & Format(x, "00")
    It works with a minor bug the first time through, you will figure it out I am sure.

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