-
Feb 4th, 2013, 12:06 AM
#1
Thread Starter
Registered User
-
Feb 5th, 2013, 03:01 AM
#2
Re: how to display count up timer in database field
This is just a slight improvement of your code, there are much better solutions around:
Code:
Private Sub Form_Load()
Timer1 = False
CmdStop.Enabled = False
ListView1.ListItems.Add 1, , "00:00:00"
End Sub
Private Sub Timer1_Timer()
Xsecond = Format$(CLng(Xsecond) + 1&, "00")
If Xsecond = "60" Then
Xsecond = "00"
xminute = Format$(CLng(xminute) + 1&, "00")
End If
If xminute = "60" Then
xminute = "00"
xmenit = Format$(CLng(xmenit) + 1&, "00")
End If
ListView1.ListItems(1).Text = xmenit & ":" & xminute & ":" & Xsecond
End Sub
BTW, rather than posting a screenshot of your code, paste it instead and surround it with Code tags ( [CODE]your code here[/CODE] ).
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Feb 5th, 2013, 09:26 AM
#3
Re: how to display count up timer in database field
Here is another approach using DateAdd/Format functions:
Code:
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = False
lblHours.Caption = "00"
lblMinutes.Caption = "00"
lblSeconds.Caption = "00"
End Sub
Private Sub Timer1_Timer()
Dim dtTime As Date
dtTime = DateAdd("s", 1, CDate(Date & Space(1) & _
lblHours.Caption & ":" & _
lblMinutes.Caption & ":" & _
lblSeconds.Caption))
lblHours.Caption = Format(dtTime, "HH")
lblMinutes.Caption = Format(dtTime, "NN")
lblSeconds.Caption = Format(dtTime, "SS")
End Sub
Private Sub btnStart_Click()
Timer1.Enabled = True
End Sub
Private Sub btnStop_Click()
Timer1.Enabled = False
End Sub
Note: this is a very quick sample so you may need to modify it to fit your app. I would also add Restore button that will reset all labels to "00".
Last edited by RhinoBull; Feb 9th, 2013 at 08:31 AM.
-
Feb 5th, 2013, 10:15 AM
#4
Re: how to display count up timer in database field
You should keep in mind that using a timer in such a way will not be 100% accurate. If you want a true counter then rather than adding 1 second each time the timer tick fires you should compare the system time with the time the counter was started.
if the timer is set to 1000 then it will be pretty close just using a counter but if it runs for very long it will start to fall behind and if there are other things going on in your app that consume CPU then it could fall way behind after a while. Using the system clock the worst that can happen is that the display does not update every second but it will not actually fall behind. If for some reason the timer is unable to fire for 3 seconds then when it does the seconds will go up by 3 rather than 1 keeping the time accurate.
-
Feb 5th, 2013, 10:28 AM
#5
Re: how to display count up timer in database field
Unless OP needs to build time sensitive scientific app ordinary timer should not be an issue.
-
Feb 9th, 2013, 12:22 AM
#6
Thread Starter
Registered User
Re: how to display count up timer in database field
Wow thanks, the code that BonnieWest and RhinoBull gave to me, it works perfectly.
I'll keep in mind not to post code in screenshot again.
But I am still confused how to program the timer according to the system time as DataMises said.
Even so the problem is solved, thanks again, you guys awesome.
-
Feb 9th, 2013, 11:24 AM
#7
Re: how to display count up timer in database field
To use system time instead of simply adding 1 each time the timer fires you would check the clock.
When you first start you would grab the value from the clock and store it in a variable. You could do this with the Now() function
When the timer fires you can use DateDiff() to check the number of seconds difference between the stored date/time and the current value of Now().
This would be important if you program was running some process that could take a few seconds to complete because the timer will not be adding while that prcess is running so when the timer fires using method 1 it will add 1 even if 5 seconds have passed where the clock method would add 5 in this scenario.
-
Feb 10th, 2013, 01:28 AM
#8
PowerPoster
Re: how to display count up timer in database field
To display a counter either going up or down, you can use a TextBox or a LabelControl to do the displaying of the data. But remember if you want it to count up use the plus key and then to go down use the minus key, for that to happen...
I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...
|Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Event's Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Bar | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University |
Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|