Results 1 to 12 of 12

Thread: VB - OnTheClock

Threaded View

  1. #1

    Thread Starter
    Fanatic Member doofusboy's Avatar
    Join Date
    Apr 2003
    Posts
    526

    VB - OnTheClock

    A simple app really. Just threw it together to keep track of how long I've been working on something so I knew how much to bill a client for coding time, documentation time, etc. One could always add "always on top" code should it be desired.

    Didn't make allowances for going past 24 hours because, regardless of how intense anyone is, they wouldn't need this app if they were at something that long, they'd need their head examined! [obviously the code could be amended to do that should you really need it]

    Here's the code and a screen shot (ID labels added to screenshot so you can tie back to the code; obviously actual form wouldn't have these ID's displayed):



    VB Code:
    1. '****************************************************
    2. '*
    3. '* Simple application employing the use of a Timer to
    4. '* determine what time an application started, keep track
    5. '* of the current time, and use those two pieces of info
    6. '* to determine how long the application has been running.
    7. '*
    8. '* Primary purpose for developing this application was to
    9. '* have a tool to keep track of how long I've been coding
    10. '* an application for billing purposes.
    11. '*
    12. '****************************************************
    13.  
    14. Option Explicit
    15. Dim startHour As String
    16. Dim startMinute As String
    17. Dim startSecond As String
    18. Dim startTotal As Long
    19. Dim currentHour As String
    20. Dim currentMinute As String
    21. Dim currentSecond As String
    22. Dim currentTotal As Long
    23. Dim elapsedHour As Long
    24. Dim elapsedMinute As Long
    25. Dim elapsedSecond As Long
    26. Dim elapsedTotal As Long
    27. Dim startAmPm As String
    28. Dim currentAmPm As String
    29. Dim ampmFlag As Boolean
    30.  
    31. Private Sub cmdUpdateRunTime_Click()
    32. Dim length As Long
    33.    
    34.     currentAmPm = Mid(Time, Len(Time) - 1, 2)
    35.  
    36.     'Set flag
    37.     If (startAmPm = "AM" And currentAmPm = "AM") Or (startAmPm = "PM" And currentAmPm = "PM") Then
    38.         ampmFlag = False
    39.     Else
    40.         ampmFlag = True
    41.     End If
    42.  
    43.     length = HowLong(startHour, startMinute, startSecond)
    44.     lblElapsedHours.Caption = elapsedHour
    45.     lblElapsedMinutes.Caption = elapsedMinute
    46.     lblElapsedSeconds.Caption = elapsedSecond
    47. End Sub
    48.  
    49. Private Sub Form_Load()
    50. Dim a As String
    51.  
    52.     Timer1.Interval = 1
    53.     lblStartTime.Caption = Time
    54.     startSecond = Mid$(lblStartTime.Caption, Len(lblStartTime.Caption) - 4, 2)
    55.     startMinute = Mid$(lblStartTime.Caption, Len(lblStartTime.Caption) - 7, 2)
    56.     If Len(lblStartTime.Caption) > 10 Then
    57.         startHour = Mid$(lblStartTime.Caption, Len(lblStartTime.Caption) - 10, 2)
    58.     Else
    59.         startHour = Mid$(lblStartTime.Caption, Len(lblStartTime.Caption) - 9, 1)
    60.     End If
    61.    
    62.     'Because of the way elapsed time is calculated, must keep
    63.     'track of AM/PM portion of Start time for comparison when
    64.     'elapsed time is eventually calculated
    65.     startAmPm = Mid$(lblStartTime.Caption, Len(lblStartTime.Caption) - 1, 2)
    66.  
    67. End Sub
    68.  
    69. Private Sub Timer1_Timer()
    70.     lblCurrentTime.Caption = Time
    71. End Sub
    72. Public Function HowLong(ByVal startHour As String, ByVal startMinute As String, ByVal startSecond As String) As Long
    73.  
    74. currentSecond = Mid$(Time, Len(Time) - 4, 2)
    75. currentMinute = Mid$(Time, Len(Time) - 7, 2)
    76. If Len(Time) > 10 Then
    77.     currentHour = Mid$(Time, Len(Time) - 10, 2)
    78. Else
    79.     currentHour = Mid$(Time, Len(Time) - 9, 1)
    80. End If
    81.  
    82. If ampmFlag = True And currentHour <> 12 Then
    83.     currentHour = currentHour + 12
    84. End If
    85.    
    86. startTotal = (startHour * 3600) + (startMinute * 60) + startSecond
    87. currentTotal = (currentHour * 3600) + (currentMinute * 60) + currentSecond
    88. elapsedTotal = currentTotal - startTotal
    89.  
    90. 'Application is active less than 1 minute
    91. If elapsedTotal < 60 Then
    92.     elapsedHour = 0
    93.     elapsedMinute = 0
    94.     elapsedSecond = elapsedTotal
    95. End If
    96.  
    97. 'Application is active for more than 1 minute
    98. 'but less than 1 hour
    99. If elapsedTotal >= 60 And elapsedTotal < 3600 Then
    100.     elapsedHour = 0
    101.     elapsedSecond = elapsedTotal Mod 60
    102.     elapsedMinute = (elapsedTotal - elapsedSecond) / 60
    103. End If
    104.  
    105. 'Application is active for 1 hour or more
    106. If elapsedTotal >= 3600 Then
    107.     elapsedHour = (elapsedTotal - (elapsedTotal Mod 3600)) / 3600
    108.     elapsedSecond = (elapsedTotal - (elapsedHour * 3600)) Mod 60
    109.     elapsedMinute = (elapsedTotal - (elapsedHour * 3600) - elapsedSecond) / 60
    110. End If
    111.  
    112. End Function
    Attached Images Attached Images  
    Last edited by doofusboy; May 17th, 2003 at 09:24 AM.
    Do canibals not eat clowns because they taste funny?

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