?
Solved

Deleting Log File

Posted on 2003-12-04
8
Medium Priority
?
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 26

Accepted Solution

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

ie

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

Assisted Solution

by:EDDYKT
EDDYKT earned 500 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

800 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