Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save existing Log file to a new log file 1

Status
Not open for further replies.

badrion

Programmer
Jul 16, 2001
34
US
I have a program that keeps a continuous log of events, I would like it if the program goes down or is rebooted/restarted that the existing log is renamed and saved in a different folder with the date added to it. I know this can't be hard to do, I just cant seem to get the wording right. Please Help!
Brandi
 
If you want this log to be copied in the case that the application terminates normally (user closed it, not a fatal error or end task from task manager), then you can put that code in the main form's Form_Unload event.

Form_Unload(Cancel as Integer)

'write appropriate stuff to the log here
'to retrieve the date/time, use these keywords:

Date 'short date (7/18/01)
Time '(8:10:04 AM)
Now '(7/18/01 8:10:04 AM)

'to copy a file, use the FileCopy command:

FileCopy "c:\MySourcePath", "c:\MyDestPath"

End Sub

If you want the date appended to the end of the log file name, you may run into issues regarding the fwdslashes (\), since this is a separator between files. In that case, write a function that replaces the \ in a date with the underscore or something.

Hope that helped!

-Mike

 
Dim errordate1
errordate1 = Date
Dim errordate2 As String
errordate2 = Replace(CStr(errordate1), "/", "")
PCpathLOG = DATpath + "WMS_error" + errordate2 + ".log"

I got the path/filename and date to work. I just needed to copy this file over to another folder. Thanks for the help! Great info.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top