|
-
Dec 26th, 2007, 11:43 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Basketball Sports ClockI
I'm working on an application that needs a counting down start stop clock, ability to be set to a specified time such as 20 minutes. I can prob figure out the code to that.
It does not have to be uberly time accurate, however, if possible, the ability to show the clock the clocks precision to a tenth of a second when under 1 minute.
so 59.9, 1.7, etc.
I searched some code on here, the code count downs accurately for a while, but I think the translation to format the clock is wrong, it counts down to random times.
Any idea's help, code?
-
Dec 26th, 2007, 11:52 AM
#2
Re: Basketball Sports ClockI
Post the code you have so far. You sould be using a timer control set at an Interval of 100.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 26th, 2007, 01:42 PM
#3
Thread Starter
Addicted Member
Re: Basketball Sports ClockI
This is what I'm currently using.
Code:
Private Sub timeClock_Timer()
Dim lTemp As Long
Dim lTemp2 As Long
intCounter = intCounter - 1000
lTemp = intCounter
lTemp = lTemp / 1000 'convert to seconds
lTemp2 = lTemp
lTemp = (lTemp / 60) Mod 60 'Minutes
lTemp2 = (lTemp2 Mod 60) 'Seconds
If lTemp2 < 10 Then
lblTime.Caption = lTemp & ":0" & lTemp2
Else
lblTime.Caption = lTemp & ":" & lTemp2
End If
If intCounter = 0 Then
timeClock.Enabled = False
MsgBox "Times up"
End If
End Sub
I'm using a basic enable/disable. I know from what I currently have the tenth of a second resolution is not going to work.
-
Dec 26th, 2007, 02:01 PM
#4
Re: Basketball Sports ClockI
Here is a quick example of a count down timer. Format for time/seconds or whatever and your good to go.
Code:
Option Explicit
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Static l As Long
l = l + 100
If 6000 - l <= 0 Then Timer1.Enabled = False
Me.Caption = 6000 - l
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 26th, 2007, 02:31 PM
#5
Thread Starter
Addicted Member
Re: Basketball Sports ClockI
is my minute second code above flawed then?
How can I get the tenth second precision as seen on TV?
-
Dec 26th, 2007, 02:39 PM
#6
Re: Basketball Sports ClockI
No, its fine I think. I was just too lazy to add all the extras in
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 26th, 2007, 03:10 PM
#7
Re: Basketball Sports ClockI
Here's a slightly different approach:
Code:
Dim StartTime As Long, Mincount As Integer
Dim Minutes As String, Seconds As String
Const GameLength = 1200 ' Playing Time in Seconds
Private Sub Form_Load()
StartTime = Timer
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
If (Timer - StartTime) / (Mincount + 1) > 60 Then Mincount = Mincount + 1
Seconds = Format$(60 * (Mincount + 1) - (Timer - StartTime), "00")
If Seconds = "60" Then Seconds = "00"
If GameLength - (Timer - StartTime) > 60 Then
Minutes = Format$((GameLength - (Timer - StartTime)) \ 60, "00:")
Label1.Caption = Minutes & Seconds
ElseIf GameLength - (Timer - StartTime) > 0 Then
Label1.Caption = Format$(60 * (Mincount + 1) - (Timer - StartTime), "00:00.0")
Else: Label1.Caption = "Game Over!"
End If
End Sub
I am sure you could simplify it a little, but it works. Be sure you set the game length at 120 seconds (two minutes) or longer to get an accurate initial clock reading. It switches over to split the second into tenths when one minute or less remains on the clock.
-
Dec 27th, 2007, 10:13 AM
#8
Re: [RESOLVED] Basketball Sports ClockI
I realize that the post is marked resolved, but here is yet another approach using two timer controls: one for the first 19 minutes and the other for splitting the second when only one minute remains:
Code:
Dim StartTime As Double, StartSecond As Long
Const GameLength = 20 ' Length of basketball game in minutes
Private Sub Form_Load()
Timer1.Interval = 100
Timer2.Interval = 100
Timer2.Enabled = False
StartTime = Now
End Sub
Private Sub Timer1_Timer()
If GameLength - 1440 * (Now - StartTime) > 1 Then
Label1.Caption = "Time Remaining: " & Format$(GameLength / 1440 - (Now - StartTime), "h:mm:ss")
Else: Timer1.Enabled = False
Timer2.Enabled = True
StartSecond = Timer
End If
End Sub
Private Sub Timer2_Timer()
If Timer - StartSecond < 60 Then
Label1.Caption = "Time Remaining: " & Format$(60 - (Timer - StartSecond), "00:00.0")
Else: Label1.Caption = "Game Over!"
End If
End Sub
Note that the seconds clock kicks in and uses the Timer function for splitting seconds. The first clock uses Now rather than Timer. So, there is less chance that the clock would have trouble near midnight when Timer is invoked. Good Luck, DJ!
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
|