Results 1 to 3 of 3

Thread: How I capture the start time program and the stop

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    1
    Hello,
    How is possible capture the start time of any program,and when it stop,the stop time.
    For example:
    when I open my file (to write),a timer start, when I have finish I close the file the timer stop.
    I not know how I must control the open and close file event

    Tank's ... is very inportant to me

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Sure. Try something like this:
    Code:
    Private Sub Command1_Click()
        Dim datStart As Date
        Dim datFinish As Date
        Dim strMsg As String
        
        datStart = Now
        'Open File and do your stuff here
        
        datFinish = Now
        datFinish = datFinish - datStart
        
        strMsg = "Hours: " & Hour(datFinish) & vbCrLf
        strMsg = strMsg & "Minutes: " & Minute(datFinish) & vbCrLf
        strMsg = strMsg & "Seconds: " & Second(datFinish)
        MsgBox strMsg
    End Sub

  3. #3
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141
    flazanel,

    I'm not sure if I fully understand your question, but here goes...

    If you want to capture the start time and stop time of the application you designed and compiled, then in the start up procedure (ie. Form_Load event or Sub Main) write the current time to a log file. The example below will write the start time to a log file called AppLog.txt.

    Code:
    Private Sub Form_Load()
        Open "AppLog.txt" For Append As #1
            Print #1, App.EXEName & " Started: " & Now
        Close #1
    
    'The rest of your application code would continue on from here.
    
    End Sub
    Then add similar code to the application stop event (either the menu item, command button, or form_unload event that stops the program.

    Code:
    Private Sub Form_Unload(Cancel As Integer)
        Open "AppLog.txt" For Append As #1
            Print #1, App.EXEName & " Stopped: " & Now
        Close #1
        Unload Me
        End
    End Sub
    If you want to log the start and stop time of other applications that you didn't write (ie. commercial word processor, spreadsheet, database, etc) then you would have to write an app that looks at processes that start and terminate and log the times from there. This would be much more difficult. If you have Microsoft Outlook, you can use the Journal feature of this program, to monitor the start and stop times of various programs and documents. That would definitely be the easier route for this scenario.

    Hope this helps.
    JC

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