hey.. again i wud like to ask for ur help..
im a really newbie to vb6 n a really stupid one..
so.. my teacher want me to test the time on how long does da program save the file to database..
so i have to put timer.. on save capture form,
it has to start from 00:00:00:00 (hr:min:seconds:millisnds) or just min:seconds:millis
so when i click save command button it starts counting and if the file has been saved on da database da timer stops counting, n i can see how long does it takes to save a file to database.. on a label..

i found some articles(on here).. but cant seem to edit it the way i want.. (im sorry for da stupidness)
here is one article i found
http://www.daniweb.com/techtalkforums/thread17352.html
most of it are countdowns and print current time, what i need is start from zero.. 00:00:00:00

can anyone help me?im not good in editing code or anything..
i mean really help me, like in dat forum.. helping me with the code..
thanks aaaaaaaaaaaa lottttttttt
help me.. :sad: :sad: :sad: :sad:

Dani AI

Generated

A compact, reliable VB6 approach is to measure real elapsed milliseconds from the system clock (GetTickCount) and use a single Timer only to refresh the display. This gives an accurate elapsed value (hh:mm:ss:ms) without juggling three separate timers. For this fits the request to "start from 00:00:00:000 on Save" and is simpler than the multi-timer method suggested by ; it also uses a Timer like mentioned, but only as a visual refresher.

Private Declare Function GetTickCount Lib "kernel32" () As Long

Private startTick As Long

Private Sub Form_Load()
    Label1.Caption = "00:00:00:000"
    Timer1.Interval = 100   ' refresh every 100 ms (adjust as needed)
    Timer1.Enabled = False
End Sub

Private Sub cmdSave_Click()
    startTick = GetTickCount()
    Timer1.Enabled = True

    ' --- perform your synchronous save here ---
    Call SaveRecordToDB      ' replace with your save routine
    ' -------------------------------------------

    Timer1.Enabled = False
    Label1.Caption = FormatElapsed(GetTickCount() - startTick)
End Sub

Private Sub Timer1_Timer()
    Label1.Caption = FormatElapsed(GetTickCount() - startTick)
End Sub

Private Function FormatElapsed(msTotal As Long) As String
    Dim ms As Long, s As Long, m As Long, h As Long
    ms = msTotal Mod 1000
    s = (msTotal \ 1000) Mod 60
    m = (msTotal \ 60000) Mod 60
    h = (msTotal \ 3600000)
    FormatElapsed = Right$("0" & CStr(h), 2) & ":" & Right$("0" & CStr(m), 2) & ":" & Right$("0" & CStr(s), 2) & ":" & Right$("000" & CStr(ms), 3)
End Function

Notes and troubleshooting:

  • If the save routine blocks the UI thread, the Timer won't visibly update while the save runs, but the final elapsed computed from GetTickCount is accurate. To get live updates during a long save, either break the work into chunks and call DoEvents occasionally or perform the save asynchronously/backgrounded.
  • Timer resolution depends on the OS (practical refresh ~10–20 ms). GetTickCount is good for millisecond-level measurements for short tests. It wraps after ~49.7 days; for extreme precision use QueryPerformanceCounter.

Recommended Answers

All 5 Replies

keep separate timers for seconds, minutes and hours.

or try this in vb.net

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = Convert.ToString(DateTime.Now.Hour) + ":" + Convert.ToString(DateTime.Now.Minute) + ":" + Convert.ToString(DateTime.Now.Second)
End Sub

or try this in vb.net

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = Convert.ToString(DateTime.Now.Hour) + ":" + Convert.ToString(DateTime.Now.Minute) + ":" + Convert.ToString(DateTime.Now.Second)
End Sub

but im using vb 6..
i duno how .net works..

try this code pls

Dim hr%, m%, s%
Private Sub Form_Load()
hr = 0
m = 0
s = 0
End Sub

Private Sub hour_Timer()
hr = hr + 1
End Sub

Private Sub min_Timer()
m = m + 1
End Sub

Private Sub sec_Timer()
s = s + 1
Label1.ForeColor = RGB(hr, m, s)
Label1.Caption = hr & ":" & m & ":" & s

End Sub

Adjust the intervals of timers as per ur wish

use the timer function
or use a timer control

either works great.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.