+ Reply to Thread
Results 1 to 8 of 8

Running multiple timers

Hybrid View

  1. #1
    Registered User
    Join Date
    09-17-2006
    Posts
    4

    Running multiple timers

    I made timer program that has 3 timers, one that runs from start to stop and two other that can be stopped and continued. Now my problem is how I get all three timers running at same time.
    Here's excel file so its easier to explore it: Combat%20laskuri.xls

    Private Declare Function timeGetTime Lib "winmm.dll" () As Long
    Dim aikanyt, aikanyt1, aikanyt2
    Dim aikasit, aikasit1, aikasit2
    Dim seis, seis1, seis2
    Dim aika, aika1, aika2
    
    '---------------------Clock 1 begins---------------------------------'
    Public Sub sekkari()
    seis = False
    Do While seis = False
    DoEvents
     aikasit = timeGetTime()
     aika = ((aikasit - aikanyt) / 1000)
     Worksheets("Sheet1").Range("D6").Value = (aika)
    Loop
    End Sub
    
    Private Sub CommandButton1_Click()
      aikanyt = timeGetTime()
      sekkari
    End Sub
    
    Private Sub CommandButton2_Click()
      seis = True
      
      'Pysäytetään ajanotto 1
      Worksheets("Sheet2").Range("A1").Value = aika1
      Worksheets("Sheet1").Range("D12").Value = aika1
      seis1 = True
      
      'Pysäytetään ajanotto 2
      Worksheets("Sheet2").Range("A2").Value = aika2
      Worksheets("Sheet1").Range("D23").Value = aika2
      seis2 = True
    End Sub
    '---------------------clock 1 ends---------------------------------'
    
    '---------------------clock 2 begins---------------------------------'
    
    Public Sub sekkari1()
    seis1 = False
    Do While seis1 = False
    DoEvents
    If seis1 = True Then GoTo Here:
     aikasit1 = timeGetTime()
     aika1 = ((aikasit1 - aikanyt1) / 1000) + (Worksheets("Sheet2").Range("A1").Value)
     Worksheets("Sheet1").Range("D12").Value = aika1
     Worksheets("Sheet1").Range("D15").Value = (Worksheets("Sheet1").Range("D6").Value) - (Worksheets("Sheet1").Range("D12").Value)
    Here:
    Loop
    End Sub
    
    Private Sub CommandButton3_Click()
      aikanyt1 = timeGetTime()
      sekkari1
    End Sub
    
    Private Sub CommandButton4_Click()
      Worksheets("Sheet2").Range("A1").Value = aika1
      Worksheets("Sheet1").Range("D12").Value = aika1
      seis1 = True
    End Sub
    
    Private Sub CommandButton5_Click()
      Worksheets("Sheet2").Range("A1").Value = 0
      Worksheets("Sheet1").Range("D12").Value = 0
      Worksheets("Sheet1").Range("D18").Value = 0
    End Sub
    
    Private Sub CommandButton6_Click()
      Dim katkot1
      katkot1 = Worksheets("Sheet1").Range("D18").Value
      Worksheets("Sheet1").Range("D18").Value = katkot1 + 1
    End Sub
    '---------------------clock 2 ends---------------------------------'
    
    '---------------------clock 3 begins---------------------------------'
    
    Public Sub sekkari2()
    seis2 = False
    Do While seis2 = False
    DoEvents
    If seis2 = True Then GoTo Here:
     aikasit2 = timeGetTime()
     aika2 = ((aikasit2 - aikanyt2) / 1000) + (Worksheets("Sheet2").Range("A2").Value)
     Worksheets("Sheet1").Range("D23").Value = aika2
     Worksheets("Sheet1").Range("D26").Value = (Worksheets("Sheet1").Range("D6").Value) - (Worksheets("Sheet1").Range("D23").Value)
    Here:
    Loop
    End Sub
    
    Private Sub CommandButton7_Click()
      aikanyt2 = timeGetTime()
      sekkari2
    End Sub
    
    Private Sub CommandButton8_Click()
      Worksheets("Sheet2").Range("A2").Value = aika2
      Worksheets("Sheet1").Range("D23").Value = aika2
      seis2 = True
    End Sub
    
    Private Sub CommandButton9_Click()
      Worksheets("Sheet2").Range("A2").Value = 0
      Worksheets("Sheet1").Range("D23").Value = 0
      Worksheets("Sheet1").Range("D29").Value = 0
    End Sub
    
    Private Sub CommandButton10_Click()
      Dim katkot2
      katkot2 = Worksheets("Sheet1").Range("D29").Value
      Worksheets("Sheet1").Range("D29").Value = katkot2 + 1
    End Sub
    '---------------------clock 3 ends---------------------------------'
    Last edited by tropy; 09-17-2006 at 07:52 AM.

  2. #2
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    This might help:
    http://www.xl-logic.com/xl_files/vba/active_clock.zip

    Col
    If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime.

  3. #3
    Registered User
    Join Date
    09-17-2006
    Posts
    4
    Looks good, but it doesnt works, least not in my computer, there's error in line marked with yellow
    Sub Click_StopWatch()
        Dim x As Double
        x = Now
        With ActiveCell
            If .HasFormula Then
                .Value = .Value
                .Interior.ColorIndex = 38 'lt red
            Else
                .Formula = "=Time-" & x
                .NumberFormat = "hh:mm:ss"
                .Interior.ColorIndex = 35 'lt green
            End If
        End With
        Call SetTime
    End Sub

  4. #4
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    What's the error?

  5. #5
    Registered User
    Join Date
    09-17-2006
    Posts
    4
    Runtime error 1004
    Application-defined or object-defined error

  6. #6
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    Hmm. It works fine for me opened from the zip file. Unless you're doing something else (?) I have no idea what's causing that. Sorry!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1