Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Deleting Log File

Posted on 2003-12-04
8
Medium Priority
?
347 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
Technology Partners: 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

618 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