From: Matt Williamson on 11 Sep 2009 16:59 I need a simple little stopwatch program to account for some project time. I've come up with some code but can't figure out how to get it to pause and continue from the point that I left off. Maybe there is a better way to do this but this is what I came up with in the last 10 minutes. Everything seems to work well except it keeps going when it's paused and I start it again instead of continuing from the point that I paused it from. I'm pretty sure it the m_dStart = DateAdd("s", m_TimePassed, m_dStart) part that I'm not doing right but the logic is failing me. Isn't that supposed to add the amount of time passed to the originating time? Option Explicit Dim m_dStart As Date Dim m_TimePassed As Long Private Sub lblPause_Click() Timer1.Enabled = False lblPause.Enabled = False lblStart.Enabled = True End Sub Private Sub lblStart_Click() Timer1.Interval = 333 With lblStart If lblPause.Enabled Then m_dStart = Now Timer1.Enabled = True Else Timer1.Enabled = True m_dStart = DateAdd("s", m_TimePassed, m_dStart) lblPause.Enabled = True End If .Enabled = False End With End Sub Private Sub lblStop_Click() Timer1.Enabled = False lblStart.Enabled = True lblTime.Caption = "00:00:00" 'Record time and log to file with description of project worked End Sub Private Sub Timer1_Timer() Static sTmp As String sTmp = Format$(Now - m_dStart, "hh:mm:ss") m_TimePassed = Now - m_dStart With lblTime If .Caption <> sTmp Then .Caption = sTmp End If End With End Sub TIA Matt
From: Larry Serflaten on 11 Sep 2009 20:39 "Matt Williamson" <ih8spam(a)spamsux.org> wrote > I need a simple little stopwatch program to account for some project time. Add 3 command buttons and a Timer to a new form and paste in the code below. LFS Option Explicit Private Elapsed As Double Private Clock As Double Private Running As Boolean Private Sub Command1_Click() ' Start Elapsed = 0 Clock = Time Running = True SetEnable False, True, True Timer1.Enabled = True Timer1.Interval = 250 End Sub Private Sub Command2_Click() ' Pause Running = Not Running Clock = Time Command2.Caption = Switch(Running, "Pause", Not Running, "Resume") Timer1.Enabled = Running End Sub Private Sub Command3_Click() ' Stop Running = False SetEnable True, False, False Me.Caption = "Stopwatch" Timer1.Enabled = False MsgBox "Logged time: " & Format$(Elapsed, "HH:NN:SS") End Sub Private Sub Form_Load() Command1.Caption = "Start" Command2.Caption = "Pause" Command3.Caption = "Stop" SetEnable True, False, False Me.Caption = "Stopwatch" End Sub Sub SetEnable(ByVal V1 As Boolean, ByVal V2 As Boolean, V3 As Boolean) Command1.Enabled = V1 Command2.Enabled = V2 Command3.Enabled = V3 End Sub Private Sub Timer1_Timer() If Running Then Elapsed = Elapsed + (Time - Clock) Clock = Time End If Me.Caption = Format$(Elapsed, "HH:NN:SS") Timer1.Enabled = Running End Sub
From: Kevin Provance on 11 Sep 2009 20:48 Switch? Cool! I just learned something new about VB6. :) -- 2025 If you do not believe in time travel, your beliefs are about to be tempered. http://www.facebook.com/group.php?gid=43606237254 "Larry Serflaten" <serflaten(a)usinternet.com> wrote in message news:urmAsE0MKHA.1280(a)TK2MSFTNGP04.phx.gbl... | | "Matt Williamson" <ih8spam(a)spamsux.org> wrote | > I need a simple little stopwatch program to account for some project time. | | Add 3 command buttons and a Timer to a new form and paste in | the code below. | | LFS | | | | Option Explicit | Private Elapsed As Double | Private Clock As Double | Private Running As Boolean | | Private Sub Command1_Click() | ' Start | Elapsed = 0 | Clock = Time | Running = True | SetEnable False, True, True | Timer1.Enabled = True | Timer1.Interval = 250 | End Sub | | Private Sub Command2_Click() | ' Pause | Running = Not Running | Clock = Time | Command2.Caption = Switch(Running, "Pause", Not Running, "Resume") | Timer1.Enabled = Running | End Sub | | Private Sub Command3_Click() | ' Stop | Running = False | SetEnable True, False, False | Me.Caption = "Stopwatch" | Timer1.Enabled = False | MsgBox "Logged time: " & Format$(Elapsed, "HH:NN:SS") | End Sub | | Private Sub Form_Load() | Command1.Caption = "Start" | Command2.Caption = "Pause" | Command3.Caption = "Stop" | SetEnable True, False, False | Me.Caption = "Stopwatch" | End Sub | | Sub SetEnable(ByVal V1 As Boolean, ByVal V2 As Boolean, V3 As Boolean) | Command1.Enabled = V1 | Command2.Enabled = V2 | Command3.Enabled = V3 | End Sub | | Private Sub Timer1_Timer() | If Running Then | Elapsed = Elapsed + (Time - Clock) | Clock = Time | End If | Me.Caption = Format$(Elapsed, "HH:NN:SS") | Timer1.Enabled = Running | End Sub | | |
From: Rick Rothstein on 12 Sep 2009 03:17 There is also the Choose function. This line... Command2.Caption = Switch(Running, "Pause", Not Running, "Resume") can also be written this way.... Command2.Caption = Choose(2 + Running, "Pause", "Resume") Here is another new VB function for you to learn about... look up the Partition function in the help files... and then try to figure out a good use for it.<g> -- Rick (MVP - Excel) "Kevin Provance" <fu_bm(a)localhost.com> wrote in message news:u72IOL0MKHA.1372(a)TK2MSFTNGP02.phx.gbl... > Switch? > > Cool! I just learned something new about VB6. :) > > -- > 2025 > If you do not believe in time travel, > your beliefs are about to be tempered. > > http://www.facebook.com/group.php?gid=43606237254 > "Larry Serflaten" <serflaten(a)usinternet.com> wrote in message > news:urmAsE0MKHA.1280(a)TK2MSFTNGP04.phx.gbl... > | > | "Matt Williamson" <ih8spam(a)spamsux.org> wrote > | > I need a simple little stopwatch program to account for some project > time. > | > | Add 3 command buttons and a Timer to a new form and paste in > | the code below. > | > | LFS > | > | > | > | Option Explicit > | Private Elapsed As Double > | Private Clock As Double > | Private Running As Boolean > | > | Private Sub Command1_Click() > | ' Start > | Elapsed = 0 > | Clock = Time > | Running = True > | SetEnable False, True, True > | Timer1.Enabled = True > | Timer1.Interval = 250 > | End Sub > | > | Private Sub Command2_Click() > | ' Pause > | Running = Not Running > | Clock = Time > | Command2.Caption = Switch(Running, "Pause", Not Running, "Resume") > | Timer1.Enabled = Running > | End Sub > | > | Private Sub Command3_Click() > | ' Stop > | Running = False > | SetEnable True, False, False > | Me.Caption = "Stopwatch" > | Timer1.Enabled = False > | MsgBox "Logged time: " & Format$(Elapsed, "HH:NN:SS") > | End Sub > | > | Private Sub Form_Load() > | Command1.Caption = "Start" > | Command2.Caption = "Pause" > | Command3.Caption = "Stop" > | SetEnable True, False, False > | Me.Caption = "Stopwatch" > | End Sub > | > | Sub SetEnable(ByVal V1 As Boolean, ByVal V2 As Boolean, V3 As Boolean) > | Command1.Enabled = V1 > | Command2.Enabled = V2 > | Command3.Enabled = V3 > | End Sub > | > | Private Sub Timer1_Timer() > | If Running Then > | Elapsed = Elapsed + (Time - Clock) > | Clock = Time > | End If > | Me.Caption = Format$(Elapsed, "HH:NN:SS") > | Timer1.Enabled = Running > | End Sub > | > | > | > >
From: Kevin Provance on 13 Sep 2009 17:24 "Rick Rothstein" <rick.newsNO.SPAM(a)NO.SPAMverizon.net> wrote in message news:uHsagk3MKHA.4964(a)TK2MSFTNGP06.phx.gbl... | There is also the Choose function. This line... | | Command2.Caption = Switch(Running, "Pause", Not Running, "Resume") | | can also be written this way.... | | Command2.Caption = Choose(2 + Running, "Pause", "Resume") | | Here is another new VB function for you to learn about... look up the | Partition function in the help files... and then try to figure out a good | use for it.<g> I knew about Choose, but Partition is another new one I missed. Besides the obvious example for SQL, I truly cannot think of a use for it. I'm going to have to give that one some thought. You'd think that after all these years I would have sat down with the Object Browser and just looked. ;-)
|
Next
|
Last
Pages: 1 2 3 Prev: Run-time error '480' Next: FindExecutable API call fails for ACCDB file extensions |