Writing to a log file - Don't tell me I stumped all of you!!

charlie79

Board Regular
Joined
Feb 27, 2002
Messages
97
My excel app requires a refresh of all data every minute or so. I have that part done. What I would like to do is write to a log file every time a refresh is done, reporting errors and what not. Problem is, I don't want these log files getting to large in size. I have the idea in my head, how I want to do it. I just can't seem to get the code down. Here's an idea of what I'm trying to do:
I would have 1 log file called mach.log. That would be the primary file being written to all the time. I would then have in code to check the size of that file before writing to it, if it's over 250000 bytes, then rename mach.log to "mach" &Date& ".log". And then start with a clean mach.log all over again. Something like this (this is pretty ruff at this point):

set f = mach.log 'you get the point....
if f.size > 250000 then
f.rename ("mach." & Date & ".log")
else
f.write(....)
end if

Hopefully you follow...? The problem? Is there an actual method .rename? I can't find anything that would do that...
This message was edited by charlie79 on 2002-03-26 08:23
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hey Charlie. Have you tried the FileSystemObject? Check the code below from the excel help file. You can get the size, in bytes, of the file in question.

Good luck!

Size Property


Description

For files, returns the size, in bytes, of the specified file. For folders, returns the size, in bytes, of all files and subfolders contained in the folder.

Syntax

object.Size

The object is always a File or Folder object.

Remarks

The following code illustrates the use of the Size property with a Folder object:

Sub ShowFolderSize(filespec)
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(filespec)
s = UCase(f.Name) & " uses " & f.size & " bytes."
MsgBox s, 0, "Folder Size Info"
End Sub
 
Upvote 0
Yes, I realize that part of it. I believe that code came directly from excel help and I've been there already. What I'm asking is if there is a way to rename the file if it is over 250000 bytes... Thanks for the idea though. Anyone else... Please!
 
Upvote 0
You should be able to say ...

If F.Size > X Then
F.CopyFile FromFileName, ToFileName
F.DeleteFile FromFileName
Set a = f.CreateTextFile(FromFileName, True)

End If

This should give you a new (empty) logfile if the size of the file grows bigger than X.
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,198
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top