![]() |
| ||
| Countdown Timer with minutes seconds and milliseconds! hi everybody! im in a basketball team n my coach asked me to make a scoreboard program for the huge screen we have (he knows im the only one from the team that does some programming) im using Visual Basic 2008. i pretty much know how to do everything except for the countdown timer which has to count down all the way from 8 minutes to 0. it would also be nice if it makes a beep when it reaches 0. so here's the problem. i know how to make a simple timer with seconds. but how to put minutes n milliseconds?? it should look like this minutes:seconds:milliseconds someone please help!! im desperate thanks in advance :) :) |
| ||
| Re: Countdown Timer with minutes seconds and milliseconds! Quote:
Even if you convert the Now to a double precision value (which you'll have to use obtain milleseconds), the best you will get is still a change in the visible value every second. So what you need to use is the Windows API 'QueryPerformanceCounter' in your program to obtain a higher precision of accuracy. To find how much precision your CPU will provide you use the 'QueryPerformanceFrequency' API The degree of precision depends on your CPU and how simple you can keep your code. Private Type LARGE_INTEGER I've given you a start. But here's the pseudo logic you'll need: Determine your CPU's capabilities with the QueryPerformanceFrequency Create a loop to provide a value to use for your millisecond display. And you need to provide some method to get yourself out of the loop. I'll leave the rest to you. But that should get you started. Hank |
| ||
| Re: Countdown Timer with minutes seconds and milliseconds! Private Declare Function GetTickCount Lib "kernel32.dll" () As Long This API function Return a time in miliSecond for each time called. you can use it. |
| ||
| Re: Countdown Timer with minutes seconds and milliseconds! Quote:
That could be anywhere from 9 to 100 milliseconds. If the user requires a resolution of 1 millisecond, then you'll have to use the other API's to determine if the running CPU has that capability: hence the necessity of using the QueryPerformanceFrequency and QueryPerformanceCounter APIs. |
| ||
| Re: Countdown Timer with minutes seconds and milliseconds! This code, when the timer property for interval is set at 1 millisecond, should give you resolution of the user's system timer. This came out to be about 15 milliseconds on a 2.4 GHz pentium4 Option Explicit |
| ||
| Re: Countdown Timer with minutes seconds and milliseconds! hi i noticed now that this forum is for vb 6... but thats no problem. i just downloaded n installed that and your code works fine! thanks! one question though... now the count is going up...like its adding time and its starting from a number like 1774796... how can i make it actually count down and start from 8 minutes?? :confused: thanks a lot appreciate your help :) |
| ||
| Re: Countdown Timer with minutes seconds and milliseconds! Quote:
Quote:
|
| ||
| Re: Countdown Timer with minutes seconds and milliseconds! Everything else is just algebra and logic. You need to have one established reference point: That's the value you derive from using the above API's and finding the current time using the Now function. Lets' call that value lngValueA. Save that value and use it as a reference point for your minutes:seconds:milleseconds. Once you have established that reference point. You need to come up with a formula to calculate How many minutes, how many seconds, and how many fractional seconds. This is just basic algebra. |
| ||
| Re: Countdown Timer with minutes seconds and milliseconds! hi i figured out how to do it. i used a different method... i dont think its as accurate as yours, but its not really important... in basketball the milliseconds are just there to look cool lol. anyway thanks for your help:) im using this code right now Option Explicit Dim EndTime As Single Private Sub Form_Load() Timer1.Enabled = False End Sub Private Sub Command1_Click() Timer1.Enabled = Not Timer1.Enabled If Timer1.Enabled = True Then Command1.Caption = "Stop" If Timer1.Enabled = False Then Command1.Caption = "Start" EndTime = (Timer + 8 * 60) Mod 86400 Timer1.Interval = 20 End Sub Private Sub Timer1_Timer() Dim CtDn As Long CtDn = (EndTime - Timer) * 100 If CtDn < 0 Then If CtDn < -1000 Then 'bit of faff to avoid over midnight countdown CtDn = CtDn + 8640000 Else Label1.Caption = "0:00:00" Beep 'or somesuch Timer1.Interval = 0 Exit Sub End If End If Label1.Caption = Format((CtDn \ 6000) Mod 60, "0:") & Format((CtDn \ 100) Mod 60, "00:") & Format(CtDn Mod 100, "00") End Sub |
| ||
| Re: Countdown Timer with minutes seconds and milliseconds! Quote:
|
| All times are GMT -4. The time now is 6:08 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC