Results 1 to 8 of 8

Thread: [RESOLVED] Basketball Sports ClockI

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Resolved [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?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    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.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: Basketball Sports ClockI

    is my minute second code above flawed then?

    How can I get the tenth second precision as seen on TV?

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  7. #7
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    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.
    Doctor Ed

  8. #8
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    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!
    Doctor Ed

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