Solved

Deleting Log File

Posted on 2003-12-04
8
327 Views
Last Modified: 2010-08-05
I have a function that creates a log file. It works fine, but I would like to  have it deleted when my application is killed. Any suggestions? I included my Sub:

Public Sub Log(LogFilename As String, LogInfo As String)
   Dim File As Integer
   
   
   'Write to file
   File = FreeFile
   Open LogPath + "C:\LOG\" & LogFilename For Append As #File
   Print #intFile, LogInfo

   Close #intFile

   Exit Sub


End Sub


'Thanks in advance
0
Comment
Question by:LeeHenry
  • 3
  • 3
  • 2
8 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 125 total points
ID: 9875083
use kill

ie

kill "C:\LOG\" & LogFilename
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 125 total points
ID: 9875091
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
kill "your log file name"
End Sub
0
 
LVL 6

Author Comment

by:LeeHenry
ID: 9875519
Thanks
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Expert Comment

by:PBuck
ID: 9875543
A couple of suggestions.  

First off, always wrap the Kill function with a Dir$() otherwise an error will be produced if the file has not been created.

If Dir$("C:\LOG\" & LogFilename, vbNormal) <> vbNullString then
   Kill "C:\LOG\" & LogFilename
End if

Secondly, are you sure you are not interested in keeping a logfile history but maintain the filesize?  What is the point of a log file if you can not view it after your application is complete?  Some people create and append to log files but keep it small (lets say around 100K) for future reference.  Some people even go as far as keeping one prior version of the log file.

Such as, applog.txt becomes 100K in size -> so FileCopy it to applog.bak and Kill applog.txt and start over with applog.txt ?

Just a suggestion.  Hope this helps.
0
 
LVL 6

Author Comment

by:LeeHenry
ID: 9882711
PBuck,

Thanks for the suggestion. I am interested in keeping the file at 100K. How is this done?

Thanks.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9882819
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If (FileLen("your log file name") > 100 * 1024) Then
    Kill "your log file name" & "old"
    Name "your log file name" As "your log file name" & "old"
End If
End Sub
0
 
LVL 4

Expert Comment

by:PBuck
ID: 9882834
Dim fNo           As Integer
Dim lFileSize     As Long

Const FILE_BACKUP As String = "applog.bak"

   If Dir$("C:\LOG\" & LogFilename, vbNormal) <> vbNullString Then
      lFileSize = FileLen("C:\LOG\" & LogFilename)
      If lFileSize > 99999 Then
         FileCopy "C:\LOG\" & LogFilename, "C:\LOG\" & FILE_BACKUP
         Kill "C:\LOG\" & LogFilename
      End If
   End If
   
   fNo = FreeFile
   
   Open "C:\LOG\" & LogFilename For Append As fNo
      Print #fNo, strMessage
   Close fNo

'Here is a sample - hope this helps
0
 
LVL 6

Author Comment

by:LeeHenry
ID: 9884787
Thanks so much
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question